Skip to content

Commit 2007f49

Browse files
Merge branch 'main' into issue-766-fix-docker-compose
2 parents f38a062 + fe62247 commit 2007f49

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

web/tests/test_views.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,31 @@ def test_robots_txt_post_disallowed(self):
242242
response = self.client.post("/robots.txt")
243243

244244
self.assertEqual(HTTPStatus.METHOD_NOT_ALLOWED, response.status_code)
245+
246+
def test_api_not_found(self):
247+
"""Test if an invalid API call returns a 404 error"""
248+
url = "http://localhost:8000/api/shared/config/config.env/"
249+
response = self.client.get(url)
250+
251+
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
252+
253+
def test_single_concept_view_valid_language_version(self):
254+
"""
255+
Test if the API response contains 'meta' and 'concepts' keys. And doesnt return error.
256+
"""
257+
url = '/api/data_types/javascript/ECMAScript%202009/'
258+
259+
# Send GET request to the URL
260+
response = self.client.get(url)
261+
262+
# Check the response status
263+
self.assertEqual(response.status_code, HTTPStatus.OK)
264+
265+
# Parse the response JSON
266+
response_data = response.json()
267+
268+
# Assert that 'meta' and 'concepts' keys exist
269+
self.assertIn('meta', response_data)
270+
self.assertIn('concepts', response_data)
271+
272+

web/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,16 @@ def api_reference(request, structure_key, lang, version):
428428
store_url_info(request)
429429

430430
lang = Language(lang, "")
431-
response = lang.load_filled_concepts(structure_key, version)
431+
432+
try:
433+
response = lang.load_filled_concepts(structure_key, version)
434+
except Exception as e:
435+
return error_handler_404_not_found(request, e)
432436

433437
if response is False:
434438
return HttpResponseNotFound()
435439

440+
436441
return HttpResponse(response, content_type="application/json")
437442

438443
def api_compare(request, structure_key, lang1, version1, lang2, version2):

0 commit comments

Comments
 (0)