Beispiel #1
0
    def test_create_tenant_group_ok(self):
        # Create a second tenant group
        tenant_group_data = {
            'name':
            'group2',
            'attached_projects':
            json.dumps(['tenant1_id', 'tenant2_id', 'tenant3_id'])
        }
        request = self.factory.post('/projects/groups',
                                    tenant_group_data,
                                    format='json')
        response = add_projects_group(request)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        request = self.factory.get('/projects/groups')
        response = add_projects_group(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        tenants_groups = json.loads(response.content)
        self.assertEqual(len(tenants_groups), 2)  # 2 groups
        for tenants_group in tenants_groups:
            if tenants_group['name'] == 'group2':
                attached_projects = tenants_group['attached_projects']
                self.assertEqual(len(attached_projects),
                                 3)  # 3 tenants in the 2nd group
                self.assertTrue('tenant1_id' in attached_projects)
                self.assertTrue('tenant2_id' in attached_projects)
                self.assertTrue('tenant3_id' in attached_projects)
Beispiel #2
0
    def test_update_tenant_group_ok(self):
        gtenant_id = '1'
        tenant_group_data = {
            'name':
            'group1',
            'attached_projects':
            json.dumps(['0123456789abcdef', 'abcdef0123456789', '3333333333'])
        }
        request = self.factory.put('/projects/groups/' + gtenant_id,
                                   tenant_group_data,
                                   format='json')
        response = projects_group_detail(request, gtenant_id)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        # Check the object type was updated properly
        request = self.factory.get('/projects/groups')
        response = add_projects_group(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        tenants_groups = json.loads(response.content)
        self.assertEqual(len(tenants_groups), 1)  # 1 group
        self.assertEqual(len(tenants_groups[0]['attached_projects']),
                         3)  # 3 tenants in the group
        self.assertTrue(
            '0123456789abcdef' in tenants_groups[0]['attached_projects'])
        self.assertTrue(
            'abcdef0123456789' in tenants_groups[0]['attached_projects'])
        self.assertTrue('3333333333' in tenants_groups[0]['attached_projects'])
Beispiel #3
0
 def test_create_tenant_group_with_empty_data(self):
     # Create a second tenant group with empty data --> ERROR
     tenant_group_data = {}
     request = self.factory.post('/projects/groups',
                                 tenant_group_data,
                                 format='json')
     response = add_projects_group(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Beispiel #4
0
 def test_list_tenants_group_ok(self):
     request = self.factory.get('/projects/groups')
     response = add_projects_group(request)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     tenants_groups = json.loads(response.content)
     self.assertEqual(len(tenants_groups), 1)  # 1 group
     attached_projects = tenants_groups[0]['attached_projects']
     self.assertEqual(len(attached_projects), 2)  # 2 tenants in the group
     self.assertTrue('0123456789abcdef' in attached_projects)
     self.assertTrue('abcdef0123456789' in attached_projects)
Beispiel #5
0
 def create_tenant_group_1(self):
     tenant_group_data = {
         'name':
         'group1',
         'attached_projects':
         json.dumps(['0123456789abcdef', 'abcdef0123456789'])
     }
     request = self.factory.post('/projects/groups',
                                 tenant_group_data,
                                 format='json')
     response = add_projects_group(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Beispiel #6
0
    def test_delete_tenant_group_ok(self):
        gtenant_id = '1'
        request = self.factory.delete('/projects/groups/' + gtenant_id)
        response = projects_group_detail(request, gtenant_id)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        request = self.factory.get('/projects/groups')
        response = add_projects_group(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.content, "[]")
        tenants_groups = json.loads(response.content)
        self.assertEqual(len(tenants_groups), 0)
Beispiel #7
0
    def test_delete_tenant_group_with_non_existent_id(self):
        gtenant_id = '2'
        request = self.factory.delete('/projects/groups/' + gtenant_id)
        response = projects_group_detail(request, gtenant_id)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        # Check nothing was deleted
        request = self.factory.get('/projects/groups')
        response = add_projects_group(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertNotEqual(response.content, "[]")
        tenants_groups = json.loads(response.content)
        self.assertEqual(len(tenants_groups), 1)  # 1 group
        self.assertEqual(len(tenants_groups[0]['attached_projects']),
                         2)  # 2 tenants in the group
Beispiel #8
0
    def test_delete_individual_tenant_from_group_ok(self):
        gtenant_id = '1'
        tenant_id = '0123456789abcdef'
        request = self.factory.delete('/projects/groups/' + gtenant_id +
                                      '/projects/' + tenant_id)
        response = projects_groups_detail(request, gtenant_id, tenant_id)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # Check delete was successful
        request = self.factory.get('/projects/groups')
        response = add_projects_group(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        tenants_groups = json.loads(response.content)
        self.assertEqual(len(tenants_groups), 1)
        self.assertEqual(len(tenants_groups[0]['attached_projects']), 1)
        self.assertFalse(
            '0123456789abcdef' in tenants_groups[0]['attached_projects'])
        self.assertTrue(
            'abcdef0123456789' in tenants_groups[0]['attached_projects'])
 def create_tenant_group_1(self):
     tenant_group_data = {'name': 'group1', 'attached_projects': json.dumps(['0123456789abcdef', 'abcdef0123456789'])}
     request = self.factory.post('/projects/groups', tenant_group_data, format='json')
     response = add_projects_group(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Beispiel #10
0
 def test_add_tenants_group_with_method_not_allowed(self):
     request = self.factory.delete('/projects/groups')
     response = add_projects_group(request)
     self.assertEqual(response.status_code,
                      status.HTTP_405_METHOD_NOT_ALLOWED)