replaycli-py/api/apiproxy/features/steps/steps.py

39 lines
1.6 KiB
Python
Raw Permalink Normal View History

2022-01-21 14:12:26 +00:00
from re import A
from behave import *
from cli import API_Proxy
# =========================== JSON RESPONSE BODY ===========================
@given(u'a API Proxy client')
def step_impl(context):
context.client = API_Proxy ()
@given(u'an APIProxyRequest instance filled with the method GET for the API url: https://pokeapi.co/api/v2/pokemon/ditto')
2022-01-21 14:12:26 +00:00
def step_impl(context):
context.request = context.client.APIProxyRequest
context.request["Method"] = "GET"
context.request["Url"] = "https://pokeapi.co/api/v2/pokemon/ditto"
@when(u'a request is made with the previous instance')
def step_impl(context):
context.response = context.client.do (context.request)
@then(u'the body of this response must be a python dictionary')
2022-01-21 14:12:26 +00:00
def step_impl(context):
assert type (context.response["body"]) == dict, "Something went wrong calling the pokemon/ditto API."
2022-01-21 14:12:26 +00:00
@then(u'the pokemon name, contained in the response body, must be ditto')
2022-01-21 14:12:26 +00:00
def step_impl(context):
assert context.response["body"]["forms"][0]["name"] == "ditto", "This pokemon is not Ditto."
2022-01-21 14:12:26 +00:00
# =========================== TEXT RESPONSE BODY ===========================
@given(u'an APIProxyRequest instance filled with the method GET for the API url: https://www.slashdot.org')
2022-01-21 14:12:26 +00:00
def step_impl(context):
context.request = context.client.APIProxyRequest
context.request["Method"] = "GET"
context.request["Url"] = "https://www.slashdot.org"
@then(u'the response body content type must be string')
2022-01-21 14:12:26 +00:00
def step_impl(context):
assert type (context.response["body"]) == str, "Something went wrong calling the slashdot API."