From eb8c3c1a1a39955e229474bfc2b8abd49138fc4a Mon Sep 17 00:00:00 2001 From: Kevin Reynolds Date: Wed, 1 May 2024 18:23:19 -0400 Subject: [PATCH] test function --- labapp/app/app.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/labapp/app/app.py b/labapp/app/app.py index 11730b4..5de1a8a 100644 --- a/labapp/app/app.py +++ b/labapp/app/app.py @@ -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.