Skip to content

Commit

Permalink
Update testing functions
Browse files Browse the repository at this point in the history
Created subdirectory and moved test functions
Changes to be committed:
	renamed:    tests/test_views/__init__.py -> tests/test_apis/__init__.py
	new file:   tests/test_apis/test_api_authentication/__init__.py
	renamed:    tests/test_views/test_account_activate.py -> tests/test_apis/test_api_authentication/test_account_activate.py
	renamed:    tests/test_views/test_account_describe.py -> tests/test_apis/test_api_authentication/test_account_describe.py
	renamed:    tests/test_views/test_account_new.py -> tests/test_apis/test_api_authentication/test_account_new.py
	renamed:    tests/test_views/test_api_auth_add.py -> tests/test_apis/test_api_authentication/test_api_auth_add.py
	renamed:    tests/test_views/test_api_auth_remove.py -> tests/test_apis/test_api_authentication/test_api_auth_remove.py
	renamed:    tests/test_views/test_api_auth_reset_token.py -> tests/test_apis/test_api_authentication/test_api_auth_reset_token.py
	renamed:    tests/test_views/test_api_objects_drafts_create.py -> tests/test_apis/test_api_objects_drafts_create.py
	renamed:    tests/test_views/test_auth_add.py -> tests/test_apis/test_auth_add.py
	renamed:    tests/test_views/test_auth_remove.py -> tests/test_apis/test_auth_remove.py
	renamed:    tests/test_views/test_auth_reset_token.py -> tests/test_apis/test_auth_reset_token.py
	renamed:    tests/test_views/test_objects_drafts_create.py -> tests/test_apis/test_objects_drafts_create.py
	renamed:    tests/test_views/test_prefixes_create.py -> tests/test_apis/test_prefixes_create.py
	new file:   tests/test_apis/test_prefixes_modify.py
	deleted:    tests/test_views/test_api_account_activate.py
	deleted:    tests/test_views/test_api_account_describe.py
	deleted:    tests/test_views/test_api_account_new.py
	deleted:    tests/test_views/test_prefixes_modify.py
  • Loading branch information
HadleyKing committed Apr 3, 2024
1 parent 30ba550 commit cb0aa9a
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 306 deletions.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'])
Expand Down
149 changes: 149 additions & 0 deletions tests/test_apis/test_prefixes_modify.py
Original file line number Diff line number Diff line change
@@ -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)
50 changes: 0 additions & 50 deletions tests/test_views/test_api_account_activate.py

This file was deleted.

40 changes: 0 additions & 40 deletions tests/test_views/test_api_account_describe.py

This file was deleted.

57 changes: 0 additions & 57 deletions tests/test_views/test_api_account_new.py

This file was deleted.

Loading

0 comments on commit cb0aa9a

Please sign in to comment.