Skip to content

Commit 826397e

Browse files
Reeya123HadleyKing
andcommitted
Objects_search (#224)
* objects_search * Fix #175 Changes to be committed: modified: search/apis.py modified: tests/test_views/test_api_objects_drafts_publish.py modified: tests/test_views/test_api_objects_search.py --------- Co-authored-by: hadleyking <[email protected]>
1 parent d1ad6aa commit 826397e

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

search/apis.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
from itertools import chain
1313

1414
class SearchObjectsAPI(APIView):
15-
"""Search the BCODB **BETA**
15+
"""
16+
Search the BCODB
1617
1718
-------------------
19+
1820
Endpoint for use of query string based search.
1921
"""
22+
23+
#TODO: multiple values in the URL will only return the last one.
24+
2025
authentication_classes = [CustomJSONWebTokenAuthentication]
2126
permission_classes = [AllowAny,]
2227

@@ -46,18 +51,12 @@ class SearchObjectsAPI(APIView):
4651
)
4752
],
4853
responses={
49-
201: "Account has been authorized.",
50-
208: "Account has already been authorized.",
51-
403: "Requestor's credentials were rejected.",
52-
424: "Account has not been registered.",
54+
200: ""
5355
},
54-
tags=["Account Management"],
56+
tags=["BCO Management"],
5557
)
5658

5759
def get(self, request) -> Response:
58-
"""GET search
59-
TODO: multiple values in the URL will only return the last one.
60-
"""
6160
return_values = [
6261
"contents",
6362
"last_update",

tests/test_views/test_api_objects_drafts_publish.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_publish_bco_invalid_token(self):
105105
}
106106
]
107107
}
108-
#using invalid token
108+
109109
self.client.credentials(HTTP_AUTHORIZATION='invalid token')
110110
response = self.client.post('/api/objects/drafts/publish/', data=data, format='json')
111111
self.assertEqual(response.status_code, 403)

tests/test_views/test_api_objects_search.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1+
#!/usr/bin/env python3
2+
3+
"""Objects Search
4+
Tests for successful search (status code: 200),
5+
prefix not found (status code: 404)
6+
"""
7+
18
from django.test import TestCase
29
from rest_framework.test import APIClient
310
from rest_framework.authtoken.models import Token
411
from django.contrib.auth.models import User
512
from rest_framework.test import APITestCase
613

714
class ObjectsSearchTestCase(APITestCase):
15+
16+
fixtures = ['tests/fixtures/test_data']
817
def setUp(self):
9-
fixtures = ['tests/fixtures/test_data']
18+
1019
self.client = APIClient()
1120
# Checking if the user 'bco_api_user' already exists
1221
try:
@@ -22,7 +31,7 @@ def setUp(self):
2231

2332
def test_search_successful(self):
2433
# Test case for a successful search (status code: 200)
25-
###Gives 404 instead of 200.
34+
2635
data = {
2736
"POST_api_objects_search": [
2837
{
@@ -40,16 +49,16 @@ def test_search_successful(self):
4049

4150
def test_prefix_not_found(self):
4251
# Test case for prefix not found (status code: 404)
52+
4353
data = {
4454
"POST_api_objects_search": [
4555
{
4656
"type": "prefix",
47-
"search": "invalid prefix"
57+
"search": "invalidprefix"
4858
}
4959
]
5060
}
51-
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
5261

62+
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
5363
response = self.client.post("/api/objects/search/", data=data, format="json")
54-
5564
self.assertEqual(response.status_code, 404)

0 commit comments

Comments
 (0)