Beispiel #1
0
def _get_test_user(group=admin_group):
    """ Get a test user. """
    u = User(email=fake.safe_email(),
             password=fake.password(),
             groups=[
                 group,
             ])
    u.save()
    return u
Beispiel #2
0
 def setUp(self):
     e = fake.safe_email()
     group = Group.objects(name='admin').first()
     if group is None:
         group = Group(name='admin')
         group.save()
     self.admin = User.objects(email=e).first()
     if self.admin is None:
         self.admin = User(email=e,
                           groups=[group, ],
                           password=fake.password(length=16))
         self.admin.save()
Beispiel #3
0
    def test_permissions(self):
        """ Permission configured correctly. """
        group_admin = Group(name='admin')
        group_desktop = Group(name='desktop', permissions=[
            'p1',
        ])
        group_other = Group(name='another', permissions=[
            'p2',
        ])
        # group_under = Group(name='underprivileged')

        admin = User(email=fake.safe_email(),
                     password=fake.password(),
                     groups=[
                         group_admin,
                     ])
        admin.save()
        desktop = User(email=fake.safe_email(),
                       password=fake.password(),
                       groups=[
                           group_desktop,
                           group_other,
                       ])
        desktop.save()
        user = User(email=fake.safe_email(), password=fake.password())
        user.save()

        self.assertTrue(admin.is_admin)
        self.assertFalse(desktop.is_admin)
        self.assertFalse(user.is_admin)

        self.assertListEqual(desktop.all_permissions, ['p1', 'p2'])

        self.assertTrue(admin.can_any('something', 'another_thing'))
        self.assertTrue(admin.can_all('something', 'another_thing'))
        self.assertTrue(desktop.can_all('p1', 'p2'))
        self.assertTrue(desktop.can_any('p1', 'run_marathon'))
        self.assertFalse(desktop.can_any('save_the_world', 'run_marathon'))
        self.assertFalse(user.can_any('p1', 'p2', 'p3'))
        self.assertFalse(user.can_any())
Beispiel #4
0
 def test_add_user(self):
     """ User can be added to a group; can be listed from Group.users. """
     user = User(email=fake.safe_email(), password=fake.password())
     user.save()
     group_a = Group(name='group_a', permissions=[
         'create_post',
     ])
     group_a.save()
     group_b = Group(name='group_b', permissions=[
         'delete_post',
     ])
     group_b.save()
     user.groups.append(group_a)
     user.save()
     self.assertTrue(group_a in user.groups)
     group_a_users = group_a.users
     self.assertIn(user, group_a_users)
     self.assertNotIn(user, group_b.users)
     logger.info('User: {}'.format(user))
     logger.info('Group: {}'.format(group_a))
Beispiel #5
0
 def test_user_create(self):
     """ User can be created. """
     user = User(email=fake.safe_email(), password=fake.password())
     user.save()
     self.assertGreater(len(User.objects), 0)