diff --git a/tests/test_views/__init__.py b/tests/test_apis/__init__.py similarity index 100% rename from tests/test_views/__init__.py rename to tests/test_apis/__init__.py diff --git a/tests/test_apis/test_api_authentication/__init__.py b/tests/test_apis/test_api_authentication/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_views/test_account_activate.py b/tests/test_apis/test_api_authentication/test_account_activate.py similarity index 100% rename from tests/test_views/test_account_activate.py rename to tests/test_apis/test_api_authentication/test_account_activate.py diff --git a/tests/test_views/test_account_describe.py b/tests/test_apis/test_api_authentication/test_account_describe.py similarity index 100% rename from tests/test_views/test_account_describe.py rename to tests/test_apis/test_api_authentication/test_account_describe.py diff --git a/tests/test_views/test_account_new.py b/tests/test_apis/test_api_authentication/test_account_new.py similarity index 100% rename from tests/test_views/test_account_new.py rename to tests/test_apis/test_api_authentication/test_account_new.py diff --git a/tests/test_views/test_api_auth_add.py b/tests/test_apis/test_api_authentication/test_api_auth_add.py similarity index 100% rename from tests/test_views/test_api_auth_add.py rename to tests/test_apis/test_api_authentication/test_api_auth_add.py diff --git a/tests/test_views/test_api_auth_remove.py b/tests/test_apis/test_api_authentication/test_api_auth_remove.py similarity index 100% rename from tests/test_views/test_api_auth_remove.py rename to tests/test_apis/test_api_authentication/test_api_auth_remove.py diff --git a/tests/test_views/test_api_auth_reset_token.py b/tests/test_apis/test_api_authentication/test_api_auth_reset_token.py similarity index 100% rename from tests/test_views/test_api_auth_reset_token.py rename to tests/test_apis/test_api_authentication/test_api_auth_reset_token.py diff --git a/tests/test_views/test_api_objects_drafts_create.py b/tests/test_apis/test_api_objects_drafts_create.py similarity index 98% rename from tests/test_views/test_api_objects_drafts_create.py rename to tests/test_apis/test_api_objects_drafts_create.py index 949674a9..b294e337 100644 --- a/tests/test_views/test_api_objects_drafts_create.py +++ b/tests/test_apis/test_api_objects_drafts_create.py @@ -50,7 +50,6 @@ def setUp(self): { "object_id": "http://127.0.0.1:8000/TEST_000001", "prefix": "TEST", - # "authorized_groups": ["testing"], "contents": { "object_id": "https://biocomputeobject.org/TEST_000001", "spec_version": "https://w3id.org/ieee/ieee-2791-schema/2791object.json", @@ -105,7 +104,6 @@ def test_bad_request(self): { "object_id": "http://127.0.0.1:8000/TEST_000001", "prefix": "TEST", - "authorized_groups": ["testing"], "contents": { "object_id": "https://biocomputeobject.org/TEST_000001", "spec_version": "https://w3id.org/ieee/ieee-2791-schema/2791object.json", diff --git a/tests/test_views/test_auth_add.py b/tests/test_apis/test_auth_add.py similarity index 100% rename from tests/test_views/test_auth_add.py rename to tests/test_apis/test_auth_add.py diff --git a/tests/test_views/test_auth_remove.py b/tests/test_apis/test_auth_remove.py similarity index 100% rename from tests/test_views/test_auth_remove.py rename to tests/test_apis/test_auth_remove.py diff --git a/tests/test_views/test_auth_reset_token.py b/tests/test_apis/test_auth_reset_token.py similarity index 100% rename from tests/test_views/test_auth_reset_token.py rename to tests/test_apis/test_auth_reset_token.py diff --git a/tests/test_views/test_objects_drafts_create.py b/tests/test_apis/test_objects_drafts_create.py similarity index 98% rename from tests/test_views/test_objects_drafts_create.py rename to tests/test_apis/test_objects_drafts_create.py index 14606378..68b15fc1 100644 --- a/tests/test_views/test_objects_drafts_create.py +++ b/tests/test_apis/test_objects_drafts_create.py @@ -50,7 +50,6 @@ def setUp(self): { "object_id": "http://127.0.0.1:8000/TEST_000001", "prefix": "TEST", - # "authorized_groups": ["testing"], "contents": { "object_id": "https://biocomputeobject.org/TEST_000001", "spec_version": "https://w3id.org/ieee/ieee-2791-schema/2791object.json", @@ -105,7 +104,6 @@ def test_bad_request(self): { "object_id": "http://127.0.0.1:8000/TEST_000001", "prefix": "TEST", - "authorized_groups": ["testing"], "contents": { "object_id": "https://biocomputeobject.org/TEST_000001", "spec_version": "https://w3id.org/ieee/ieee-2791-schema/2791object.json", diff --git a/tests/test_views/test_prefixes_create.py b/tests/test_apis/test_prefixes_create.py similarity index 95% rename from tests/test_views/test_prefixes_create.py rename to tests/test_apis/test_prefixes_create.py index 91a70a34..78ee6013 100644 --- a/tests/test_views/test_prefixes_create.py +++ b/tests/test_apis/test_prefixes_create.py @@ -31,12 +31,12 @@ def setUp(self): self.data = [{ "prefix": "test1", "description": "Test prefix description.", - "authorized_groups": ["bco_publisher", "bco_drafter"] + "public": "true" }, { "prefix": "test2", "description": "Test prefix description.", - "authorized_groups": [""] + "public": "true" }] self.legacy_data = { @@ -125,8 +125,6 @@ def test_create_multi_status(self): # 400: Bad Request. The prefix * does not follow the naming rules for a prefix. self.assertIn('prefix', response.data[0]['INVALID-PREFIX']['data']) - # 404: Not Found. The user * was not found on the server. - self.assertIn('authorized_groups', response.data[1]['TESTR']['data']) # 409: Conflict. The prefix the requestor is attempting to create already exists. self.assertIn('prefix_name', response.data[3]['TEST']['data']) diff --git a/tests/test_apis/test_prefixes_modify.py b/tests/test_apis/test_prefixes_modify.py new file mode 100644 index 00000000..26c014b9 --- /dev/null +++ b/tests/test_apis/test_prefixes_modify.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python3 + +"""Bulk Create Prefixes +Tests for 'All prefixes were successfully created. 200', 'Some prefix +modifications failed. 207', '400: All modifications failed', and 'Unauthorized. Authentication credentials were +not provided. 401' + +For the 207 response Each object submitted will have it's own response object +with it's own status code and message. These are as follows: + 201: The prefix * was successfully created. + 400: Bad Request. The expiration date * is not valid. + 400: Bad Request. The prefix * does not follow the naming rules for a prefix. + 403: Forbidden. User does not have permission to perform this action. + 404: Not Found. The user * was not found on the server. + 409: Conflict. The prefix the requestor is attempting to create already exists. + """ + +from django.test import TestCase +from rest_framework.test import APIClient +from rest_framework.authtoken.models import Token +from django.contrib.auth.models import User +from rest_framework.test import APITestCase +from django.contrib.auth.models import Group + +class CreatePrefixeTestCase(APITestCase): + fixtures=['tests/fixtures/test_data'] + + def setUp(self): + + self.client= APIClient() + self.data = [{ + "prefix": "test", + "description": "Test prefix description." + }] + + self.legacy_data = { + "POST_api_prefixes_modify": [ + { + "owner_group": "bco_publisher", + "owner_user": "bco_api_user", + "prefixes": [ + { + "description": "Just a test modification for prefix.", + "prefix": "Test" + } + ] + } + ] + } + + # def test_modify_prefix_success(self): + # """The prefix was successfully modified. 200 + # """ + + # token = Token.objects.get(user=User.objects.get(username='tester')).key + + # self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) + # legacy_response = self.client.post('/api/prefixes/modify/', data=self.legacy_data, format='json') + # response = self.client.post('/api/prefixes/modify/', data=self.data, format='json') + # self.assertEqual(legacy_response.status_code, 200) + # self.assertEqual(response.status_code, 200) + + # def test_modify_multi_status(self): + # """Tests for 'Some prefix modifications failed. 207.' + # """ + + # token = Token.objects.get(user=User.objects.get(username='tester')).key + # data = { + # "POST_api_prefixes_modify": [ + # { + # "owner_group": "test_drafter", + # "owner_user": "bco_api_user", + # "prefixes": [ + # { + # "description": "Invalid prefix naming.", + # "expiration_date": "null", + # "prefix": "invalid-prefix" + # } + # ] + # }, + # { + # "owner_group": "does_not_exist", + # "owner_user": "does_not_exist", + # "prefixes": [ + # { + # "description": "Invalid owner.", + # "prefix": "testR" + # } + # ] + # }, + # { + # "owner_group": "test_drafter", + # "owner_user": "bco_api_user", + # "prefixes": [ + # { + # "description": "Just a test prefix update.", + # "prefix": "test" + # }, + + # ] + # }, + # { + # "owner_group": "test_drafter", + # "owner_user": "bco_api_user", + # "prefixes": [ + # { + # "description": "Just a test prefix.", + # "prefix": "BCO" + # } + # ] + # } + # ] + # } + + # self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) + # response = self.client.post('/api/prefixes/modify/', data=data, format='json') + # # 201: The prefix * was successfully created. + # self.assertEqual(response.data[2]['TEST']['status_code'], 200) + + # # 400: Bad Request. The prefix * does not exist. + # self.assertIn('prefix', response.data[0]['INVALID-PREFIX']['data']) + # # 404: Not Found. The user * was not found on the server. + + # # 409: Conflict. The prefix the requestor is attempting to create already exists. + # self.assertIn('permissions', response.data[3]['BCO']['message']) + + # self.assertEqual(response.status_code, 207) + + # def test_create_prefix_unauthorized(self): + # """Unauthorized. Authentication credentials were not provided. 401 + # """ + + # data = { + # "POST_api_prefixes_create": [ + # { + # "owner_group": "test_drafter", + # "owner_user": "bco_api_user", + # "prefixes": [ + # { + # "description": "Just a test prefix.", + # "prefix": "testR" + # } + # ] + # } + # ] + # } + + # response = self.client.post('/api/prefixes/create/', data=data, format='json') + # self.assertEqual(response.status_code, 403) diff --git a/tests/test_views/test_api_account_activate.py b/tests/test_views/test_api_account_activate.py deleted file mode 100644 index 5a0340fd..00000000 --- a/tests/test_views/test_api_account_activate.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python3 - -"""Test Account Activation -Test for '200: Account has been authorized.', '404: Credentials not found.', -and '403: Requestor's credentials were rejected.' -""" - -import time -from django.test import TestCase, Client - -class ApiAccountsActivateTestCase(TestCase): - fixtures = ['tests/fixtures/test_data'] - - def setUp(self): - self.client = Client() - - def test_account_activated_success(self): - """Test for '201: Account creation request is successful.' - """ - - response = self.client.get( - '/api/accounts/activate/'\ - +'test_new_user%40testing.com/sample_temp_identifier' - ) - self.assertEqual(response.status_code, 200) - - def test_account_activated_forbidden(self): - """Test for '403: Requestor's credentials were rejected.' - """ - - bad_link = "test_new_user%40testing.com/bad_temp_identifier" - response = self.client.get(f'/api/accounts/activate/{bad_link}') - self.assertEqual(response.status_code, 403) - - def test_account_activated_not_found(self): - """Test for '404: That account, {email}, was not found' - """ - - bad_link = "test22%40testing.com/sample_temp_identifier" - response = self.client.get(f'/api/accounts/activate/{bad_link}') - self.assertEqual(response.status_code, 404) - - def test_account_activated_conflict(self): - """Test for '409: CONFLICT: That account, {email}, - has already been activated.' - """ - - bad_link = "tester%40testing.com/sample_temp_identifier" - response = self.client.get(f'/api/accounts/activate/{bad_link}') - self.assertEqual(response.status_code, 409) \ No newline at end of file diff --git a/tests/test_views/test_api_account_describe.py b/tests/test_views/test_api_account_describe.py deleted file mode 100644 index 29401698..00000000 --- a/tests/test_views/test_api_account_describe.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python3 - -"""API- Accounts describe -Tests for 'Authorization is successfull' (200), -'Forbidden. Authentication credentials were not provided' (403), -'Invalid Token' (403) -""" - - -from django.test import TestCase -from django.contrib.auth.models import User -from rest_framework.authtoken.models import Token -from rest_framework.test import APIClient - -class AccountDescribeTestCase(TestCase): - fixtures = ['tests/fixtures/test_data'] - - def test_success_response(self): - """200: Authorization is successful. - """ - client = APIClient() - token = Token.objects.get(user=User.objects.get(username='bco_api_user')).key - client.credentials(HTTP_AUTHORIZATION='Token ' + token) - response = client.post('/api/accounts/describe/', format='json') - self.assertEqual(response.status_code, 200) - - def test_forbidden_response(self): - """403: Forbidden. Authentication credentials were not provided. - """ - client = APIClient() - response = client.post('/api/accounts/describe/') - self.assertEqual(response.status_code, 403) - - def test_unauthorized_response(self): - """403: Invalid token - """ - client = APIClient() - client.credentials(HTTP_AUTHORIZATION='Token This-token-is-bad') - response = client.post('/api/accounts/describe/') - self.assertEqual(response.status_code, 403) diff --git a/tests/test_views/test_api_account_new.py b/tests/test_views/test_api_account_new.py deleted file mode 100644 index e06a593f..00000000 --- a/tests/test_views/test_api_account_new.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python3 - -"""New Account -Test for '201: Account creation request is successful.', '400: Bad -request format.', and '409: Account has already been authenticated or -requested.' -""" - -from django.test import TestCase, Client - -class ApiAccountsNewTestCase(TestCase): - fixtures = ['tests/fixtures/test_data'] - - def setUp(self): - self.client = Client() - - def test_creation_request_success(self): - """ Test for '201: Account creation request is successful.' - """ - - data = { - 'hostname': 'http://localhost:8000', - 'email': 'test@gwu.edu', - 'token': 'SampleToken' - } - - - response = self.client.post('/api/accounts/new/', data=data) - self.assertEqual(response.status_code, 201) - - def test_creation_request_success_bad_request(self): - """Test for '400: Bad request format.' - """ - data = { - 'hostname': 'UserDB', - 'email': 'test@gwu.edu' - } - - response = self.client.post('/api/accounts/new/', data=data) - self.assertEqual(response.status_code, 400) - - def test_creation_request_conflict(self): - """ Test for '409: Account has already been authenticated or - requested.' - """ - - data = { - 'hostname': 'http://localhost:8000', - 'email': 'test@gwu.edu', - 'token': 'SampleToken' - } - - - response = self.client.post('/api/accounts/new/', data=data) - response2 = self.client.post('/api/accounts/new/', data=data) - self.assertEqual(response.status_code, 201) - self.assertEqual(response2.status_code, 409) \ No newline at end of file diff --git a/tests/test_views/test_prefixes_modify.py b/tests/test_views/test_prefixes_modify.py deleted file mode 100644 index 1dabbcb5..00000000 --- a/tests/test_views/test_prefixes_modify.py +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env python3 - -"""Bulk Create Prefixes -Tests for 'All prefixes were successfully created. 200', 'Some prefix -modifications failed. 207', '400: All modifications failed', and 'Unauthorized. Authentication credentials were -not provided. 401' - -For the 207 response Each object submitted will have it's own response object -with it's own status code and message. These are as follows: - 201: The prefix * was successfully created. - 400: Bad Request. The expiration date * is not valid. - 400: Bad Request. The prefix * does not follow the naming rules for a prefix. - 403: Forbidden. User does not have permission to perform this action. - 404: Not Found. The user * was not found on the server. - 409: Conflict. The prefix the requestor is attempting to create already exists. - """ - -from django.test import TestCase -from rest_framework.test import APIClient -from rest_framework.authtoken.models import Token -from django.contrib.auth.models import User -from rest_framework.test import APITestCase -from django.contrib.auth.models import Group - -class CreatePrefixeTestCase(APITestCase): - fixtures=['tests/fixtures/test_data'] - - def setUp(self): - - self.client= APIClient() - self.data = [{ - "prefix": "test", - "description": "Test prefix description.", - "authorized_groups": ["bco_publisher", "bco_drafter"] - }] - - self.legacy_data = { - "POST_api_prefixes_modify": [ - { - "owner_group": "bco_publisher", - "owner_user": "bco_api_user", - "prefixes": [ - { - "description": "Just a test modification for prefix.", - "prefix": "Test" - } - ] - } - ] - } - - def test_modify_prefix_success(self): - """The prefix was successfully modified. 200 - """ - - token = Token.objects.get(user=User.objects.get(username='tester')).key - - self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) - legacy_response = self.client.post('/api/prefixes/modify/', data=self.legacy_data, format='json') - response = self.client.post('/api/prefixes/modify/', data=self.data, format='json') - self.assertEqual(legacy_response.status_code, 200) - self.assertEqual(response.status_code, 200) - - def test_modify_multi_status(self): - """Tests for 'Some prefix modifications failed. 207.' - """ - - token = Token.objects.get(user=User.objects.get(username='tester')).key - data = { - "POST_api_prefixes_modify": [ - { - "owner_group": "test_drafter", - "owner_user": "bco_api_user", - "prefixes": [ - { - "description": "Invalid prefix naming.", - "expiration_date": "null", - "prefix": "invalid-prefix" - } - ] - }, - { - "owner_group": "does_not_exist", - "owner_user": "does_not_exist", - "prefixes": [ - { - "description": "Invalid owner.", - "prefix": "testR" - } - ] - }, - { - "owner_group": "test_drafter", - "owner_user": "bco_api_user", - "prefixes": [ - { - "description": "Just a test prefix update.", - "prefix": "test" - }, - - ] - }, - { - "owner_group": "test_drafter", - "owner_user": "bco_api_user", - "prefixes": [ - { - "description": "Just a test prefix.", - "prefix": "BCO" - } - ] - } - ] - } - - self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) - response = self.client.post('/api/prefixes/modify/', data=data, format='json') - # 201: The prefix * was successfully created. - self.assertEqual(response.data[2]['TEST']['status_code'], 200) - - # 400: Bad Request. The prefix * does not exist. - self.assertIn('prefix', response.data[0]['INVALID-PREFIX']['data']) - # 404: Not Found. The user * was not found on the server. - self.assertIn('authorized_groups', response.data[1]['TESTR']['data']) - - # 409: Conflict. The prefix the requestor is attempting to create already exists. - self.assertIn('permissions', response.data[3]['BCO']['message']) - - self.assertEqual(response.status_code, 207) - - def test_create_prefix_unauthorized(self): - """Unauthorized. Authentication credentials were not provided. 401 - """ - - data = { - "POST_api_prefixes_create": [ - { - "owner_group": "test_drafter", - "owner_user": "bco_api_user", - "prefixes": [ - { - "description": "Just a test prefix.", - "prefix": "testR" - } - ] - } - ] - } - - response = self.client.post('/api/prefixes/create/', data=data, format='json') - self.assertEqual(response.status_code, 403)