Beispiel #1
0
def create_user(admin=True):
    role = UserRole(name='Average')
    if admin:
        role.admin_4_apps = ['creme_core']
    else:
        role.allowed_apps = ['creme_core']

    role.save()

    return get_user_model().objects.create(
        username='******',
        first_name='Joe',
        last_name='Average',
        email='*****@*****.**',
        role=role,
    )
Beispiel #2
0
    def test_actions_admin(self):
        field = CreatorModelChoiceField(queryset=FakeSector.objects.all())

        role = UserRole(name='CEO')
        role.admin_4_apps = ['creme_core']
        role.save()

        field.user = get_user_model().objects.create(username='******',
                                                     role=role)

        render_str = field.widget.render('sector', None)
        self.assertIn(self.ADD_URL, render_str)
        self.assertIn(str(FakeSector.creation_label), render_str)

        field.user = None
        render_str = field.widget.render('sector', None)
        self.assertNotIn(self.ADD_URL, render_str)
Beispiel #3
0
    def test_actions_admin(self):
        field = CreatorModelChoiceField(queryset=FakePosition.objects.all())

        role = UserRole(name='CEO')
        role.admin_4_apps = ['creme_core']
        role.save()

        admin = get_user_model().objects.create(username='******', role=role)
        admin.role = role

        field.user = admin

        render_str = field.widget.render('position', None)
        self.assertIn(self.ADD_URL, render_str)
        self.assertIn(_(u'Create'), render_str)

        field.user = None
        render_str = field.widget.render('position', None)
        self.assertNotIn(self.ADD_URL, render_str)
Beispiel #4
0
    def test_actions_admin_no_creatable(self):
        field = CreatorModelChoiceField(queryset=FakePosition.objects.all())

        role = UserRole(name='CEO')
        role.admin_4_apps = ['creme_core']
        role.save()

        field.user = get_user_model().objects.create(username='******',
                                                     role=role)

        render_str = field.widget.render('position', None)
        self.assertNotIn(
            reverse(
                'creme_config__create_instance_from_widget',
                args=('creme_core', 'fake_position'),
            ),
            render_str,
        )
        self.assertNotIn(str(FakePosition.creation_label), render_str)