From ad34f46e7060f759b97f1e2b17b2d4bf0ae99c7d Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Guedes Date: Mon, 31 Jan 2022 12:19:30 -0300 Subject: [PATCH] Updating the test methods according to the new response interface. Check the last commit to more information about the new return interface. --- api/apiproxy/features/apiproxy.feature | 12 ++++---- api/apiproxy/features/steps/steps.py | 38 ++++++++++++-------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/api/apiproxy/features/apiproxy.feature b/api/apiproxy/features/apiproxy.feature index 22c566b..d96e227 100644 --- a/api/apiproxy/features/apiproxy.feature +++ b/api/apiproxy/features/apiproxy.feature @@ -1,12 +1,14 @@ 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 + And an APIProxyRequest instance filled with the method GET for the API url: https://pokeapi.co/api/v2/pokemon/ditto + When a request is made with the previous instance + 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 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 \ No newline at end of file + And an APIProxyRequest instance filled with the method GET for the API url: https://www.slashdot.org + When a request is made with the previous instance + Then the response body content type must be string \ No newline at end of file diff --git a/api/apiproxy/features/steps/steps.py b/api/apiproxy/features/steps/steps.py index 4b7797a..5e5f89c 100644 --- a/api/apiproxy/features/steps/steps.py +++ b/api/apiproxy/features/steps/steps.py @@ -7,35 +7,33 @@ from cli import API_Proxy 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') +@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): - context.response = context.client.do ( - { - "Method": "GET", - "Url": "https://pokeapi.co/api/v2/pokemon/ditto", - } - ) + context.request = context.client.APIProxyRequest + context.request["Method"] = "GET" + context.request["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): - 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): - 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 =========================== -@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): - context.response = context.client.do ( - { - "Method": "GET", - "Url": "https://www.slashdot.org", - } - ) + context.request = context.client.APIProxyRequest + context.request["Method"] = "GET" + context.request["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): - assert type (context.response) == str, "Something went wrong calling the slashdot API." \ No newline at end of file + assert type (context.response["body"]) == str, "Something went wrong calling the slashdot API." \ No newline at end of file