Skip to content

Commit

Permalink
Refactor config/services.py::response_constructor
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   config/services.py
	modified:   tests/test_apis/test_api_prefix/test_prefixes_create.py
  • Loading branch information
HadleyKing committed Apr 19, 2024
1 parent a4c5c46 commit 3cea13e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions config/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ def response_constructor(
"""

response_object = {
identifier: {
"request_status": status,
"status_code": code
}
"identifier": identifier,
"request_status": status,
"status_code": code
}

if data is not None:
response_object[identifier]["data"] = data
response_object["data"] = data
if message is not None:
response_object[identifier]["message"] = message
response_object["message"] = message

return response_object
6 changes: 3 additions & 3 deletions tests/test_apis/test_api_prefix/test_prefixes_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ def test_create_multi_status(self):
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
response = self.client.post('/api/prefixes/create/', data=data, format='json')
# 201: The prefix * was successfully created.
self.assertEqual(response.data[2]['TEST2']['status_code'], 201)
self.assertEqual(response.data[2]['status_code'], 201)

# 400: Bad Request. The prefix * does not follow the naming rules for a prefix.
self.assertIn('prefix', response.data[0]['INVALID-PREFIX']['data'])
self.assertIn('prefix', response.data[0]['data'])

# 409: Conflict. The prefix the requestor is attempting to create already exists.
self.assertIn('prefix_name', response.data[3]['TEST']['data'])
self.assertIn('prefix_name', response.data[3]['data'])

self.assertEqual(response.status_code, 207)

Expand Down

0 comments on commit 3cea13e

Please sign in to comment.