Beispiel #1
0
    def test_create_object_type_ok(self):
        # Create a second object type:
        object_type_data = {'name': 'VIDEO', 'types_list': ['avi', 'mkv']}
        request = self.factory.post('/policies/object_type', object_type_data, format='json')
        response = object_type_list(request)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        # obtain the list
        request = self.factory.get('/policies/object_type')
        response = object_type_list(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertNotEqual(response.content, "[]")
        object_types = json.loads(response.content)
        self.assertEqual(len(object_types), 2)
Beispiel #2
0
    def test_delete_object_type_ok(self):
        name = 'DOCS'
        request = self.factory.delete('/policies/object_type/' + name)
        response = object_type_detail(request, name)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        request = self.factory.get('/policies/object_type')
        response = object_type_list(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.content, "[]")
Beispiel #3
0
    def test_list_object_types_ok(self):
        request = self.factory.get('/policies/object_type')
        response = object_type_list(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertNotEqual(response.content, "[]")

        object_types = json.loads(response.content)

        self.assertEqual(object_types[0]['name'], "DOCS")
        self.assertEqual(len(object_types[0]['types_list']), 3)
Beispiel #4
0
    def test_delete_object_type_with_non_existent_name(self):
        name = 'AUDIO'
        request = self.factory.delete('/policies/object_type/' + name)
        response = object_type_detail(request, name)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        # Check nothing was deleted
        request = self.factory.get('/policies/object_type')
        response = object_type_list(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertNotEqual(response.content, "[]")
        object_types = json.loads(response.content)
        self.assertEqual(object_types[0]['name'], "DOCS")
Beispiel #5
0
    def test_update_object_type_ok_with_more_extensions(self):
        name = 'DOCS'
        data = ['txt', 'doc', 'docx', 'odt']
        request = self.factory.put('/policies/object_type/' + name, data, format='json')
        response = object_type_detail(request, name)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        # Check the object type was updated properly
        request = self.factory.get('/policies/object_type')
        response = object_type_list(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertNotEqual(response.content, "[]")
        object_types = json.loads(response.content)
        self.assertEqual(len(object_types), 1)
        self.assertEqual(object_types[0]['name'], "DOCS")
        self.assertEqual(len(object_types[0]['types_list']), 4)
        for extension in data:
            self.assertTrue(extension in object_types[0]['types_list'])
Beispiel #6
0
 def create_object_type_docs(self):
     object_type_data = {'name': 'DOCS', 'types_list': ['txt', 'doc', 'docx']}
     request = self.factory.post('/controller/object_type', object_type_data, format='json')
     response = object_type_list(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Beispiel #7
0
 def test_create_object_type_with_empty_types_list(self):
     # Create a second object type with empty types_list --> ERROR
     object_type_data = {'name': 'VIDEO', 'types_list': []}
     request = self.factory.post('/policies/object_type', object_type_data, format='json')
     response = object_type_list(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Beispiel #8
0
 def test_create_object_type_with_an_existing_name(self):
     # Create a second object type with an existing name --> ERROR
     object_type_data = {'name': 'DOCS', 'types_list': ['avi', 'mkv']}
     request = self.factory.post('/policies/object_type', object_type_data, format='json')
     response = object_type_list(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Beispiel #9
0
 def test_object_type_list_with_method_not_allowed(self):
     request = self.factory.delete('/policies/object_type')
     response = object_type_list(request)
     self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)