# HG changeset patch # User Sylvain Thénault # Date 1375347592 -7200 # Node ID 0d346a0a1451cd09a0734b7df00a47d9f65c791d # Parent d45d66d94baa0d0b4f29bbad3b1d107e498de1b4 [testlib] temporary_appobjects should call __registered__ if it exists. Closes #3064075 diff -r d45d66d94baa -r 0d346a0a1451 devtools/test/unittest_testlib.py --- a/devtools/test/unittest_testlib.py Thu Aug 01 15:51:22 2013 +0200 +++ b/devtools/test/unittest_testlib.py Thu Aug 01 10:59:52 2013 +0200 @@ -1,4 +1,4 @@ -# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of CubicWeb. @@ -20,7 +20,9 @@ from cStringIO import StringIO from unittest import TextTestRunner + from logilab.common.testlib import TestSuite, TestCase, unittest_main +from logilab.common.registry import yes from cubicweb.devtools import htmlparser from cubicweb.devtools.testlib import CubicWebTC @@ -172,5 +174,20 @@ self.assertTrue(rdef.permissions['add']) self.assertTrue(rdef.permissions['read'], ()) + def test_temporary_appobjects_registered(self): + class AnAppobject(object): + __registries__ = ('hip',) + __regid__ = 'hop' + __select__ = yes() + registered = None + @classmethod + def __registered__(cls, reg): + cls.registered = reg + + with self.temporary_appobjects(AnAppobject): + self.assertEqual(self.vreg['hip'], AnAppobject.registered) + self.assertIn(AnAppobject, self.vreg['hip']['hop']) + self.assertNotIn(AnAppobject, self.vreg['hip']['hop']) + if __name__ == '__main__': unittest_main() diff -r d45d66d94baa -r 0d346a0a1451 devtools/testlib.py --- a/devtools/testlib.py Thu Aug 01 15:51:22 2013 +0200 +++ b/devtools/testlib.py Thu Aug 01 10:59:52 2013 +0200 @@ -461,6 +461,10 @@ self.vreg._loadedmods.setdefault(self.__module__, {}) for obj in appobjects: self.vreg.register(obj) + registered = getattr(obj, '__registered__', None) + if registered: + for registry in obj.__registries__: + registered(self.vreg[registry]) try: yield finally: