diff --git a/spec/test/features/data/response/success.feature b/spec/test/features/data/response/success.feature index 3e00bd1..8031781 100644 --- a/spec/test/features/data/response/success.feature +++ b/spec/test/features/data/response/success.feature @@ -13,7 +13,7 @@ Feature: Setting values for handler response resources in Kapow! server. When I send a request to the testing route "/listRootDir" And I set the resource "/response/status" with value "418" And I release the testing request - Then I get 418 as response code + Then I get 418 as response code in the testing request Scenario Outline: Set different resources for the current response. Set the following resources for the current @@ -27,11 +27,11 @@ Feature: Setting values for handler response resources in Kapow! server. And I release the testing request Then I get 200 as response code And I get "OK" as response reason phrase - And I get the value for the response named + And I get the value "" for the response "" named "" in the testing request Examples: - | resourcePath | value | fieldType | elementName | - | /headers/head1 | "headVal1" | header | "head1" | - | /cookies/cook1 | "cookVal1" | cookie | "cook1" | - | /body | "bodyValue1" | body | "" | - | /stream | "bodyValue2" | body | "" | + | resourcePath | value | fieldType | elementName | + | /response/headers/head1 | headVal1 | header | head1 | + | /response/cookies/cook1 | cookVal1 | cookie | cook1 | + | /response/body | bodyValue1 | body | - | + | /response/stream | bodyValue2 | body | - | diff --git a/spec/test/features/steps/steps.py b/spec/test/features/steps/steps.py index aaa000e..02f0ad2 100644 --- a/spec/test/features/steps/steps.py +++ b/spec/test/features/steps/steps.py @@ -9,6 +9,7 @@ import subprocess import sys import tempfile import threading +from multiprocessing.pool import ThreadPool import time import requests @@ -126,10 +127,7 @@ def step_impl(context): def testing_request(context, request_fn): # Run the request in background - def _testing_request(): - context.testing_response = request_fn() - context.testing_request = threading.Thread(target=_testing_request) - context.testing_request.start() + context.testing_request = ThreadPool(processes=1).apply_async(request_fn) # Block until the handler connects and give us its pid and the # handler_id @@ -152,7 +150,7 @@ def step_impl(context, path): @when('I release the testing request') def step_impl(context): os.kill(int(context.testing_handler_pid), signal.SIGTERM) - context.testing_request.join() + context.testing_response = context.testing_request.get() @when('I append the route') @@ -167,6 +165,11 @@ def step_impl(context, code): assert context.response.status_code == int(code), f"Got {context.response.status_code} instead" +@then('I get {code} as response code in the testing request') +def step_impl(context, code): + assert context.testing_response.status_code == int(code), f"Got {context.response.status_code} instead" + + @then('I get "{reason}" as response reason phrase') def step_impl(context, reason): assert context.response.reason == reason, f"Got {context.response.reason} instead" @@ -274,3 +277,17 @@ def step_impl(context, path): return None testing_request(context, _request) + + +@then('I get the value "{value}" for the response "{fieldType}" named "{elementName}" in the testing request') +def step_impl(context, value, fieldType, elementName): + if fieldType == "header": + actual = context.testing_response.headers.get(elementName) + elif fieldType == "cookie": + actual = context.testing_response.cookies.get(elementName) + elif fieldType == "body": + actual = context.testing_response.text + else: + raise ValueError("Unknown fieldtype {fieldType!r}") + + assert actual == value, f"Expecting {fieldType} {elementName!r} to be {value!r}, got {actual!r} insted"