diff --git a/mayan/apps/documents/tests/test_api.py b/mayan/apps/documents/tests/test_api.py index 571c9b7eb0..79a7de09bf 100644 --- a/mayan/apps/documents/tests/test_api.py +++ b/mayan/apps/documents/tests/test_api.py @@ -6,8 +6,6 @@ import time from json import loads -from django.contrib.auth import get_user_model - from django.core.urlresolvers import reverse from django.test import override_settings from django.utils.six import BytesIO @@ -15,38 +13,24 @@ from django.utils.six import BytesIO from rest_framework import status from rest_framework.test import APITestCase -from organizations.utils import create_default_organization +from rest_api.tests.base import GenericAPITestCase from user_management.tests.literals import ( TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME ) from .literals import ( TEST_DOCUMENT_FILENAME, TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE, - TEST_SMALL_DOCUMENT_CHECKSUM, TEST_SMALL_DOCUMENT_PATH, + TEST_DOCUMENT_TYPE_EDITED_LABEL, TEST_SMALL_DOCUMENT_CHECKSUM, + TEST_SMALL_DOCUMENT_PATH, ) from ..models import Document, DocumentType, HASH_FUNCTION -class DocumentTypeAPITestCase(APITestCase): +class DocumentTypeAPITestCase(GenericAPITestCase): """ Test the document type API endpoints """ - def setUp(self): - create_default_organization() - - self.admin_user = get_user_model().objects.create_superuser( - username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, - password=TEST_ADMIN_PASSWORD - ) - - self.client.login( - username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD - ) - - def tearDown(self): - self.admin_user.delete() - def test_document_type_create(self): self.assertEqual(DocumentType.on_organization.all().count(), 0) @@ -67,26 +51,30 @@ class DocumentTypeAPITestCase(APITestCase): label=TEST_DOCUMENT_TYPE ) - self.client.put( + response = self.client.put( reverse('rest_api:documenttype-detail', args=(document_type.pk,)), - {'label': TEST_DOCUMENT_TYPE + 'edited'} + {'label': TEST_DOCUMENT_TYPE_EDITED_LABEL} ) + self.assertEqual(response.status_code, 200) + document_type = DocumentType.on_organization.get(pk=document_type.pk) - self.assertEqual(document_type.label, TEST_DOCUMENT_TYPE + 'edited') + self.assertEqual(document_type.label, TEST_DOCUMENT_TYPE_EDITED_LABEL) def test_document_type_edit_via_patch(self): document_type = DocumentType.on_organization.create( label=TEST_DOCUMENT_TYPE ) - self.client.patch( + response = self.client.patch( reverse('rest_api:documenttype-detail', args=(document_type.pk,)), - {'label': TEST_DOCUMENT_TYPE + 'edited'} + {'label': TEST_DOCUMENT_TYPE_EDITED_LABEL} ) + self.assertEqual(response.status_code, 200) document_type = DocumentType.on_organization.get(pk=document_type.pk) - self.assertEqual(document_type.label, TEST_DOCUMENT_TYPE + 'edited') + self.assertEqual(document_type.label, TEST_DOCUMENT_TYPE_EDITED_LABEL) + document_type.delete() def test_document_type_delete(self): document_type = DocumentType.on_organization.create( @@ -101,28 +89,20 @@ class DocumentTypeAPITestCase(APITestCase): @override_settings(OCR_AUTO_OCR=False) -class DocumentAPITestCase(APITestCase): +class DocumentAPITestCase(GenericAPITestCase): """ Test document API endpoints """ def setUp(self): - self.admin_user = get_user_model().objects.create_superuser( - username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, - password=TEST_ADMIN_PASSWORD - ) - - self.client.login( - username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD - ) - + super(DocumentAPITestCase, self).setUp() self.document_type = DocumentType.on_organization.create( label=TEST_DOCUMENT_TYPE ) def tearDown(self): - self.admin_user.delete() self.document_type.delete() + super(DocumentAPITestCase, self).tearDown() def test_document_upload(self): with open(TEST_DOCUMENT_PATH) as file_descriptor: diff --git a/mayan/apps/tags/tests/test_api.py b/mayan/apps/tags/tests/test_api.py index d13da662e7..cb9a7bd620 100644 --- a/mayan/apps/tags/tests/test_api.py +++ b/mayan/apps/tags/tests/test_api.py @@ -4,12 +4,9 @@ from django.contrib.auth import get_user_model from django.core.urlresolvers import reverse from django.test import override_settings -from rest_framework.test import APITestCase - from documents.models import DocumentType from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH -from organizations.models import Organization -from organizations.utils import create_default_organization +from rest_api.tests.base import GenericAPITestCase from user_management.tests.literals import ( TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME ) @@ -22,26 +19,11 @@ from .literals import ( ) -class TagAPITestCase(APITestCase): +class TagAPITestCase(GenericAPITestCase): """ Test the tag API endpoints """ - def setUp(self): - create_default_organization() - self.admin_user = get_user_model().on_organization.create_superuser( - username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, - password=TEST_ADMIN_PASSWORD - ) - - self.client.login( - username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD - ) - - def tearDown(self): - self.admin_user.delete() - Organization.objects.clear_cache() - def test_tag_create(self): response = self.client.post( reverse('rest_api:tag-list'), { @@ -49,6 +31,8 @@ class TagAPITestCase(APITestCase): } ) + self.assertEqual(response.status_code, 201) + tag = Tag.on_organization.first() self.assertEqual(response.data['id'], tag.pk)