From 86d1d612a05da791339fd3bdecf90b34945a35f8 Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Guedes Date: Fri, 21 Jan 2022 11:12:26 -0300 Subject: [PATCH] Adding API Proxy tests. --- api/apiproxy/features/apiproxy.feature | 12 ++++++++ api/apiproxy/features/steps/steps.py | 41 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/api/apiproxy/features/apiproxy.feature b/api/apiproxy/features/apiproxy.feature index e69de29..22c566b 100644 --- a/api/apiproxy/features/apiproxy.feature +++ b/api/apiproxy/features/apiproxy.feature @@ -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 \ No newline at end of file diff --git a/api/apiproxy/features/steps/steps.py b/api/apiproxy/features/steps/steps.py index e69de29..4b7797a 100644 --- a/api/apiproxy/features/steps/steps.py +++ b/api/apiproxy/features/steps/steps.py @@ -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." \ No newline at end of file