For Example-
step1-For every api call we need to encrypt the payload with the help of encrypt API
step 2- This output of encrypt API will pass as payload of another API(say Login API)
Step 3- Again for another API say(logout API), I need to encrypt the plain text payload and use the encrypted payload as input payload for logout API
My approach is like
@pytest.fixture()
def setup():
payload = {
"userName": "7978130592",
"password": "Test@123",
"SessionId": "abc123",
"version": "1620"
}
url = "http://101.15.101.256:443/encrypt"
response = requests.request("POST",url,headers=headers,data=json.dumps(payload))
python_response = json.loads(response.text)
jsonpath_data = parse("$.data")
data =(jsonpath_data.find(python_response)[0].value)
return data
def test_login(setup):
headers = {
'Content-Type': 'application/json',
}
url = "https://testsite.com/users/Login"
payload = setup
response = requests.request("POST",url=url,headers=headers,data=payload)
and for logout API payload is like below and i want to encrypt this paylaod by using encrypt API which is defined as method for fixture.
{
"deviceId": "goldfishx86",
"user": "xyz",
"isGpsEnabled": "Y"
}
My query here is how can I replace my different payload again and again in same method so that I use the output in different API call
What I have tried:
Please help me, I tried but could not succeed to use different payload as input of fixture method
@pytest.fixture()
def setup():
payload = {
"userName": "7978130592",
"password": "Test@123",
"SessionId": "abc123",
"version": "1620"
}
url = "http://101.15.101.256:443/encrypt"
response = requests.request("POST",url,headers=headers,data=json.dumps(payload))
python_response = json.loads(response.text)
jsonpath_data = parse("$.data")
data =(jsonpath_data.find(python_response)[0].value)
return data
def test_login(setup):
headers = {
'Content-Type': 'application/json',
}
url = "https://testsite.com/users/Login"
payload = setup
response = requests.request("POST",url=url,headers=headers,data=payload)
def test_logout(setup):
payload =
{
"deviceId": "goldfishx86",
"user": "xyz",
"isGpsEnabled": "Y"
}
url = "https://testsite.com/users/Logout"
response = requests.request("POST", url, headers=headers, data=json.dumps(payload))