Skip to content

Commit

Permalink
test function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed May 1, 2024
1 parent c318f90 commit eb8c3c1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ def cloudapp_fetch(session, url, timeout, prop, value, headers = {}):
return data
return data

def cloudapp_fetch2(session, url, timeout, prop, key, value):
"""
Fetch data from URL
Validate if a specific key-value pair is present in the dictionary located at `prop` in the JSON response
"""
response = session.get(url, timeout=timeout)
response.raise_for_status()
data = response.json()

prop_data = data.get(prop, {})
if not isinstance(prop_data, dict) or prop_data.get(key) != value:
raise ValueError(f"Expected {key}: {value} in {prop}, but got {key}: {prop_data.get(key)}")

if data.get("request_headers"):
clean_headers = headers_cleaner(data['request_headers'])
data['request_headers'] = clean_headers

return data

def headers_cleaner(headers):
"""
Remove headers that contain specific substrings.
Expand Down

0 comments on commit eb8c3c1

Please sign in to comment.