-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to be committed: modified: biocompute/apis.py modified: biocompute/migrations/0001_initial.py modified: prefix/apis.py modified: prefix/migrations/0001_initial.py new file: tests/test_views/test_account_activate.py new file: tests/test_views/test_account_describe.py new file: tests/test_views/test_account_new.py new file: tests/test_views/test_auth_add.py new file: tests/test_views/test_auth_remove.py new file: tests/test_views/test_auth_reset_token.py new file: tests/test_views/test_objects_drafts_create.py
- Loading branch information
1 parent
1b20196
commit 2530f7d
Showing
11 changed files
with
449 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/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': '[email protected]', | ||
'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': '[email protected]' | ||
} | ||
|
||
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': '[email protected]', | ||
'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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python3 | ||
|
||
"""Add Authentication | ||
Tests for 'New authentication credentials added to existing object' (200), | ||
'Authentication credentials were created and added' (201), 'Bad request' (400), | ||
'That object already exists for this account' (409) | ||
""" | ||
|
||
from django.test import TestCase, Client | ||
from rest_framework.test import APIClient | ||
from rest_framework.authtoken.models import Token | ||
from django.contrib.auth.models import User | ||
from authentication.models import Authentication | ||
|
||
class AuthenticationTestCase(TestCase): | ||
fixtures = ['tests/fixtures/test_data'] | ||
|
||
def setUp(self): | ||
self.client = APIClient() | ||
|
||
def test_credentials_created_response(self): | ||
"""Add authentication is successful (200) | ||
""" | ||
|
||
token = Token.objects.get(user=User.objects.get(username='tester')).key | ||
data = {"iss": "Reeya1","sub": "ReeyaGupta1"} | ||
|
||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) | ||
response = self.client.post('/api/auth/add/', data=data) | ||
self.assertEqual(response.status_code, 201) | ||
|
||
def test_credentials_added(self): | ||
"""New authentication credentials added to existing object (200) | ||
""" | ||
|
||
token = Token.objects.get(user=User.objects.get(username='bco_api_user')).key | ||
data = {"iss": "new","sub": "new One"} | ||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) | ||
response = self.client.post('/api/auth/add/', data=data, format='json') | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_bad_request_response(self): | ||
"""Bad request (400) | ||
""" | ||
|
||
token = Token.objects.get(user=User.objects.get(username='tester')).key | ||
data = {"Missing required fields"} | ||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) | ||
response = self.client.post('/api/auth/add/', data=data, format='json') | ||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_object_already_exists_response(self): | ||
"""That object already exists for this account (409) | ||
""" | ||
|
||
token = Token.objects.get(user=User.objects.get(username='bco_api_user')).key | ||
data = {"iss": "Reeya1","sub": "ReeyaGupta1"} | ||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) | ||
response = self.client.post('/api/auth/add/', data=data, format='json') | ||
self.assertEqual(response.status_code, 409) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
|
||
"""Remove Authentication | ||
Tests for 'Remove authentication is successful.` (200), 'Authentication | ||
failed.' (403), and 'That object does not exist for this account.' (404) | ||
""" | ||
|
||
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 | ||
|
||
class AuthenticationRemovetestcase(APITestCase): | ||
fixtures = ['tests/fixtures/test_data'] | ||
|
||
def setUp(self): | ||
self.client = APIClient() | ||
|
||
def test_success_response(self): | ||
"""Remove authentication is successful. (200) | ||
""" | ||
|
||
token = Token.objects.get(user=User.objects.get(username='bco_api_user')).key | ||
|
||
data = {"iss": "Reeya1","sub": "ReeyaGupta1"} | ||
|
||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) | ||
response = self.client.post('/api/auth/remove/', data=data, format='json') | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_bad_authentication(self): | ||
"""Authentication failed. 403 | ||
""" | ||
|
||
token = Token.objects.get(user=User.objects.get(username='bco_api_user')).key | ||
data = {} | ||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) | ||
response = self.client.post('/api/auth/remove/', data=data) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
def test_object_already_exists_response(self): | ||
"""That object does not exist for this account. 404 | ||
""" | ||
|
||
token = Token.objects.get(user=User.objects.get(username='bco_api_user')).key | ||
data = {"iss": "Reeya2","sub": "ReeyaGupta2"} | ||
|
||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) | ||
response = self.client.post('/api/auth/remove/', data=data) | ||
self.assertEqual(response.status_code, 404) |
Oops, something went wrong.