Use the GenericAPITestCase for the documents and tags api tests.
This commit is contained in:
@@ -6,8 +6,6 @@ import time
|
|||||||
|
|
||||||
from json import loads
|
from json import loads
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
from django.utils.six import BytesIO
|
from django.utils.six import BytesIO
|
||||||
@@ -15,38 +13,24 @@ from django.utils.six import BytesIO
|
|||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase
|
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 (
|
from user_management.tests.literals import (
|
||||||
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME
|
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME
|
||||||
)
|
)
|
||||||
|
|
||||||
from .literals import (
|
from .literals import (
|
||||||
TEST_DOCUMENT_FILENAME, TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE,
|
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
|
from ..models import Document, DocumentType, HASH_FUNCTION
|
||||||
|
|
||||||
|
|
||||||
class DocumentTypeAPITestCase(APITestCase):
|
class DocumentTypeAPITestCase(GenericAPITestCase):
|
||||||
"""
|
"""
|
||||||
Test the document type API endpoints
|
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):
|
def test_document_type_create(self):
|
||||||
self.assertEqual(DocumentType.on_organization.all().count(), 0)
|
self.assertEqual(DocumentType.on_organization.all().count(), 0)
|
||||||
|
|
||||||
@@ -67,26 +51,30 @@ class DocumentTypeAPITestCase(APITestCase):
|
|||||||
label=TEST_DOCUMENT_TYPE
|
label=TEST_DOCUMENT_TYPE
|
||||||
)
|
)
|
||||||
|
|
||||||
self.client.put(
|
response = self.client.put(
|
||||||
reverse('rest_api:documenttype-detail', args=(document_type.pk,)),
|
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)
|
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):
|
def test_document_type_edit_via_patch(self):
|
||||||
document_type = DocumentType.on_organization.create(
|
document_type = DocumentType.on_organization.create(
|
||||||
label=TEST_DOCUMENT_TYPE
|
label=TEST_DOCUMENT_TYPE
|
||||||
)
|
)
|
||||||
|
|
||||||
self.client.patch(
|
response = self.client.patch(
|
||||||
reverse('rest_api:documenttype-detail', args=(document_type.pk,)),
|
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)
|
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):
|
def test_document_type_delete(self):
|
||||||
document_type = DocumentType.on_organization.create(
|
document_type = DocumentType.on_organization.create(
|
||||||
@@ -101,28 +89,20 @@ class DocumentTypeAPITestCase(APITestCase):
|
|||||||
|
|
||||||
|
|
||||||
@override_settings(OCR_AUTO_OCR=False)
|
@override_settings(OCR_AUTO_OCR=False)
|
||||||
class DocumentAPITestCase(APITestCase):
|
class DocumentAPITestCase(GenericAPITestCase):
|
||||||
"""
|
"""
|
||||||
Test document API endpoints
|
Test document API endpoints
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.admin_user = get_user_model().objects.create_superuser(
|
super(DocumentAPITestCase, self).setUp()
|
||||||
username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL,
|
|
||||||
password=TEST_ADMIN_PASSWORD
|
|
||||||
)
|
|
||||||
|
|
||||||
self.client.login(
|
|
||||||
username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD
|
|
||||||
)
|
|
||||||
|
|
||||||
self.document_type = DocumentType.on_organization.create(
|
self.document_type = DocumentType.on_organization.create(
|
||||||
label=TEST_DOCUMENT_TYPE
|
label=TEST_DOCUMENT_TYPE
|
||||||
)
|
)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.admin_user.delete()
|
|
||||||
self.document_type.delete()
|
self.document_type.delete()
|
||||||
|
super(DocumentAPITestCase, self).tearDown()
|
||||||
|
|
||||||
def test_document_upload(self):
|
def test_document_upload(self):
|
||||||
with open(TEST_DOCUMENT_PATH) as file_descriptor:
|
with open(TEST_DOCUMENT_PATH) as file_descriptor:
|
||||||
|
|||||||
@@ -4,12 +4,9 @@ from django.contrib.auth import get_user_model
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
|
||||||
from rest_framework.test import APITestCase
|
|
||||||
|
|
||||||
from documents.models import DocumentType
|
from documents.models import DocumentType
|
||||||
from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH
|
from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH
|
||||||
from organizations.models import Organization
|
from rest_api.tests.base import GenericAPITestCase
|
||||||
from organizations.utils import create_default_organization
|
|
||||||
from user_management.tests.literals import (
|
from user_management.tests.literals import (
|
||||||
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME
|
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
|
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):
|
def test_tag_create(self):
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse('rest_api:tag-list'), {
|
reverse('rest_api:tag-list'), {
|
||||||
@@ -49,6 +31,8 @@ class TagAPITestCase(APITestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 201)
|
||||||
|
|
||||||
tag = Tag.on_organization.first()
|
tag = Tag.on_organization.first()
|
||||||
|
|
||||||
self.assertEqual(response.data['id'], tag.pk)
|
self.assertEqual(response.data['id'], tag.pk)
|
||||||
|
|||||||
Reference in New Issue
Block a user