Skip to content

Commit

Permalink
Correct order of None handling in Cleveland provider script (#544)
Browse files Browse the repository at this point in the history
* Check for none before property access

* Add test
  • Loading branch information
stacimc authored Jun 2, 2022
1 parent b36aac7 commit 8ca6a23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _get_response(query_param, endpoint=ENDPOINT, retries=RETRIES):
response_json, total_images, tries = None, 0, 0
for tries in range(retries):
response = delay_request.get(endpoint, query_param)
if response.status_code == 200 and response is not None:
if response is not None and response.status_code == 200:
try:
response_json = response.json()
total_images = len(response_json["data"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ def test_get_response_failure():
assert mock_get.call_count == 3


def test_get_response_None():
query_param = {"cc": 1, "has_image": 1, "limit": 1, "skip": -1}
with patch.object(clm.delay_request, "get", return_value=None) as mock_get:
response_json, total_images = clm._get_response(query_param)

assert response_json is None
assert total_images == 0
# Retries
assert mock_get.call_count == 3


def test_handle_response():
response_json = _get_resource_json("handle_response_data.json")
data = response_json["data"]
Expand Down

0 comments on commit 8ca6a23

Please sign in to comment.