Пример #1
0
class OdaApiTestCase(APITestCase):
    TEST_USERNAME = "******"

    def setUp(self):
        self.user = OdaUser(username=self.TEST_USERNAME)
        self.user.save()
        load_examples(self.user)
        self.client.force_login(self.user)
Пример #2
0
    def test_get_detail_non_owner(self):
        otheruser = OdaUser(username='******')
        otheruser.save()
        othergroup = Group.objects.create(name='othergroup')
        otheruser.groups.add(othergroup)

        response = self.client.get('/odaweb/api/usergroups/' +
                                   str(othergroup.pk) + '/',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Пример #3
0
    def test_user_add_non_owner(self):
        group = Group.objects.create(name='mygroup')
        otheruser = OdaUser(username='******')
        otheruser.save()
        otheruser.groups.add(group)

        response = self.client.post('/odaweb/api/usergroups/' + str(group.pk) +
                                    '/user/', {'username': self.TEST_USERNAME},
                                    format='json')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Пример #4
0
    def test_permission_create_user(self):
        otheruser = OdaUser(username='******')
        otheruser.save()

        response = self.client.post('/odaweb/api/masters/mkdir/permission/', {
            'username': '******',
            'permission': 'read',
        },
                                    format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Пример #5
0
    def test_missing_permission(self):
        otheruser = OdaUser(username='******')
        otheruser.save()

        response = self.client.post('/odaweb/api/masters/mkdir/permission/', {
            'username': '******',
            'permission': 'does_not_exist',
        },
                                    format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn('Permission', response.data['detail'])
Пример #6
0
    def test_list_permissions_on_oda_master(self):
        otheruser = OdaUser(username='******')
        otheruser.save()

        oda_master = OdaMaster.get_by_short_name('mkdir')
        perm = Permission.objects.get(codename='read_odamaster')

        OdaMasterPermission.objects.create(master=oda_master,
                                           user=otheruser,
                                           permission=perm)

        response = self.client.get('/odaweb/api/masters/mkdir/', format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['permissions'][0]['username'],
                         'otheruser')
        self.assertEqual(response.data['permissions'][0]['permission'], 'read')
Пример #7
0
    def test_user_add(self):
        group = Group.objects.create(name='mygroup')
        self.user.groups.add(group)

        response = self.client.get('/odaweb/api/usergroups/' + str(group.pk) +
                                   '/',
                                   format='json')
        self.assertEqual(response.data['name'], 'mygroup')
        self.assertEqual(response.data['users'][0]['username'],
                         self.TEST_USERNAME)

        otheruser = OdaUser(username='******')
        otheruser.save()

        response = self.client.post('/odaweb/api/usergroups/' + str(group.pk) +
                                    '/user/', {'username': '******'},
                                    format='json')
        self.assertEqual(response.data['users'][1]['username'], 'otheruser')
Пример #8
0
    def test_get_list(self):
        response = self.client.get('/odaweb/api/usergroups/', format='json')
        self.assertEqual(response.data, [])

        group = Group.objects.create(name='mygroup')
        self.user.groups.add(group)

        response = self.client.get('/odaweb/api/usergroups/', format='json')
        self.assertEqual(response.data[0]['name'], 'mygroup')

        otheruser = OdaUser(username='******')
        otheruser.save()
        othergroup = Group.objects.create(name='othergroup')
        otheruser.groups.add(othergroup)

        response = self.client.get('/odaweb/api/usergroups/', format='json')
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], 'mygroup')
Пример #9
0
    def test_permission_delete_user(self):
        otheruser = OdaUser(username='******')
        otheruser.save()

        oda_master = OdaMaster.get_by_short_name('mkdir')
        perm = Permission.objects.get(codename='read_odamaster')

        OdaMasterPermission.objects.create(master=oda_master,
                                           user=otheruser,
                                           permission=perm)

        response = self.client.delete('/odaweb/api/masters/mkdir/permission/',
                                      {
                                          'username': '******',
                                          'permission': 'read',
                                      },
                                      format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Пример #10
0
    def test_user_remove(self):
        group = Group.objects.create(name='mygroup')
        self.user.groups.add(group)
        otheruser = OdaUser(username='******')
        otheruser.save()
        otheruser.groups.add(group)

        response = self.client.delete('/odaweb/api/usergroups/' +
                                      str(group.pk) + '/user/',
                                      {'username': '******'},
                                      format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        response = self.client.get('/odaweb/api/usergroups/' + str(group.pk) +
                                   '/',
                                   format='json')
        self.assertEqual(len(response.data['users']), 1)
        self.assertEqual(response.data['users'][0]['username'],
                         self.TEST_USERNAME)
Пример #11
0
 def setUp(self):
     self.user = OdaUser(username=self.TEST_USERNAME)
     self.user.save()
     load_examples(self.user)
     self.client.force_login(self.user)