diff --git a/spec/test/features/data/handler/error_invalidresource.feature b/spec/test/features/data/handler/error_invalidresource.feature index 6541c1a..eeeab48 100644 --- a/spec/test/features/data/handler/error_invalidresource.feature +++ b/spec/test/features/data/handler/error_invalidresource.feature @@ -1,7 +1,6 @@ -Feature: Fail to retrieve invalid resources from a handler in Kapow! server. - If trying to access an invalid resource from - a handler then the server responds with an - error. +Feature: Fail to retrieve an invalid resource for a handler in Kapow! server. + If trying to access an invalid resource for a handler + then the server responds with an error. Scenario: Try to get an inexistent resource from a handler. A request to retrieve an invalid resource diff --git a/spec/test/features/data/handler/error_notfound.feature b/spec/test/features/data/handler/error_notfound.feature index 5bc031b..8a04294 100644 --- a/spec/test/features/data/handler/error_notfound.feature +++ b/spec/test/features/data/handler/error_notfound.feature @@ -1,6 +1,6 @@ -Feature: Fail to retrieve resources from a nonexistent handler in Kapow! server. - If trying to access a nonexistent handler then - the server responds with a not found error. +Feature: Fail to retrieve resources from nonexistent handler in Kapow! server. + If trying to access a nonexistent handler then the + server responds with a noptfound error. Scenario: Try to get a valid resource path from a nonexistent handler. A request to retrieve a resource from a diff --git a/spec/test/features/steps/steps.py b/spec/test/features/steps/steps.py index a163a1a..dcc5f74 100644 --- a/spec/test/features/steps/steps.py +++ b/spec/test/features/steps/steps.py @@ -1,6 +1,8 @@ from contextlib import suppress from time import sleep import json +import os +import threading import shlex import socket import subprocess @@ -124,6 +126,7 @@ def step_impl(context, id): context.response = requests.delete(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}") +@given('I insert the route') @when('I insert the route') def step_impl(context): context.response = requests.put(f"{Env.KAPOW_CONTROLAPI_URL}/routes", @@ -165,3 +168,23 @@ def step_impl(context, order): routes = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes") id = routes.json()[idx]["id"] context.response = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}") + + +@when('I send a background request to the route {route}') +def step_imp(context, route): + def _back(): + return requests.get(f"{Env.KAPOW_DATAAPI_URL}/{route}") + context.background_request = threading.Thread(target=_back) + context.background_request.start() + + +@when('I get the resource {resource} for the current request handler') +def step_imp(context, resource): + def retrieve_request_id(): + target = os.listdir('/tmp/wip')[0] + with open(target, "r") as f: + return f.readline().strip() + background_request_id = retrieve_request_id() + resource = f"/handlers/{background_request_id}/{resource}" + context.response = requests.get(resource) +