|
|
@ -6,7 +6,9 @@ from rest_framework.reverse import reverse |
|
|
|
from rest_framework.test import APITestCase |
|
|
|
|
|
|
|
from projects.models import DOCUMENT_CLASSIFICATION |
|
|
|
from api.tests.api.utils import (DATA_DIR, CRUDMixin, make_label, make_project, make_user, prepare_project) |
|
|
|
from api.tests.api.utils import (CRUDMixin, make_label, make_project, make_user, prepare_project) |
|
|
|
|
|
|
|
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') |
|
|
|
|
|
|
|
|
|
|
|
class TestLabelList(CRUDMixin): |
|
|
@ -140,17 +142,17 @@ class TestLabelUploadAPI(APITestCase): |
|
|
|
self.assertEqual(response.status_code, expected_status) |
|
|
|
|
|
|
|
def test_allows_project_admin_to_upload_label(self): |
|
|
|
self.assert_upload_file('label/valid_labels.json', self.project.admin, status.HTTP_201_CREATED) |
|
|
|
self.assert_upload_file('valid_labels.json', self.project.admin, status.HTTP_201_CREATED) |
|
|
|
|
|
|
|
def test_denies_project_member_to_upload_label(self): |
|
|
|
for member in self.project.staffs: |
|
|
|
self.assert_upload_file('label/valid_labels.json', member, status.HTTP_403_FORBIDDEN) |
|
|
|
self.assert_upload_file('valid_labels.json', member, status.HTTP_403_FORBIDDEN) |
|
|
|
|
|
|
|
def test_denies_non_project_member_to_upload_label(self): |
|
|
|
self.assert_upload_file('label/valid_labels.json', self.non_member, status.HTTP_403_FORBIDDEN) |
|
|
|
self.assert_upload_file('valid_labels.json', self.non_member, status.HTTP_403_FORBIDDEN) |
|
|
|
|
|
|
|
def test_denies_unauthenticated_user_to_upload_label(self): |
|
|
|
self.assert_upload_file('label/valid_labels.json', expected_status=status.HTTP_403_FORBIDDEN) |
|
|
|
self.assert_upload_file('valid_labels.json', expected_status=status.HTTP_403_FORBIDDEN) |
|
|
|
|
|
|
|
def test_try_to_upload_invalid_file(self): |
|
|
|
self.assert_upload_file('label/invalid_labels.json', self.project.admin, status.HTTP_400_BAD_REQUEST) |
|
|
|
self.assert_upload_file('invalid_labels.json', self.project.admin, status.HTTP_400_BAD_REQUEST) |