From a77a2c88f596290d62ca1629240bc8557e4c511f Mon Sep 17 00:00:00 2001 From: Nicolas Dumazet <nicolas.dumazet@nexedi.com> Date: Sat, 25 Sep 2010 23:14:17 +0000 Subject: [PATCH] tests for portal types as classes. Not working for now, as the code is not yet committed, but demonstrates the features. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38642 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../tests/input/non_migrated_person.zexp | Bin 0 -> 3977 bytes product/ERP5Type/tests/testMigration.py | 131 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 product/ERP5Type/tests/input/non_migrated_person.zexp create mode 100644 product/ERP5Type/tests/testMigration.py diff --git a/product/ERP5Type/tests/input/non_migrated_person.zexp b/product/ERP5Type/tests/input/non_migrated_person.zexp new file mode 100644 index 0000000000000000000000000000000000000000..251056e0bf9c35f9552d80df28d3e331a0759830 GIT binary patch literal 3977 zcmds3NpsXj6!tQUN8@F@0mcSwR$+p$4F)D;8*B^&kL@ATK&5I*2&ru;jHG!|D-MVG z5&1j0CWqWZ<&;CJa>ya%k}9gGT#~0zw<PR=A|wYY@<DA)_j_Nz<$K@fHy&*Dgiqm* zyPbDWCNJw-o@)d;^OYNSx0dTqT2xte^}wbMQ?{t*yN<+P(0i6apVEeYnMm7~=QGvO zYzi4N=(x^#+uHFoMh(c4LQ@kz=149&4tdfaSOyHNFJ4_Lm)9jy+I79h+f8>@H7%dH z-V-R00gmr8kZPpZay_OsRfeFT7#kWS1=VJ%<rwrU7?R^NHVo_6>mH@PqHb<>R+4zb z2&<8ts=I;1pp=|x!l*d2PMsZQO8f<5c;Kj7F$|TX&|QaNP*l8*ZTY_CIxvogD!ANn zD1`~Jc0HIR1^n*n76t?kkX$8TCVoCh@>R{zcBlu3NOp7A!NnAV!(>cVnWs5^Q)6gX zH7uRMbQ@+6vfJ5pL~g)QnPjNfT83k!py^FD@G(6wOG!y&u1<ZnqWKi&7#t^aYSlHY z?I*9fz=`w)PNpt!Dt&>|@de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! zr?)dA`b9|H$W-4}w~)r-JQ_q2e<g!hj&ycreep{9>T*||osFkM3vzpOcAn(;h#Tl4 zMha;$f-^W$zsTyvM1Kq>s$)o~j$v%nHxZ<vG>;Yas92-@vBc=OFgk$^`Q~cvK-%=d zlxgH`A<(80FNcMfX@)wyn@~N{4kh`1@qMfTv*PfaMy6Lbt6S$c*Vb;Y?ANo$8*n0V zfAUq5^;82+$M7*4sKW(h85L`&zR!}qbu~{U9l2}A^(^YcxwEm#Yw=Qji1qdMDvyjr fS|gEIiOd6(d44Rh;Qvk$PoH0yejP>pwdeU8bsr(p literal 0 HcmV?d00001 diff --git a/product/ERP5Type/tests/testMigration.py b/product/ERP5Type/tests/testMigration.py new file mode 100644 index 0000000000..7072bc90c3 --- /dev/null +++ b/product/ERP5Type/tests/testMigration.py @@ -0,0 +1,131 @@ +import os, shutil +import unittest + +import transaction + +from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase + +class TestNewStyleClasses(ERP5TypeTestCase): + + def getBusinessTemplateList(self): + return 'erp5_base', + + def testImportNonMigratedPerson(self): + """ + Import a .zexp containing a Person created with an old + Products.ERP5Type.Document.Person.Person type + """ + file_name = 'non_migrated_person.zexp' + import Products.ERP5Type.tests as test_module + test_path = test_module.__path__ + if isinstance(test_path, list): + test_path = test_path[0] + + zexp_path = os.path.join(test_path, 'input', file_name) + self.assertTrue(os.path.exists(zexp_path)) + + import_path = os.path.join(os.environ['INSTANCE_HOME'], 'import') + if not os.path.exists(import_path): + os.mkdir(import_path) + shutil.copy(zexp_path, import_path) + + + person_module = self.getPortal().person_module + person_module.manage_importObject(file_name) + + transaction.commit() + + non_migrated_person = person_module.non_migrated_person + # check that object unpickling instanciated a new style object + from erp5.portal_type import Person as erp5_document_person + self.assertEquals(non_migrated_person.__class__, erp5_document_person) + + def testMigrateOldObjectFromZODB(self): + """ + Load an object with ERP5Type.Document.Person.Person from the ZODB + and check that migration works well + """ + from Products.ERP5Type.Document.Person import Person + + # remove temporarily the migration + from Products.ERP5Type.Utils import PersistentMigrationMixin + PersistentMigrationMixin.migrate = 0 + + person_module = self.getPortal().person_module + obj_id = "this_object_is_old" + old_object = Person(obj_id) + person_module._setObject(obj_id, old_object) + old_object = person_module._getOb(obj_id) + + transaction.commit() + self.assertEquals(old_object.__class__.__module__, 'Products.ERP5Type.Document.Person') + self.assertEquals(old_object.__class__.__name__, 'Person') + + self.assertTrue(hasattr(old_object.__class__, '__setstate__')) + + # unload/deactivate the object + old_object._p_invalidate() + + # From now on, everything happens as if the object was a old, non-migrated + # object with an old Products.ERP5Type.Document.Person.Person + + # now turn on migration + PersistentMigrationMixin.migrate = 1 + + # reload the object + old_object._p_activate() + + self.assertEquals(old_object.__class__.__module__, 'erp5.portal_type') + self.assertEquals(old_object.__class__.__name__, 'Person') + + def testChangeMixin(self): + """ + Take an existing object, change the mixin definitions of its portal type. + Check that the new methods are there. + """ + portal = self.getPortal() + person_module = portal.person_module + person = person_module.newContent(id='John Dough', portal_type='Person') + + person_type = portal.portal_types.Person + self.assertEquals(person_type.getTypeMixinList(), None) + + try: + self.assertEquals(getattr(person, 'asText', None), None) + # just use a mixin/method that Person does not have yet + person_type.setTypeMixin('TextConvertableMixin') + + transaction.commit() + + self.assertTrue(hasattr(person, 'asText')) + finally: + # reset the type + person_type.setTypeMixin(None) + + def testChangeDocument(self): + """ + Take an existing object, change its document class + Check that the new methods are there. + """ + portal = self.getPortal() + person_module = portal.person_module + person = person_module.newContent(id='Eva Dough', portal_type='Person') + + person_type = portal.portal_types.Person + self.assertEquals(person_type.getTypeClass(), 'Person') + + try: + self.assertEquals(getattr(person, 'getCorporateName', None), None) + # change the base type class + person_type.setTypeClass('Organisation') + + transaction.commit() + + self.assertTrue(hasattr(person, 'getCorporateName')) + finally: + # reset the type + person_type.setTypeClass('Person') +def test_suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestNewStyleClasses)) + return suite -- 2.30.9