Exemplo n.º 1
0
        def wrapper(self):
            from anyblok.registry import RegistryManager
            name = self.__name__
            if name in cls.declaration_types:
                raise DeclarationsException(
                    "The declaration type %r is already defined" % name)

            cls.declaration_types[name] = self

            setattr(self, '__registry_name__', name)
            setattr(self, '__declaration_type__', name)
            setattr(cls, name, self)

            if isAnEntry:
                assemble_callback = initialize_callback = None
                if assemble and hasattr(self, assemble):
                    assemble_callback = getattr(self, assemble)

                if initialize and hasattr(self, initialize):
                    initialize_callback = getattr(self, initialize)

                RegistryManager.declare_entry(
                    name, assemble_callback=assemble_callback,
                    initialize_callback=initialize_callback)

            # All declaration type can need to be unload declarated values
            if unload and hasattr(self, unload):
                RegistryManager.declare_unload_callback(
                    name, getattr(self, unload))

            return self
Exemplo n.º 2
0
    def init_env(self, request):
        def revert():
            EnvironmentManager.set('current_blok', None)
            del RegistryManager.loaded_bloks['testEntry']
            RegistryManager.undeclare_entry('Other')

        request.addfinalizer(revert)
        RegistryManager.declare_entry('Other')
        RegistryManager.init_blok('testEntry')
        EnvironmentManager.set('current_blok', 'testEntry')
Exemplo n.º 3
0
    def test_add_entry(self):
        RegistryManager.declare_entry('Other')
        RegistryManager.init_blok('newblok')
        is_exist = 'newblok' in RegistryManager.loaded_bloks
        self.assertEqual(is_exist, True)
        for entry in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query',
                      'InstrumentedList'):
            self.assertEqual(
                RegistryManager.loaded_bloks['newblok']['Core'][entry], [])

        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Model'],
                         {'registry_names': []})
        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Mixin'],
                         {'registry_names': []})
        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Other'],
                         {'registry_names': []})
Exemplo n.º 4
0
    def test_add_entry(self):
        RegistryManager.declare_entry('Other')
        RegistryManager.init_blok('newblok')
        is_exist = 'newblok' in RegistryManager.loaded_bloks
        self.assertEqual(is_exist, True)
        for entry in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query',
                      'InstrumentedList'):
            self.assertEqual(
                RegistryManager.loaded_bloks['newblok']['Core'][entry], [])

        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Model'],
                         {'registry_names': []})
        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Mixin'],
                         {'registry_names': []})
        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Other'],
                         {'registry_names': []})
Exemplo n.º 5
0
 def test_global_property(self):
     RegistryManager.declare_entry('Other')
     blok = 'newblok'
     RegistryManager.init_blok(blok)
     try:
         oldblok = EnvironmentManager.get('current_blok')
         EnvironmentManager.set('current_blok', blok)
         assert not RegistryManager.has_blok_property('myproperty')
         RegistryManager.add_or_replace_blok_property('myproperty', 2)
         assert RegistryManager.has_blok_property('myproperty')
         assert RegistryManager.get_blok_property('myproperty') == 2
         RegistryManager.add_or_replace_blok_property('myproperty', 3)
         assert RegistryManager.get_blok_property('myproperty') == 3
         RegistryManager.remove_blok_property('myproperty')
         assert not RegistryManager.has_blok_property('myproperty')
     finally:
         EnvironmentManager.set('current_blok', oldblok)
Exemplo n.º 6
0
    def test_add_entry(self):
        RegistryManager.declare_entry('Other')
        RegistryManager.init_blok('newblok')
        is_exist = 'newblok' in RegistryManager.loaded_bloks
        assert is_exist
        for entry in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query',
                      'InstrumentedList'):
            assert RegistryManager.loaded_bloks['newblok']['Core'][entry] == []

        assert RegistryManager.loaded_bloks['newblok']['Model'] == {
            'registry_names': []
        }
        assert RegistryManager.loaded_bloks['newblok']['Mixin'] == {
            'registry_names': []
        }
        assert RegistryManager.loaded_bloks['newblok']['Other'] == {
            'registry_names': []
        }
Exemplo n.º 7
0
    def test_init_blok_with_other_entry(self):
        RegistryManager.declare_entry('Other')
        hasOther = 'Other' in RegistryManager.declared_entries
        self.assertEqual(hasOther, True)
        RegistryManager.init_blok('newblok')
        is_exist = 'newblok' in RegistryManager.loaded_bloks
        self.assertEqual(is_exist, True)
        for core in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query',
                     'InstrumentedList'):
            self.assertIn(
                core, RegistryManager.loaded_bloks['newblok']['Core'].keys())
            self.assertEqual(
                RegistryManager.loaded_bloks['newblok']['Core'][core], [])

        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Model'],
                         {'registry_names': []})
        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Mixin'],
                         {'registry_names': []})
        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Other'],
                         {'registry_names': []})
Exemplo n.º 8
0
    def test_init_blok_with_other_entry(self):
        RegistryManager.declare_entry('Other')
        hasOther = 'Other' in RegistryManager.declared_entries
        self.assertEqual(hasOther, True)
        RegistryManager.init_blok('newblok')
        is_exist = 'newblok' in RegistryManager.loaded_bloks
        self.assertEqual(is_exist, True)
        for core in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query',
                     'InstrumentedList'):
            self.assertIn(
                core, RegistryManager.loaded_bloks['newblok']['Core'].keys())
            self.assertEqual(
                RegistryManager.loaded_bloks['newblok']['Core'][core], [])

        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Model'],
                         {'registry_names': []})
        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Mixin'],
                         {'registry_names': []})
        self.assertEqual(RegistryManager.loaded_bloks['newblok']['Other'],
                         {'registry_names': []})
Exemplo n.º 9
0
    def test_add_callback(self):
        def callback():
            pass

        RegistryManager.declare_entry('Other',
                                      assemble_callback=callback,
                                      initialize_callback=callback)
        hasModel = 'Model' in RegistryManager.declared_entries
        hasMixin = 'Mixin' in RegistryManager.declared_entries
        hasOther = 'Other' in RegistryManager.declared_entries
        self.assertEqual(hasModel, True)
        self.assertEqual(hasMixin, True)
        self.assertEqual(hasOther, True)

        cb = Model.assemble_callback
        hasModelCb = cb == RegistryManager.callback_assemble_entries['Model']
        cb = callback
        hasOtherCb = cb == RegistryManager.callback_assemble_entries['Other']
        self.assertEqual(hasModelCb, True)
        self.assertEqual(hasOtherCb, True)

        cb = Model.initialize_callback
        hasModelCb = cb == RegistryManager.callback_initialize_entries['Model']
        cb = callback
        hasOtherCb = cb == RegistryManager.callback_initialize_entries['Other']
        self.assertEqual(hasModelCb, True)
        self.assertEqual(hasOtherCb, True)

        RegistryManager.init_blok('newblok')
        is_exist = 'newblok' in RegistryManager.loaded_bloks
        self.assertEqual(is_exist, True)
        hasCore = 'Core' in RegistryManager.loaded_bloks['newblok']
        hasModel = 'Model' in RegistryManager.loaded_bloks['newblok']
        hasMixin = 'Mixin' in RegistryManager.loaded_bloks['newblok']
        hasOther = 'Other' in RegistryManager.loaded_bloks['newblok']
        self.assertEqual(hasCore, True)
        self.assertEqual(hasModel, True)
        self.assertEqual(hasMixin, True)
        self.assertEqual(hasOther, True)
Exemplo n.º 10
0
 def test_global_property(self):
     RegistryManager.declare_entry('Other')
     blok = 'newblok'
     RegistryManager.init_blok(blok)
     try:
         oldblok = EnvironmentManager.get('current_blok')
         EnvironmentManager.set('current_blok', blok)
         self.assertEqual(RegistryManager.has_blok_property('myproperty'),
                          False)
         RegistryManager.add_or_replace_blok_property('myproperty', 2)
         self.assertEqual(RegistryManager.has_blok_property('myproperty'),
                          True)
         self.assertEqual(RegistryManager.get_blok_property('myproperty'),
                          2)
         RegistryManager.add_or_replace_blok_property('myproperty', 3)
         self.assertEqual(RegistryManager.get_blok_property('myproperty'),
                          3)
         RegistryManager.remove_blok_property('myproperty')
         self.assertEqual(RegistryManager.has_blok_property('myproperty'),
                          False)
     finally:
         EnvironmentManager.set('current_blok', oldblok)
Exemplo n.º 11
0
    def test_add_callback(self):

        def callback():
            pass

        RegistryManager.declare_entry('Other', assemble_callback=callback,
                                      initialize_callback=callback)
        hasModel = 'Model' in RegistryManager.declared_entries
        hasMixin = 'Mixin' in RegistryManager.declared_entries
        hasOther = 'Other' in RegistryManager.declared_entries
        self.assertEqual(hasModel, True)
        self.assertEqual(hasMixin, True)
        self.assertEqual(hasOther, True)

        cb = Model.assemble_callback
        hasModelCb = cb == RegistryManager.callback_assemble_entries['Model']
        cb = callback
        hasOtherCb = cb == RegistryManager.callback_assemble_entries['Other']
        self.assertEqual(hasModelCb, True)
        self.assertEqual(hasOtherCb, True)

        cb = Model.initialize_callback
        hasModelCb = cb == RegistryManager.callback_initialize_entries['Model']
        cb = callback
        hasOtherCb = cb == RegistryManager.callback_initialize_entries['Other']
        self.assertEqual(hasModelCb, True)
        self.assertEqual(hasOtherCb, True)

        RegistryManager.init_blok('newblok')
        is_exist = 'newblok' in RegistryManager.loaded_bloks
        self.assertEqual(is_exist, True)
        hasCore = 'Core' in RegistryManager.loaded_bloks['newblok']
        hasModel = 'Model' in RegistryManager.loaded_bloks['newblok']
        hasMixin = 'Mixin' in RegistryManager.loaded_bloks['newblok']
        hasOther = 'Other' in RegistryManager.loaded_bloks['newblok']
        self.assertEqual(hasCore, True)
        self.assertEqual(hasModel, True)
        self.assertEqual(hasMixin, True)
        self.assertEqual(hasOther, True)
Exemplo n.º 12
0
 def test_global_property(self):
     RegistryManager.declare_entry('Other')
     blok = 'newblok'
     RegistryManager.init_blok(blok)
     try:
         oldblok = EnvironmentManager.get('current_blok')
         EnvironmentManager.set('current_blok', blok)
         self.assertEqual(RegistryManager.has_blok_property('myproperty'),
                          False)
         RegistryManager.add_or_replace_blok_property('myproperty', 2)
         self.assertEqual(
             RegistryManager.has_blok_property('myproperty'), True)
         self.assertEqual(
             RegistryManager.get_blok_property('myproperty'), 2)
         RegistryManager.add_or_replace_blok_property('myproperty', 3)
         self.assertEqual(
             RegistryManager.get_blok_property('myproperty'), 3)
         RegistryManager.remove_blok_property('myproperty')
         self.assertEqual(RegistryManager.has_blok_property('myproperty'),
                          False)
     finally:
         EnvironmentManager.set('current_blok', oldblok)
Exemplo n.º 13
0
    def test_init_blok_with_other_entry(self):
        RegistryManager.declare_entry('Other')
        hasOther = 'Other' in RegistryManager.declared_entries
        assert hasOther
        RegistryManager.init_blok('newblok')
        is_exist = 'newblok' in RegistryManager.loaded_bloks
        assert is_exist
        for core in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query',
                     'InstrumentedList'):
            assert core in RegistryManager.loaded_bloks['newblok'][
                'Core'].keys()
            assert RegistryManager.loaded_bloks['newblok']['Core'][core] == []

        assert RegistryManager.loaded_bloks['newblok']['Model'] == {
            'registry_names': []
        }
        assert RegistryManager.loaded_bloks['newblok']['Mixin'] == {
            'registry_names': []
        }
        assert RegistryManager.loaded_bloks['newblok']['Other'] == {
            'registry_names': []
        }
Exemplo n.º 14
0
    def test_add_callback(self):
        def callback():
            pass

        RegistryManager.declare_entry('Other',
                                      assemble_callback=callback,
                                      initialize_callback=callback)
        hasModel = 'Model' in RegistryManager.declared_entries
        hasMixin = 'Mixin' in RegistryManager.declared_entries
        hasOther = 'Other' in RegistryManager.declared_entries
        assert hasModel
        assert hasMixin
        assert hasOther

        cb = Model.assemble_callback
        hasModelCb = cb == RegistryManager.callback_assemble_entries['Model']
        cb = callback
        hasOtherCb = cb == RegistryManager.callback_assemble_entries['Other']
        assert hasModelCb
        assert hasOtherCb

        cb = Model.initialize_callback
        hasModelCb = cb == RegistryManager.callback_initialize_entries['Model']
        cb = callback
        hasOtherCb = cb == RegistryManager.callback_initialize_entries['Other']
        assert hasModelCb
        assert hasOtherCb

        RegistryManager.init_blok('newblok')
        is_exist = 'newblok' in RegistryManager.loaded_bloks
        assert is_exist
        hasCore = 'Core' in RegistryManager.loaded_bloks['newblok']
        hasModel = 'Model' in RegistryManager.loaded_bloks['newblok']
        hasMixin = 'Mixin' in RegistryManager.loaded_bloks['newblok']
        hasOther = 'Other' in RegistryManager.loaded_bloks['newblok']
        assert hasCore
        assert hasModel
        assert hasMixin
        assert hasOther
Exemplo n.º 15
0
        def wrapper(self):
            from anyblok.registry import RegistryManager
            name = self.__name__
            if name in cls.declaration_types:
                raise DeclarationsException(
                    "The declaration type %r is already defined" % name)

            cls.declaration_types[name] = self

            setattr(self, '__registry_name__', name)
            setattr(self, '__declaration_type__', name)
            setattr(cls, name, self)

            if isAnEntry:
                pre_assemble_callback = assemble_callback = None
                initialize_callback = None
                if pre_assemble and hasattr(self, pre_assemble):
                    pre_assemble_callback = getattr(self, pre_assemble)

                if assemble and hasattr(self, assemble):
                    assemble_callback = getattr(self, assemble)

                if initialize and hasattr(self, initialize):
                    initialize_callback = getattr(self, initialize)

                RegistryManager.declare_entry(
                    name,
                    pre_assemble_callback=pre_assemble_callback,
                    assemble_callback=assemble_callback,
                    initialize_callback=initialize_callback)

            # All declaration type can need to be unload declarated values
            if unload and hasattr(self, unload):
                RegistryManager.declare_unload_callback(
                    name, getattr(self, unload))

            return self
Exemplo n.º 16
0
 def setUpClass(cls):
     super(TestRegistryEntry, cls).setUpClass()
     RegistryManager.declare_entry('Other')
     RegistryManager.init_blok('testEntry')
     EnvironmentManager.set('current_blok', 'testEntry')