Feature data/response/success
This commit is contained in:
@@ -13,7 +13,7 @@ Feature: Setting values for handler response resources in Kapow! server.
|
|||||||
When I send a request to the testing route "/listRootDir"
|
When I send a request to the testing route "/listRootDir"
|
||||||
And I set the resource "/response/status" with value "418"
|
And I set the resource "/response/status" with value "418"
|
||||||
And I release the testing request
|
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.
|
Scenario Outline: Set different resources for the current response.
|
||||||
Set the following resources for the current
|
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
|
And I release the testing request
|
||||||
Then I get 200 as response code
|
Then I get 200 as response code
|
||||||
And I get "OK" as response reason phrase
|
And I get "OK" as response reason phrase
|
||||||
And I get the value <value> for the response <fieldType> named <elementName>
|
And I get the value "<value>" for the response "<fieldType>" named "<elementName>" in the testing request
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
| resourcePath | value | fieldType | elementName |
|
| resourcePath | value | fieldType | elementName |
|
||||||
| /headers/head1 | "headVal1" | header | "head1" |
|
| /response/headers/head1 | headVal1 | header | head1 |
|
||||||
| /cookies/cook1 | "cookVal1" | cookie | "cook1" |
|
| /response/cookies/cook1 | cookVal1 | cookie | cook1 |
|
||||||
| /body | "bodyValue1" | body | "" |
|
| /response/body | bodyValue1 | body | - |
|
||||||
| /stream | "bodyValue2" | body | "" |
|
| /response/stream | bodyValue2 | body | - |
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
|
from multiprocessing.pool import ThreadPool
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -126,10 +127,7 @@ def step_impl(context):
|
|||||||
|
|
||||||
def testing_request(context, request_fn):
|
def testing_request(context, request_fn):
|
||||||
# Run the request in background
|
# Run the request in background
|
||||||
def _testing_request():
|
context.testing_request = ThreadPool(processes=1).apply_async(request_fn)
|
||||||
context.testing_response = request_fn()
|
|
||||||
context.testing_request = threading.Thread(target=_testing_request)
|
|
||||||
context.testing_request.start()
|
|
||||||
|
|
||||||
# Block until the handler connects and give us its pid and the
|
# Block until the handler connects and give us its pid and the
|
||||||
# handler_id
|
# handler_id
|
||||||
@@ -152,7 +150,7 @@ def step_impl(context, path):
|
|||||||
@when('I release the testing request')
|
@when('I release the testing request')
|
||||||
def step_impl(context):
|
def step_impl(context):
|
||||||
os.kill(int(context.testing_handler_pid), signal.SIGTERM)
|
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')
|
@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"
|
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')
|
@then('I get "{reason}" as response reason phrase')
|
||||||
def step_impl(context, reason):
|
def step_impl(context, reason):
|
||||||
assert context.response.reason == reason, f"Got {context.response.reason} instead"
|
assert context.response.reason == reason, f"Got {context.response.reason} instead"
|
||||||
@@ -274,3 +277,17 @@ def step_impl(context, path):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
testing_request(context, _request)
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user