示例#1
0
 def test_create_detailview06(self):
     "Default configuration cannot have a related role"
     with self.assertRaises(ValueError):
         BrickDetailviewLocation.create_if_needed(
                 brick_id=PropertiesBrick.id_,
                 order=5, zone=BrickDetailviewLocation.RIGHT,
                 model=None, role='superuser', # <==
         )
示例#2
0
    def setUpClass(cls):
        # super(ImprintViewsTestCase, cls).setUpClass()
        super().setUpClass()

        BrickDetailviewLocation.create_if_needed(
            brick_id=ImprintsBrick.id_,
            order=1,
            zone=BrickDetailviewLocation.LEFT,
        )
        # BlockPortalLocation.create_or_update(brick_id=ImprintsBrick.id_, order=1, app_name='creme_core')
        BrickHomeLocation.objects.create(brick_id=ImprintsBrick.id_, order=1)
示例#3
0
    def test_brick_orga03(self):
        "Statistics"
        self.login()

        orga = Organisation.objects.create(user=self.user, name='NERV')
        brick_id = bricks.PersonsStatisticsBrick.id_

        BrickDetailviewLocation.create_if_needed(
            brick_id=brick_id,
            order=1000,
            zone=BrickDetailviewLocation.LEFT,
            model=Organisation,
        )

        response = self.assertGET200(orga.get_absolute_url())
        self.assertTemplateUsed(response,
                                'billing/bricks/persons-statistics.html')

        tree = self.get_html_tree(response.content)
        self.get_brick_node(tree, brick_id)
示例#4
0
    def test_display_custombrick03(self):
        "With FieldsConfig on sub-fields"
        user = self.login()

        hidden_fname = 'zipcode'
        FieldsConfig.create(
            FakeAddress,
            descriptions=[(hidden_fname, {
                FieldsConfig.HIDDEN: True
            })],
        )
        build_cell = EntityCellRegularField.build
        cbc_item = CustomBrickConfigItem.objects.create(
            id='tests-contacts1',
            name='Contact info',
            content_type=ContentType.objects.get_for_model(FakeContact),
            cells=[
                build_cell(FakeContact, 'last_name'),
                build_cell(FakeContact, 'address__' + hidden_fname),
                build_cell(FakeContact, 'address__city'),
            ],
        )
        bdl = BrickDetailviewLocation.create_if_needed(
            brick_id=cbc_item.generate_id(),
            order=1000,  # Should be the last block
            model=FakeContact,
            zone=BrickDetailviewLocation.BOTTOM,
        )
        naru = FakeContact.objects.create(
            user=user,
            last_name='Narusegawa',
            first_name='Naru',
            phone='1122334455',
        )
        naru.address = FakeAddress.objects.create(
            value='Hinata Inn',
            city='Tokyo',
            zipcode='112233',
            entity=naru,
        )
        naru.save()

        content_node = self._get_contact_brick_content(naru,
                                                       brick_id=bdl.brick_id)
        self.assertEqual(
            naru.last_name,
            self.get_brick_tile(content_node, 'regular_field-last_name').text)
        self.assertEqual(
            naru.address.city,
            self.get_brick_tile(content_node,
                                'regular_field-address__city').text)
        self._assertNoBrickTile(content_node, 'regular_field-address__zipcode')
示例#5
0
    def populate(self):
        already_populated = UserMessagePriority.objects.filter(
            pk=PRIO_IMP_PK).exists()

        for pk, title in USERMESSAGE_PRIORITIES.items():
            create_if_needed(UserMessagePriority, {'pk': pk},
                             title=str(title),
                             is_custom=False)

        SettingValue.objects.get_or_create(key_id=todo_reminder_key.id,
                                           defaults={'value': 9})

        Job.objects.get_or_create(
            type_id=usermessages_send_type.id,
            defaults={
                'language': settings.LANGUAGE_CODE,
                'status': Job.STATUS_OK,
            },
        )

        if not already_populated:
            RIGHT = BrickDetailviewLocation.RIGHT
            BrickDetailviewLocation.create_if_needed(brick_id=TodosBrick.id_,
                                                     order=100,
                                                     zone=RIGHT)
            BrickDetailviewLocation.create_if_needed(brick_id=MemosBrick.id_,
                                                     order=200,
                                                     zone=RIGHT)
            BrickDetailviewLocation.create_if_needed(brick_id=AlertsBrick.id_,
                                                     order=300,
                                                     zone=RIGHT)
            BrickDetailviewLocation.create_if_needed(
                brick_id=UserMessagesBrick.id_, order=400, zone=RIGHT)

            # BlockPortalLocation.create_or_update(brick_id=MemosBrick.id_,        order=100)
            # BlockPortalLocation.create_or_update(brick_id=AlertsBrick.id_,       order=200)
            # BlockPortalLocation.create_or_update(brick_id=UserMessagesBrick.id_, order=300)

            # BlockPortalLocation.create_or_update(app_name='creme_core', brick_id=MemosBrick.id_,        order=100)
            # BlockPortalLocation.create_or_update(app_name='creme_core', brick_id=AlertsBrick.id_,       order=200)
            # BlockPortalLocation.create_or_update(app_name='creme_core', brick_id=UserMessagesBrick.id_, order=300)
            BrickHomeLocation.objects.create(brick_id=MemosBrick.id_,
                                             order=100)
            BrickHomeLocation.objects.create(brick_id=AlertsBrick.id_,
                                             order=200)
            BrickHomeLocation.objects.create(brick_id=UserMessagesBrick.id_,
                                             order=300)
示例#6
0
    def test_create_detailview02(self):
        "For a ContentType"
        self.assertFalse(BrickDetailviewLocation.config_exists(FakeContact))

        order = 4
        zone = BrickDetailviewLocation.LEFT
        brick_id = PropertiesBrick.id_
        loc = BrickDetailviewLocation.create_if_needed(brick_id=brick_id, order=order, zone=zone, model=FakeContact)
        loc = self.get_object_or_fail(BrickDetailviewLocation, pk=loc.pk)
        self.assertEqual(FakeContact, loc.content_type.model_class())
        self.assertEqual(brick_id, loc.brick_id)
        self.assertEqual(order,    loc.order)
        self.assertEqual(zone,     loc.zone)

        self.assertTrue(BrickDetailviewLocation.config_exists(FakeContact))
示例#7
0
    def test_create_detailview01(self):  # DEPRECATED
        "Default configuration."
        order = 25
        zone = BrickDetailviewLocation.TOP
        brick_id = RelationsBrick.id_
        loc = BrickDetailviewLocation.create_if_needed(brick_id=brick_id,
                                                       order=order,
                                                       zone=zone)
        self.assertIsInstance(loc, BrickDetailviewLocation)

        loc = self.get_object_or_fail(BrickDetailviewLocation, pk=loc.pk)
        self.assertIsNone(loc.content_type)
        self.assertEqual(brick_id, loc.brick_id)
        self.assertEqual(order, loc.order)
        self.assertEqual(zone, loc.zone)
示例#8
0
    def test_display_custombrick02(self):
        "With FieldsConfig"
        user = self.login()

        hidden_fname = 'phone'
        FieldsConfig.create(
            FakeContact,
            descriptions=[(hidden_fname, {
                FieldsConfig.HIDDEN: True
            })],
        )
        build_cell = EntityCellRegularField.build
        cbc_item = CustomBrickConfigItem.objects.create(
            id='tests-contacts1',
            name='Contact info',
            content_type=ContentType.objects.get_for_model(FakeContact),
            cells=[
                build_cell(FakeContact, 'last_name'),
                build_cell(FakeContact, hidden_fname),
            ],
        )
        bdl = BrickDetailviewLocation.create_if_needed(
            brick_id=cbc_item.generate_id(),
            order=1000,
            model=FakeContact,
            zone=BrickDetailviewLocation.BOTTOM,
        )
        naru = FakeContact.objects.create(
            user=user,
            last_name='Narusegawa',
            first_name='Naru',
            phone='1122334455',
        )

        content_node = self._get_contact_brick_content(naru,
                                                       brick_id=bdl.brick_id)
        self.assertEqual(
            naru.last_name,
            self.get_brick_tile(content_node, 'regular_field-last_name').text)
        self._assertNoBrickTile(content_node, 'regular_field-phone')
示例#9
0
    def test_display_custombrick01(self):
        user = self.login()

        fname1 = 'last_name'
        fname2 = 'phone'
        build_cell = EntityCellRegularField.build
        cbc_item = CustomBrickConfigItem.objects.create(
            id='tests-contacts1',
            name='Contact info',
            content_type=ContentType.objects.get_for_model(FakeContact),
            cells=[
                build_cell(FakeContact, fname1),
                build_cell(FakeContact, fname2),
            ],
        )
        bdl = BrickDetailviewLocation.create_if_needed(
            brick_id=cbc_item.generate_id(),
            order=1000,
            model=FakeContact,
            zone=BrickDetailviewLocation.BOTTOM,
        )
        naru = FakeContact.objects.create(
            user=user,
            last_name='Narusegawa',
            first_name='Naru',
            phone='1122334455',
        )

        content_node = self._get_contact_brick_content(naru,
                                                       brick_id=bdl.brick_id)
        self.assertEqual(
            naru.last_name,
            self.get_brick_tile(content_node, 'regular_field-last_name').text)
        self.assertIn(
            naru.phone,
            self.get_brick_tile(content_node, 'regular_field-phone').text)