Skip to content

Commit

Permalink
Merge pull request Kuadrant#367 from trepel/extract-response-empty-ha…
Browse files Browse the repository at this point in the history
…ndling

Improve extract_response to return None for empty content only
  • Loading branch information
azgabur authored Mar 14, 2024
2 parents a4bb2ff + f6c4018 commit ea59682
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions testsuite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def generate_tail(tail=5):


def randomize(name, tail=5):
"To avoid conflicts returns modified name with random sufffix"
"To avoid conflicts returns modified name with random suffix"
return f"{name}-{generate_tail(tail)}"


Expand Down Expand Up @@ -125,8 +125,8 @@ def extract_response(response, header="Simple", key="data"):
:return: Extracted value
"""

# Returning None for non-200 responses because the content of such responses might not be a valid JSON
if response.status_code != 200:
# Returning None if content is empty, this typically happens for non-200 responses
if len(response.content) == 0:
return weakget(None)

return weakget(json.loads(response.json()["headers"][header]))[key]
Expand Down

0 comments on commit ea59682

Please sign in to comment.