|
@ -15,16 +15,18 @@ DATA_DIR = os.path.join(os.path.dirname(__file__), "data") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestLabelList(CRUDMixin): |
|
|
class TestLabelList(CRUDMixin): |
|
|
@classmethod |
|
|
|
|
|
def setUpTestData(cls): |
|
|
|
|
|
cls.non_member = make_user() |
|
|
|
|
|
cls.project_a = prepare_project(ProjectType.DOCUMENT_CLASSIFICATION) |
|
|
|
|
|
cls.label = make_label(cls.project_a.item) |
|
|
|
|
|
cls.url = reverse(viewname="category_types", args=[cls.project_a.item.id]) |
|
|
|
|
|
|
|
|
def setUp(self): |
|
|
|
|
|
self.non_member = make_user() |
|
|
|
|
|
self.project_a = prepare_project(ProjectType.DOCUMENT_CLASSIFICATION) |
|
|
|
|
|
self.label = make_label(self.project_a.item) |
|
|
|
|
|
self.url = reverse(viewname="category_types", args=[self.project_a.item.id]) |
|
|
|
|
|
|
|
|
# Ensure that the API does not return the labels of the other project. |
|
|
# Ensure that the API does not return the labels of the other project. |
|
|
cls.project_b = make_project(task="Any", users=["admin"], roles=[settings.ROLE_PROJECT_ADMIN]) |
|
|
|
|
|
make_label(cls.project_b.item) |
|
|
|
|
|
|
|
|
self.project_b = make_project(task="Any", users=["admin"], roles=[settings.ROLE_PROJECT_ADMIN]) |
|
|
|
|
|
make_label(self.project_b.item) |
|
|
|
|
|
|
|
|
|
|
|
# for label creation |
|
|
|
|
|
self.data = {"text": "example"} |
|
|
|
|
|
|
|
|
def test_returns_labels_to_project_member(self): |
|
|
def test_returns_labels_to_project_member(self): |
|
|
for member in self.project_a.members: |
|
|
for member in self.project_a.members: |
|
@ -38,32 +40,11 @@ class TestLabelList(CRUDMixin): |
|
|
def test_does_not_return_labels_to_unauthenticated_user(self): |
|
|
def test_does_not_return_labels_to_unauthenticated_user(self): |
|
|
self.assert_fetch(expected=status.HTTP_403_FORBIDDEN) |
|
|
self.assert_fetch(expected=status.HTTP_403_FORBIDDEN) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestLabelSearch(CRUDMixin): |
|
|
|
|
|
def setUp(self): |
|
|
|
|
|
self.project = prepare_project(ProjectType.DOCUMENT_CLASSIFICATION) |
|
|
|
|
|
make_label(self.project.item) |
|
|
|
|
|
self.url = reverse(viewname="category_types", args=[self.project.item.id]) |
|
|
|
|
|
|
|
|
|
|
|
def test_search(self): |
|
|
|
|
|
for member in self.project.members: |
|
|
|
|
|
response = self.assert_fetch(member, status.HTTP_200_OK) |
|
|
|
|
|
self.assertEqual(len(response.data), 1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestLabelCreate(CRUDMixin): |
|
|
|
|
|
@classmethod |
|
|
|
|
|
def setUpTestData(cls): |
|
|
|
|
|
cls.non_member = make_user(ProjectType.DOCUMENT_CLASSIFICATION) |
|
|
|
|
|
cls.project = prepare_project() |
|
|
|
|
|
cls.url = reverse(viewname="category_types", args=[cls.project.item.id]) |
|
|
|
|
|
cls.data = {"text": "example"} |
|
|
|
|
|
|
|
|
|
|
|
def test_allows_admin_to_create_label(self): |
|
|
def test_allows_admin_to_create_label(self): |
|
|
self.assert_create(self.project.admin, status.HTTP_201_CREATED) |
|
|
|
|
|
|
|
|
self.assert_create(self.project_a.admin, status.HTTP_201_CREATED) |
|
|
|
|
|
|
|
|
def test_denies_project_staff_to_create_label(self): |
|
|
def test_denies_project_staff_to_create_label(self): |
|
|
for member in self.project.staffs: |
|
|
|
|
|
|
|
|
for member in self.project_a.staffs: |
|
|
self.assert_create(member, status.HTTP_403_FORBIDDEN) |
|
|
self.assert_create(member, status.HTTP_403_FORBIDDEN) |
|
|
|
|
|
|
|
|
def test_denies_non_project_member_to_create_label(self): |
|
|
def test_denies_non_project_member_to_create_label(self): |
|
@ -72,11 +53,19 @@ class TestLabelCreate(CRUDMixin): |
|
|
def test_denies_unauthenticated_user_to_create_label(self): |
|
|
def test_denies_unauthenticated_user_to_create_label(self): |
|
|
self.assert_create(expected=status.HTTP_403_FORBIDDEN) |
|
|
self.assert_create(expected=status.HTTP_403_FORBIDDEN) |
|
|
|
|
|
|
|
|
|
|
|
def test_allows_admin_to_bulk_delete_label(self): |
|
|
|
|
|
self.assert_delete(self.project_a.admin, status.HTTP_204_NO_CONTENT, data={"ids": [self.label.id]}) |
|
|
|
|
|
|
|
|
|
|
|
def test_denies_project_staff_to_bulk_delete_label(self): |
|
|
|
|
|
member = self.project_a.staffs[0] |
|
|
|
|
|
self.assert_delete(member, status.HTTP_403_FORBIDDEN, data={"ids": [self.label.id]}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAllowMemberToCreateLabelType(CRUDMixin): |
|
|
class TestAllowMemberToCreateLabelType(CRUDMixin): |
|
|
@classmethod |
|
|
@classmethod |
|
|
def setUpTestData(cls): |
|
|
def setUpTestData(cls): |
|
|
cls.project = prepare_project(ProjectType.DOCUMENT_CLASSIFICATION, allow_member_to_create_label_type=True) |
|
|
cls.project = prepare_project(ProjectType.DOCUMENT_CLASSIFICATION, allow_member_to_create_label_type=True) |
|
|
|
|
|
cls.label = make_label(cls.project.item) |
|
|
cls.url = reverse(viewname="category_types", args=[cls.project.item.id]) |
|
|
cls.url = reverse(viewname="category_types", args=[cls.project.item.id]) |
|
|
cls.data = {"text": "example"} |
|
|
cls.data = {"text": "example"} |
|
|
|
|
|
|
|
@ -85,6 +74,10 @@ class TestAllowMemberToCreateLabelType(CRUDMixin): |
|
|
self.data["text"] = member.username |
|
|
self.data["text"] = member.username |
|
|
self.assert_create(member, status.HTTP_201_CREATED) |
|
|
self.assert_create(member, status.HTTP_201_CREATED) |
|
|
|
|
|
|
|
|
|
|
|
def test_denies_project_staff_to_bulk_delete_label(self): |
|
|
|
|
|
member = self.project.staffs[0] |
|
|
|
|
|
self.assert_delete(member, status.HTTP_403_FORBIDDEN, data={"ids": [self.label.id]}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestLabelDetailAPI(CRUDMixin): |
|
|
class TestLabelDetailAPI(CRUDMixin): |
|
|
@classmethod |
|
|
@classmethod |
|
|