Skip to content

Commit 84a05ee

Browse files
committed
Fix #236
Changes to be committed: modified: api/scripts/method_specific/GET_draft_object_by_id.py modified: api/views.py new file: tests/test_views/test_get_object_id_draft.py
1 parent fa0e5a4 commit 84a05ee

File tree

3 files changed

+64
-15
lines changed

3 files changed

+64
-15
lines changed

api/scripts/method_specific/GET_draft_object_by_id.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ def get_draft_object_by_id(do_id, request):
6363

6464
return Response(
6565
data="The contents of the draft could not be sent back because"
66-
" the requestor did not have appropriate permissions.",
67-
status=status.HTTP_403_FORBIDDEN,
66+
" the requestor does not have appropriate permissions.",
67+
status=status.HTTP_401_UNAUTHORIZED,
6868
)
6969
# the root ID does not exist at all.
7070
return Response(
71-
data="The draft could not be found on the server.",
72-
status=status.HTTP_400_BAD_REQUEST,
71+
data="That draft could not be found on the server.",
72+
status=status.HTTP_404_NOT_FOUND,
7373
)

api/views.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,16 +1638,10 @@ class DraftObjectId(APIView):
16381638
16391639
--------------------
16401640
1641-
Reads and returns and object based on a URI.
1641+
Reads and returns a single object from a given object_id.
16421642
16431643
"""
16441644

1645-
# For the success and error messages
1646-
# renderer_classes = [
1647-
# TemplateHTMLRenderer
1648-
# ]
1649-
# template_name = 'api/account_activation_message.html'
1650-
16511645
auth = []
16521646
auth.append(
16531647
openapi.Parameter(
@@ -1661,10 +1655,12 @@ class DraftObjectId(APIView):
16611655
@swagger_auto_schema(
16621656
manual_parameters=auth,
16631657
responses={
1664-
201: "Account has been authorized.",
1665-
208: "Account has already been authorized.",
1666-
403: "Requestor's credentials were rejected.",
1667-
424: "Account has not been registered.",
1658+
200: "Success. Object contents returned",
1659+
401: "The contents of the draft could not be sent back because"
1660+
" the requestor does not have appropriate permissions.",
1661+
403: "Forbidden. Authentication credentials were not provided, or"
1662+
" the token was invalid.",
1663+
404: "Not found. That draft could not be found on the server."
16681664
},
16691665
tags=["BCO Management"],
16701666
)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
#!/usr/bin/env python3
3+
4+
""" Get Draft BCO
5+
6+
"""
7+
8+
import unittest
9+
from django.test import TestCase
10+
from rest_framework.test import APIClient
11+
from rest_framework.authtoken.models import Token
12+
from django.contrib.auth.models import User
13+
14+
class GetDraftBcoTestCase(TestCase):
15+
fixtures = ['tests/fixtures/test_data']
16+
17+
def setUp(self):
18+
self.client = APIClient()
19+
20+
def test_get_draft(self):
21+
"""Test a successful response with status code 201
22+
"""
23+
token = Token.objects.get(user=User.objects.get(username='test50')).key
24+
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
25+
response = self.client.get('/BCO_000000/DRAFT', format='json')
26+
self.assertEqual(response.status_code, 200)
27+
28+
def test_no_credentials(self):
29+
"""Test for '403: Authentication credentials were not provided.'
30+
"""
31+
32+
response = self.client.get('/BCO_000000/DRAFT', format='json')
33+
self.assertEqual(response.status_code, 403)
34+
35+
def test_dne(self):
36+
"""Test for '404: Not found. That draft could not be found on the
37+
server.'
38+
"""
39+
40+
token = Token.objects.get(user=User.objects.get(username='test50')).key
41+
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
42+
response = self.client.get('/BCO_000100/DRAFT', format='json')
43+
self.assertEqual(response.status_code, 404)
44+
45+
def test_unauthorized(self):
46+
"""Test for '404: Not found. That draft could not be found on the
47+
server.'
48+
"""
49+
50+
token = Token.objects.get(user=User.objects.get(username='test50')).key
51+
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
52+
response = self.client.get('/OTHER_000001/DRAFT', format='json')
53+
self.assertEqual(response.status_code, 401)

0 commit comments

Comments
 (0)