Skip to content

Commit eb8c3c1

Browse files
author
Kevin Reynolds
committed
test function
1 parent c318f90 commit eb8c3c1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

labapp/app/app.py

+19
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ def cloudapp_fetch(session, url, timeout, prop, value, headers = {}):
5959
return data
6060
return data
6161

62+
def cloudapp_fetch2(session, url, timeout, prop, key, value):
63+
"""
64+
Fetch data from URL
65+
Validate if a specific key-value pair is present in the dictionary located at `prop` in the JSON response
66+
"""
67+
response = session.get(url, timeout=timeout)
68+
response.raise_for_status()
69+
data = response.json()
70+
71+
prop_data = data.get(prop, {})
72+
if not isinstance(prop_data, dict) or prop_data.get(key) != value:
73+
raise ValueError(f"Expected {key}: {value} in {prop}, but got {key}: {prop_data.get(key)}")
74+
75+
if data.get("request_headers"):
76+
clean_headers = headers_cleaner(data['request_headers'])
77+
data['request_headers'] = clean_headers
78+
79+
return data
80+
6281
def headers_cleaner(headers):
6382
"""
6483
Remove headers that contain specific substrings.

0 commit comments

Comments
 (0)