Adding API Proxy tests.
parent
4c130636d3
commit
86d1d612a0
|
@ -0,0 +1,12 @@
|
|||
Feature: The API Proxy client
|
||||
Scenario: A HTTP request with json body response
|
||||
Given a API Proxy client
|
||||
When a request is made with GET for the API: https://pokeapi.co/api/v2/pokemon/ditto
|
||||
Then there must be a json response
|
||||
And the pokemon name must be ditto
|
||||
|
||||
|
||||
Scenario: A HTTP request with text body response
|
||||
Given a API Proxy client
|
||||
When a request is made with GET for the API: https://www.slashdot.org
|
||||
Then the response content type must be string
|
|
@ -0,0 +1,41 @@
|
|||
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."
|
Loading…
Reference in New Issue