Updating the test methods according to the new response interface.

Check the last commit to more information about the new return interface.
master
Pedro de Oliveira Guedes 2022-01-31 12:19:30 -03:00
parent 94337e2949
commit ad34f46e70
2 changed files with 25 additions and 25 deletions

View File

@ -1,12 +1,14 @@
Feature: The API Proxy client Feature: The API Proxy client
Scenario: A HTTP request with json body response Scenario: A HTTP request with json body response
Given a API Proxy client Given a API Proxy client
When a request is made with GET for the API: https://pokeapi.co/api/v2/pokemon/ditto And an APIProxyRequest instance filled with the method GET for the API url: https://pokeapi.co/api/v2/pokemon/ditto
Then there must be a json response When a request is made with the previous instance
And the pokemon name must be ditto Then the body of this response must be a python dictionary
And the pokemon name, contained in the response body, must be ditto
Scenario: A HTTP request with text body response Scenario: A HTTP request with text body response
Given a API Proxy client Given a API Proxy client
When a request is made with GET for the API: https://www.slashdot.org And an APIProxyRequest instance filled with the method GET for the API url: https://www.slashdot.org
Then the response content type must be string When a request is made with the previous instance
Then the response body content type must be string

View File

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