Add more steps

This commit is contained in:
Fang-Pen Lin
2025-11-07 09:17:44 -08:00
parent 375a74fc26
commit d3539e1d3a
3 changed files with 24 additions and 8 deletions
+13 -7
View File
@@ -1,14 +1,10 @@
from behave.runner import Context
import httpx
from behave import given
from behave import when
from behave import then
BASE_URL = "http://localhost:8080"
class PkiProject:
def __init__(self, id: str):
self.id = id
@@ -25,11 +21,21 @@ def step_impl(context: Context, project_var: str):
@when('I send a {method} request to "{url}"')
def step_impl(context: Context, method: str, url: str):
with httpx.Client(base_url=BASE_URL) as client:
context.response = client.request(method, url.format(**context.vars))
context.response = context.http_client.request(method, url.format(**context.vars))
@then('the response status code should be "{expected_status_code}"')
def step_impl(context: Context, expected_status_code: int):
assert context.response.status_code == expected_status_code, (
f"{context.response.status_code} != {expected_status_code}"
)
@then('the response header "{header}" should contains non-empty value')
def step_impl(context: Context, header: str):
header_value = context.response.headers.get(header)
assert header_value
print(context.response.headers)
assert header_value is not None, f"Header {header} not found in response"
assert header_value, (
f"Header {header} found in response, but value {header_value:!r} is empty"
)