示例#1
0
    def test_creation_forms_item07(self):
        "Credentials"
        user = self.login(is_superuser=False, creatable_models=[FakeContact])
        cfi = CreationFormsItem('any_forms', label='Other type of entity')

        cfi.get_or_create_group('persons', 'Directory') \
           .add_link('add_contact', FakeContact) \
           .add_link('add_orga',    FakeOrganisation)
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Test Contact',
                            'url': '/tests/contact/add'
                        },
                        {
                            'label': 'Test Organisation'
                        },
                    ],
                },
            ],
        ], cfi.as_grid(user))
示例#2
0
    def test_creation_forms_item05(self):
        "Group priority"
        user = self.login()
        cfi = CreationFormsItem('any_forms', label=u'Other type of entity')

        cfi.get_or_create_group('persons', u'Directory', priority=10).add_link('add_contact', FakeContact)
        cfi.get_or_create_group('tools', u'Tools', priority=2).add_link('add_doc', FakeDocument)

        self.assertEqual(
            [[{'label': u'Tools',
               'links': [{'label': 'Test Document', 'url': ''}],
              },
             ],
             [{'label': u'Directory',
               'links': [{'label': 'Test Contact', 'url': '/tests/contact/add'}],
              },
             ],
            ],
            cfi.as_grid(user)
        )

        cfi.change_priority(1, 'persons')
        self.assertEqual(
            [[{'label': u'Directory',
               'links': [{'label': 'Test Contact', 'url': '/tests/contact/add'}],
              },
             ],
             [{'label': u'Tools',
               'links': [{'label': 'Test Document', 'url': ''}],
              },
             ],
            ],
            cfi.as_grid(user)
        )
示例#3
0
    def test_creation_forms_item08(self):
        "ID uniqueness"
        cfi = CreationFormsItem('any_forms', label='Other type of entity')

        group = cfi.get_or_create_group('persons', 'Directory') \
                   .add_link('add_contact', FakeContact)

        with self.assertRaises(ValueError):
            group.add_link('add_contact', FakeContact, label='Contact')
示例#4
0
    def test_creation_forms_item04(self):
        "Remove Link"
        user = self.login()
        cfi = CreationFormsItem('any_forms', label=u'Other type of entity')
        group = cfi.get_or_create_group('persons', u'Directory')

        group.add_link('add_contact', FakeContact) \
             .add_link('add_orga',    FakeOrganisation) \
             .add_link('add_propect', label='Propect', url='/tests/propect/add', perm='creme_core.add_fakecontact')

        group.remove('add_contact', 'add_propect', 'invalid')
        self.assertEqual(
            [[{'label': u'Directory',
               'links': [{'label': 'Test Organisation', 'url': '/tests/organisation/add'}],
              },
             ],
            ],
            cfi.as_grid(user)
        )
示例#5
0
    def test_creation_forms_item06(self):
        "Remove Group"
        user = self.login()
        cfi = CreationFormsItem('any_forms', label='Other type of entity')

        cfi.get_or_create_group('tools',
                                'Tools').add_link('add_doc', FakeDocument)
        cfi.get_or_create_group('persons',
                                'Directory').add_link('add_contact',
                                                      FakeContact)
        cfi.get_or_create_group('activities',
                                'Activities').add_link('add_act', FakeActivity)

        cfi.remove('tools', 'activities', 'unknown')
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [{
                        'label': 'Test Contact',
                        'url': '/tests/contact/add'
                    }],
                },
            ],
        ], cfi.as_grid(user))
示例#6
0
    def test_creation_forms_item03(self):
        "Link priority"
        user = self.login()
        cfi = CreationFormsItem('any_forms', label='Other type of entity')
        group = cfi.get_or_create_group('persons', 'Directory')

        group.add_link('add_contact', FakeContact,      priority=10) \
             .add_link('add_orga',    FakeOrganisation, priority=5)
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Test Organisation',
                            'url': '/tests/organisation/add'
                        },
                        {
                            'label': 'Test Contact',
                            'url': '/tests/contact/add'
                        },
                    ],
                },
            ],
        ], cfi.as_grid(user))

        group.add_link('add_customer',
                       label='Customer',
                       url='/tests/customer/add',
                       perm='creme_core.add_fakecontact')
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Test Organisation',
                            'url': '/tests/organisation/add'
                        },
                        {
                            'label': 'Test Contact',
                            'url': '/tests/contact/add'
                        },
                        {
                            'label': 'Customer',
                            'url': '/tests/customer/add'
                        },
                    ],
                },
            ],
        ], cfi.as_grid(user))

        group.add_link(
            'add_propect',
            label='Prospect',
            url='/tests/prospect/add',
            perm='creme_core.add_fakecontact',
            priority=15,
        )
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Test Organisation',
                            'url': '/tests/organisation/add'
                        },
                        {
                            'label': 'Test Contact',
                            'url': '/tests/contact/add'
                        },
                        {
                            'label': 'Customer',
                            'url': '/tests/customer/add'
                        },
                        {
                            'label': 'Prospect',
                            'url': '/tests/prospect/add'
                        },
                    ],
                },
            ],
        ], cfi.as_grid(user))

        group.change_priority(1, 'add_propect', 'add_customer')
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Prospect',
                            'url': '/tests/prospect/add'
                        },
                        {
                            'label': 'Customer',
                            'url': '/tests/customer/add'
                        },
                        {
                            'label': 'Test Organisation',
                            'url': '/tests/organisation/add'
                        },
                        {
                            'label': 'Test Contact',
                            'url': '/tests/contact/add'
                        },
                    ],
                },
            ],
        ], cfi.as_grid(user))

        with self.assertRaises(KeyError):
            group.change_priority(2, 'add_customer', 'unknown')
示例#7
0
    def test_creation_forms_item02(self):
        "Simplified API"
        user = self.login()
        cfi = CreationFormsItem('any_forms', label='Other type of entity')

        cfi.get_or_create_group('persons',
                                'Directory').add_link('add_contact',
                                                      FakeContact)
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [{
                        'label': 'Test Contact',
                        'url': '/tests/contact/add'
                    }],
                },
            ],
        ], cfi.as_grid(user))

        # ----
        cfi = CreationFormsItem('any_forms', label='Other types')

        label = 'Contact'
        url = '/tests/customer/add'
        cfi.get_or_create_group('persons', 'Directory')\
           .add_link('add_contact', FakeContact, label=label, url=url)
        self.assertEqual([
            [
                {
                    'label': 'Directory',
                    'links': [{
                        'label': label,
                        'url': url
                    }],
                },
            ],
        ], cfi.as_grid(user))

        # ----
        group = CreationFormsItem('any_forms',
                                  label='Other types').get_or_create_group(
                                      'persons', 'Directory')

        with self.assertRaises(TypeError):
            group.add_link('add_contact', label=label,
                           url=url)  # No model + missing perm
示例#8
0
    def test_creation_forms_item01(self):
        user = self.login()
        cfi = CreationFormsItem('any_forms', label='Other type of entity')

        cfi.get_or_create_group('persons', 'Directory') \
           .add_link('add_contact', label='Contact', url='/tests/contact/add', perm='creme_core.add_fakecontact')
        self.assertEqual(
            [[{
                'label': 'Directory',
                'links': [{
                    'label': 'Contact',
                    'url': '/tests/contact/add'
                }]
            }]], cfi.as_grid(user))

        cfi.get_or_create_group('persons', 'Directory') \
           .add_link('add_orga', label='Organisation', url='/tests/organisation/add', perm='creme_core.add_fakeorganisation')
        self.assertEqual([[
            {
                'label':
                'Directory',
                'links': [
                    {
                        'label': 'Contact',
                        'url': '/tests/contact/add'
                    },
                    {
                        'label': 'Organisation',
                        'url': '/tests/organisation/add'
                    },
                ],
            },
        ]], cfi.as_grid(user))

        cfi.get_or_create_group('activities', 'Activities') \
           .add_link('add_pcall',   label='Phone call', url='/tests/phone_call/add', perm='creme_core.add_fakeactivity') \
           .add_link('add_meeting', label='Meeting',    url='/tests/meeting/add',    perm='creme_core.add_fakeactivity')
        cfi.get_or_create_group('tools', 'Tools')\
           .add_link('add_doc', label='Document', url='/tests/document/add', perm='creme_core.add_fakedocument')
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Contact',
                            'url': '/tests/contact/add'
                        },
                        {
                            'label': 'Organisation',
                            'url': '/tests/organisation/add'
                        },
                    ],
                },
            ],
            [
                {
                    'label':
                    'Activities',
                    'links': [
                        {
                            'label': 'Phone call',
                            'url': '/tests/phone_call/add'
                        },
                        {
                            'label': 'Meeting',
                            'url': '/tests/meeting/add'
                        },
                    ],
                },
                {
                    'label': 'Tools',
                    'links': [{
                        'label': 'Document',
                        'url': '/tests/document/add'
                    }],
                },
            ],
        ], cfi.as_grid(user))

        cfi.get_or_create_group('analysis', 'Analysis')\
           .add_link('add_report', label='Report', url='/tests/report/add', perm='creme_core.add_fakereport')
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Contact',
                            'url': '/tests/contact/add'
                        },
                        {
                            'label': 'Organisation',
                            'url': '/tests/organisation/add'
                        },
                    ],
                },
                {
                    'label':
                    'Activities',
                    'links': [
                        {
                            'label': 'Phone call',
                            'url': '/tests/phone_call/add'
                        },
                        {
                            'label': 'Meeting',
                            'url': '/tests/meeting/add'
                        },
                    ],
                },
            ],
            [
                {
                    'label': 'Tools',
                    'links': [{
                        'label': 'Document',
                        'url': '/tests/document/add'
                    }],
                },
                {
                    'label': 'Analysis',
                    'links': [{
                        'label': 'Report',
                        'url': '/tests/report/add'
                    }],
                },
            ],
        ], cfi.as_grid(user))

        cfi.get_or_create_group('management', 'Management') \
           .add_link('add_invoice', label='Invoice', url='/tests/invoice/add', perm='creme_core.add_fakeinvoice')
        self.assertEqual(
            [[
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Contact',
                            'url': '/tests/contact/add'
                        },
                        {
                            'label': 'Organisation',
                            'url': '/tests/organisation/add'
                        },
                    ],
                },
            ],
             [
                 {
                     'label':
                     'Activities',
                     'links': [
                         {
                             'label': 'Phone call',
                             'url': '/tests/phone_call/add'
                         },
                         {
                             'label': 'Meeting',
                             'url': '/tests/meeting/add'
                         },
                     ],
                 },
                 {
                     'label':
                     'Tools',
                     'links': [{
                         'label': 'Document',
                         'url': '/tests/document/add'
                     }],
                 },
             ],
             [
                 {
                     'label': 'Analysis',
                     'links': [{
                         'label': 'Report',
                         'url': '/tests/report/add'
                     }],
                 },
                 {
                     'label': 'Management',
                     'links': [{
                         'label': 'Invoice',
                         'url': '/tests/invoice/add'
                     }],
                 },
             ]], cfi.as_grid(user))

        cfi.get_or_create_group('commercial', 'Commercial') \
           .add_link('add_act', label='Act', url='/tests/act/add', perm='creme_core')
        self.assertEqual(
            [[
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Contact',
                            'url': '/tests/contact/add'
                        },
                        {
                            'label': 'Organisation',
                            'url': '/tests/organisation/add'
                        },
                    ],
                },
                {
                    'label':
                    'Activities',
                    'links': [
                        {
                            'label': 'Phone call',
                            'url': '/tests/phone_call/add'
                        },
                        {
                            'label': 'Meeting',
                            'url': '/tests/meeting/add'
                        },
                    ],
                },
            ],
             [
                 {
                     'label':
                     'Tools',
                     'links': [{
                         'label': 'Document',
                         'url': '/tests/document/add'
                     }],
                 },
                 {
                     'label': 'Analysis',
                     'links': [{
                         'label': 'Report',
                         'url': '/tests/report/add'
                     }],
                 },
             ],
             [
                 {
                     'label': 'Management',
                     'links': [{
                         'label': 'Invoice',
                         'url': '/tests/invoice/add'
                     }],
                 },
                 {
                     'label': 'Commercial',
                     'links': [{
                         'label': 'Act',
                         'url': '/tests/act/add'
                     }],
                 },
             ]], cfi.as_grid(user))

        cfi.get_or_create_group('marketing', 'Marketing') \
           .add_link('add_campaign', label='Campaign', url='/tests/campaign/add', perm='creme_core')
        self.assertEqual([
            [
                {
                    'label':
                    'Directory',
                    'links': [
                        {
                            'label': 'Contact',
                            'url': '/tests/contact/add'
                        },
                        {
                            'label': 'Organisation',
                            'url': '/tests/organisation/add'
                        },
                    ],
                },
                {
                    'label':
                    'Activities',
                    'links': [
                        {
                            'label': 'Phone call',
                            'url': '/tests/phone_call/add'
                        },
                        {
                            'label': 'Meeting',
                            'url': '/tests/meeting/add'
                        },
                    ],
                },
            ],
            [
                {
                    'label': 'Tools',
                    'links': [{
                        'label': 'Document',
                        'url': '/tests/document/add'
                    }],
                },
                {
                    'label': 'Analysis',
                    'links': [{
                        'label': 'Report',
                        'url': '/tests/report/add'
                    }],
                },
            ],
            [
                {
                    'label': 'Management',
                    'links': [{
                        'label': 'Invoice',
                        'url': '/tests/invoice/add'
                    }],
                },
                {
                    'label': 'Commercial',
                    'links': [{
                        'label': 'Act',
                        'url': '/tests/act/add'
                    }],
                },
                {
                    'label': 'Marketing',
                    'links': [{
                        'label': 'Campaign',
                        'url': '/tests/campaign/add'
                    }],
                },
            ]
        ], cfi.as_grid(user))