Given:
Getting all values from a certain node in json using python
I now want to use the dict (all_ids) constructed in this function:
def test_get_powerplant():
global hpsId
global powerplantId
# Act:
response = get_requests(token, '/api/powerplant/all')
try:
data = response.json()
all_ids = [(item["hpsId"], item["powerPlant"]["id"]) for item in data]
print(all_ids)
except KeyError:
print("Unable to get values")
as input to my function setpayload_bids (for alle the pairs of values)
def setpayload_bids(hps_id, pp_id):
# Arrange:
myjson = {
"hpsId": hps_id,
"powerPlantId": pp_id,
"timeAxis": {
"t0": 0,
"dt": 0,
"n": 0,
"time_Points": [
0
]
},
"readPeriod": [
0
]
}
return myjson
The above set-function is called in another (pytest) like this:
def test_bids():
# Act:
response = post_requests(token, '/api/Bids', setpayload_bids(hpsId, powerplantId))
# Assertion:
assert response.status_code == 200 # Validation of status code
Not sure how and where to iterate over the dict for n-times to be able to send one request against /api/Bids with all the pair values. Probably in the def setpayload_bids(hps_id, pp_id), where the dict can be a parameter?