Esempio n. 1
0
    def test_interface_view_registered_default(self):
        """If the object supports an interface, and the view is registered as
        the default view, when a view is requested where no name is specified,
        the default view is returned."""

        class IHasInterface(Interface):
            pass

        class HasInterface(object):
            implements(IHasInterface)

        class AView(object):
            for_interface = IHasInterface
            name = "name"
            is_default = True

            def __init__(self, *args):
                pass

            def initialize(self):
                self.initialized = True

        register_view(AView)
        obj = HasInterface()
        view = get_view(obj, None, None)
        self.assertIsInstance(view, AView)
        self.assertTrue(view.initialized)
Esempio n. 2
0
    def test_interface_view_registered(self):
        """If the object supports an interface, and the view is registered,
        make sure that the view is returned when asked for."""

        class IHasInterface(Interface):
            pass

        class HasInterface(object):
            implements(IHasInterface)

        class AView(object):
            for_interface = IHasInterface
            name = "name"

            def __init__(self, *args):
                pass

            def initialize(self):
                self.initialized = True

        register_view(AView)
        obj = HasInterface()
        view = get_view(obj, "name", None)
        self.assertIsInstance(view, AView)
        self.assertTrue(view.initialized)
Esempio n. 3
0
 def __new__(cls, classname, bases, classdict):
     """Called when defining a new class."""
     instance = type.__new__(cls, classname, bases, classdict)
     register_view(instance)
     return instance