def test_register_portal_bricks(self): class TestPortalBrick(SimpleBrick): pass class TestPortalBrick1(TestPortalBrick): id_ = SimpleBrick.generate_id('creme_config', 'test_register_portal_bricks1') class TestPortalBrick2(TestPortalBrick): id_ = SimpleBrick.generate_id('creme_config', 'test_register_portal_bricks2') brick_registry = _BrickRegistry() brick_registry.register(TestPortalBrick1, TestPortalBrick2) registry = _ConfigRegistry(brick_registry) registry.register_portal_bricks(TestPortalBrick1, TestPortalBrick2) brick_ids = set() for brick in registry.portal_bricks: self.assertIsInstance(brick, TestPortalBrick) brick_ids.add(brick.id_) self.assertIn(TestPortalBrick1.id_, brick_ids) self.assertIn(TestPortalBrick2.id_, brick_ids)
def test_registry_register_bricks(self): class TestBrick1(SimpleBrick): id_ = SimpleBrick.generate_id('creme_config', 'test_registry_register_bricks1') class TestBrick2(SimpleBrick): id_ = SimpleBrick.generate_id('creme_config', 'test_registry_register_bricks2') brick_registry = _BrickRegistry() brick_registry.register(TestBrick1, TestBrick2) registry = self._ConfigRegistry(brick_registry) registry.register_bricks(('creme_core', TestBrick1), ('documents', TestBrick2), ) with self.assertNoException(): app_conf = registry.get_app('creme_core') def get_brick_ids(app_conf_registry): b_ids = set() for brick in app_conf_registry.bricks: self.assertIsInstance(brick, SimpleBrick) b_ids.add(brick.id_) return b_ids brick_ids = get_brick_ids(app_conf) self.assertIn(TestBrick1.id_, brick_ids) self.assertNotIn(TestBrick2, brick_ids) with self.assertNoException(): app_conf = registry.get_app('documents') brick_ids = get_brick_ids(app_conf) self.assertIn(TestBrick2.id_, brick_ids) self.assertNotIn(TestBrick1, brick_ids)
def test_app_registry_is_empty01(self): "use models" registry = _ConfigRegistry( brick_registry=_BrickRegistry(), setting_key_registry=_SettingKeyRegistry(), ) app_registry = registry.get_app_registry('creme_core', create=True) self.assertIs(True, app_registry.is_empty) registry.register_model(FakeCivility) self.assertIs(False, app_registry.is_empty)
def test_registry_register_userbricks(self): class TestUserBrick1(SimpleBrick): id_ = SimpleBrick.generate_id('creme_config', 'test_registry_register_userbricks1') class TestUserBrick2(SimpleBrick): id_ = SimpleBrick.generate_id('creme_config', 'test_registry_register_userbricks2') brick_registry = _BrickRegistry() brick_registry.register(TestUserBrick1, TestUserBrick2) registry = self._ConfigRegistry(brick_registry) registry.register_user_bricks(TestUserBrick1, TestUserBrick2) bricks = list(registry.user_bricks) self.assertEqual(2, len(bricks)) self.assertIsInstance(bricks[0], TestUserBrick1) self.assertIsInstance(bricks[1], TestUserBrick2)
def test_set_state04(self): "Brick ids with |" user = self.login() casca = FakeContact.objects.create(user=user, first_name='Casca', last_name='Mylove') class ContactBrick(Brick): id_ = InstanceBrickConfigItem.generate_base_id( 'creme_core', 'base_block') dependencies = (FakeOrganisation, ) template_name = 'persons/bricks/itdoesnotexist.html' def __init__(self, instance_block_config_item): # super(ContactBrick, self).__init__() super().__init__() self.ibci = instance_block_config_item def detailview_display(self, context): return '<table id="{}"><thead><tr>{}</tr></thead></table>'.format( self.id_, self.ibci.entity) # Useless :) self.assertTrue( InstanceBrickConfigItem.id_is_specific(ContactBrick.id_)) ibci = InstanceBrickConfigItem.objects \ .create(entity=casca, brick_id=InstanceBrickConfigItem.generate_id(ContactBrick, casca, ''), verbose=u'I am an awesome brick', data='', ) brick_registry = _BrickRegistry() brick_registry.register_4_instance(ContactBrick) bricks = list(brick_registry.get_bricks([ibci.brick_id], entity=casca)) brick_id = bricks[0].id_ self.assertPOST200(self.SET_STATE_URL, data={ 'id': brick_id, 'is_open': 1, 'show_empty_fields': 1 })
def test_app_registry_is_empty02(self): "use bricks" class TestBrick(SimpleBrick): id_ = SimpleBrick.generate_id('creme_config', 'test_app_registry_is_empty02') brick_registry = _BrickRegistry() registry = _ConfigRegistry( brick_registry=brick_registry, setting_key_registry=_SettingKeyRegistry(), ) app_registry = registry.get_app_registry('creme_core', create=True) self.assertTrue(app_registry.is_empty) brick_registry.register(TestBrick) self.assertTrue(app_registry.is_empty) registry.register_app_bricks('creme_core', TestBrick) self.assertFalse(app_registry.is_empty)
def test_set_state04(self): "Instance brick." # "Brick ids with |" user = self.login() casca = FakeContact.objects.create(user=user, first_name='Casca', last_name='Mylove') class ContactBrick(InstanceBrick): id_ = InstanceBrickConfigItem.generate_base_id( 'creme_core', 'base_block') dependencies = (FakeOrganisation, ) template_name = 'persons/bricks/itdoesnotexist.html' def detailview_display(self, context): return f'<table id="{self.id_}"><thead><tr>' \ f'{self.config_item.entity}</tr></thead></table>' # Useless :) ibci = InstanceBrickConfigItem.objects.create( entity=casca, brick_class_id=ContactBrick.id_, ) brick_registry = _BrickRegistry() brick_registry.register_4_instance(ContactBrick) brick_id = ibci.brick_id self.assertPOST200( self.SET_STATE_URL, data={ 'id': brick_id, 'is_open': 1, 'show_empty_fields': 1 }, )