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 ()
|
|
|
|
|
|
|
|
@when(u'a request is made with GET for the API: https://pokeapi.co/api/v2/pokemon/ditto')
|
|
|
|
def step_impl(context):
|
|
|
|
context.response = context.client.do (
|
|
|
|
{
|
|
|
|
"Method": "GET",
|
|
|
|
"Url": "https://pokeapi.co/api/v2/pokemon/ditto",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
@then(u'there must be a json response')
|
|
|
|
def step_impl(context):
|
|
|
|
assert type (context.response) == dict, "Something went wrong calling the pokemon/ditto API."
|
|
|
|
|
|
|
|
@then(u'the pokemon name must be ditto')
|
|
|
|
def step_impl(context):
|
|
|
|
assert context.response["forms"][0]["name"] == "ditto", "This pokemon is not Ditto."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# =========================== TEXT RESPONSE BODY ===========================
|
|
|
|
@when(u'a request is made with GET for the API: https://www.slashdot.org')
|
|
|
|
def step_impl(context):
|
|
|
|
context.response = context.client.do (
|
|
|
|
{
|
|
|
|
"Method": "GET",
|
|
|
|
"Url": "https://www.slashdot.org",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
@then(u'the response content type must be string')
|
|
|
|
def step_impl(context):
|
|
|
|
assert type (context.response) == str, "Something went wrong calling the slashdot API."
|