Annotation of kupuMPIWG/plone/tests/test_librarymanager.py, revision 1.1

1.1     ! dwinter     1: ##############################################################################
        !             2: #
        !             3: # Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
        !             4: #
        !             5: # This software is distributed under the terms of the Kupu
        !             6: # License. See LICENSE.txt for license text. For a list of Kupu
        !             7: # Contributors see CREDITS.txt.
        !             8: #
        !             9: ##############################################################################
        !            10: """Tests for the library tool
        !            11: 
        !            12: $Id: test_librarymanager.py 9879 2005-03-18 12:04:00Z yuppie $
        !            13: """
        !            14: 
        !            15: import os, sys
        !            16: if __name__ == '__main__':
        !            17:     execfile(os.path.join(sys.path[0], 'framework.py'))
        !            18: 
        !            19: import Acquisition
        !            20: from Testing.ZopeTestCase import ZopeTestCase
        !            21: 
        !            22: from Products.kupu.plone.plonelibrarytool import PloneKupuLibraryTool
        !            23: 
        !            24: class FakeMembershipTool:
        !            25:     isAnonymousUser = lambda self: True
        !            26: 
        !            27: class FakePortal(Acquisition.Implicit):
        !            28:     absolute_url = lambda(self): None
        !            29:     portal_membership = FakeMembershipTool()
        !            30: 
        !            31: class FakeContextObject(Acquisition.Implicit):
        !            32: 
        !            33:     __allow_access_to_unprotected_subobjects__ = True
        !            34:     isPrincipiaFolderish = True
        !            35:     REQUEST = 42
        !            36:     absolute_url = lambda(self): "The answer is 42"
        !            37: 
        !            38: class TestILibraryManager(ZopeTestCase):
        !            39:     """Test the implementation of ILibraryManger in KupuLibraryTool"""
        !            40: 
        !            41:     def afterSetUp(self):
        !            42:         self.libs = self.makeLibraries()
        !            43: 
        !            44:     def makeLibraries(self):
        !            45:         # need to use Plone specific tool for Acquisition. Sucks.
        !            46:         libs = PloneKupuLibraryTool()
        !            47:         self.portal = FakePortal()
        !            48:         context = FakeContextObject()
        !            49:         libs = libs.__of__(self.portal)
        !            50:         self.context = context.__of__(self.portal)
        !            51:         libs.addLibrary('foo_id', 'Foobar', 'foobar', 'foosrc', 'fooicon')
        !            52:         libs.addLibrary('bar_id', 'Barfoo', 'barfoo', 'barsrc', 'baricon')
        !            53:         libs.addLibrary('baz_id', 'Baz', 'foobarbaz', 'bazsrc', 'bazicon')
        !            54:         return libs
        !            55: 
        !            56:     def test_get_library(self):
        !            57:         libs = self.libs
        !            58:         expected = (
        !            59:             dict(id='foo_id', title='Foobar', uri='foobar',
        !            60:                  src='foosrc', icon='fooicon'),
        !            61:             dict(id='bar_id', title='Barfoo', uri='barfoo',
        !            62:                  src='barsrc', icon='baricon'),
        !            63:             dict(id='baz_id', title='Baz', uri='foobarbaz',
        !            64:                  src='bazsrc', icon='bazicon'),
        !            65:             )
        !            66:         self.assertEqual(libs.getLibraries(self.context), expected)
        !            67: 
        !            68:     def test_expressions(self):
        !            69:         libs = self.libs
        !            70:         context = self.context
        !            71:         new_libs = (
        !            72:             dict(id='foo_id', title='Foobar', uri='python:request',
        !            73:                  src='foosrc', icon='fooicon'),
        !            74:             dict(id='bar_id', title='Barfoo', uri='python:object',
        !            75:                  src='barsrc', icon='baricon'),
        !            76:             dict(id='baz_id', title='Baz', uri='string:${object/absolute_url}',
        !            77:                  src='bazsrc', icon='bazicon'),
        !            78:             )
        !            79:         libs.updateLibraries(new_libs)
        !            80: 
        !            81:         expected = (
        !            82:             dict(id='foo_id', title='Foobar', uri=42,
        !            83:                  src='foosrc', icon='fooicon'),
        !            84:             dict(id='bar_id', title='Barfoo', uri=context,
        !            85:                  src='barsrc', icon='baricon'),
        !            86:             dict(id='baz_id', title='Baz', uri="The answer is 42",
        !            87:                  src='bazsrc', icon='bazicon')
        !            88:             )
        !            89:         self.assertEqual(libs.getLibraries(context), expected)
        !            90: 
        !            91:     def test_delete(self):
        !            92:         libs = self.libs
        !            93:         libs.deleteLibraries([1])
        !            94:         expected = (
        !            95:             dict(id='foo_id', title='Foobar', uri='foobar',
        !            96:                  src='foosrc', icon='fooicon'),
        !            97:             dict(id='baz_id', title='Baz', uri='foobarbaz',
        !            98:                  src='bazsrc', icon='bazicon'),
        !            99:             )
        !           100:         self.assertEqual(libs.getLibraries(self.context), expected)
        !           101: 
        !           102:         libs = self.makeLibraries()
        !           103:         libs.deleteLibraries([0, 1])
        !           104:         expected = (
        !           105:             dict(id='baz_id', title='Baz', uri='foobarbaz',
        !           106:                  src='bazsrc', icon='bazicon'),
        !           107:             )
        !           108:         self.assertEqual(libs.getLibraries(self.context), expected)
        !           109: 
        !           110:     def test_update(self):
        !           111:         libs = self.libs
        !           112:         context = self.context
        !           113:         new_libs = (
        !           114:             dict(id='foo_new_id', title='Newfoo', uri="python:object",
        !           115:                  src='foonewsrc', icon="foonewicon"),
        !           116:             dict(id='just_a_new_id'),
        !           117:             dict(src="python:'you stink'.upper()"),
        !           118:             )
        !           119:         libs.updateLibraries(new_libs)
        !           120:         expected = (
        !           121:             dict(id='foo_new_id', title='Newfoo', uri=context,
        !           122:                  src='foonewsrc', icon='foonewicon'),
        !           123:             dict(id='just_a_new_id', title='Barfoo', uri='barfoo',
        !           124:                  src='barsrc', icon='baricon'),
        !           125:             dict(id='baz_id', title='Baz', uri='foobarbaz',
        !           126:                  src="YOU STINK", icon='bazicon'),
        !           127:             )
        !           128:         self.assertEqual(libs.getLibraries(context), expected)
        !           129: 
        !           130:     def test_move(self):
        !           131:         libs = self.libs
        !           132:         libs.moveUp([1])
        !           133:         expected = (
        !           134:             dict(id='bar_id', title='Barfoo', uri='barfoo',
        !           135:                  src='barsrc', icon='baricon'),
        !           136:             dict(id='foo_id', title='Foobar', uri='foobar',
        !           137:                  src='foosrc', icon='fooicon'),
        !           138:             dict(id='baz_id', title='Baz', uri='foobarbaz',
        !           139:                  src='bazsrc', icon='bazicon'),
        !           140:             )
        !           141:         self.assertEqual(libs.getLibraries(self.context), expected)
        !           142: 
        !           143:         libs.moveDown([1])
        !           144:         expected = (
        !           145:             dict(id='bar_id', title='Barfoo', uri='barfoo',
        !           146:                  src='barsrc', icon='baricon'),
        !           147:             dict(id='baz_id', title='Baz', uri='foobarbaz',
        !           148:                  src='bazsrc', icon='bazicon'),
        !           149:             dict(id='foo_id', title='Foobar', uri='foobar',
        !           150:                  src='foosrc', icon='fooicon'),
        !           151:             )
        !           152:         self.assertEqual(libs.getLibraries(self.context), expected)
        !           153: 
        !           154:         libs.moveUp([1, 2])
        !           155:         expected = (
        !           156:             dict(id='baz_id', title='Baz', uri='foobarbaz',
        !           157:                  src='bazsrc', icon='bazicon'),
        !           158:             dict(id='foo_id', title='Foobar', uri='foobar',
        !           159:                  src='foosrc', icon='fooicon'),
        !           160:             dict(id='bar_id', title='Barfoo', uri='barfoo',
        !           161:                  src='barsrc', icon='baricon'),
        !           162:             )
        !           163:         self.assertEqual(libs.getLibraries(self.context), expected)
        !           164: 
        !           165:         libs.moveDown([2])
        !           166:         expected = (
        !           167:             dict(id='bar_id', title='Barfoo', uri='barfoo',
        !           168:                  src='barsrc', icon='baricon'),
        !           169:             dict(id='foo_id', title='Foobar', uri='foobar',
        !           170:                  src='foosrc', icon='fooicon'),
        !           171:             dict(id='baz_id', title='Baz', uri='foobarbaz',
        !           172:                  src='bazsrc', icon='bazicon'),
        !           173:             )
        !           174:         self.assertEqual(libs.getLibraries(self.context), expected)
        !           175: 
        !           176: if __name__ == '__main__':
        !           177:     framework()
        !           178: else:
        !           179:     # While framework.py provides its own test_suite()
        !           180:     # method the testrunner utility does not.
        !           181:     from unittest import TestSuite, makeSuite
        !           182:     def test_suite():
        !           183:         suite = TestSuite()
        !           184:         suite.addTest(makeSuite(TestILibraryManager))
        !           185:         return suite

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>