Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions tests/e2e/features/steps/common_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def request_endpoint_with_body(
def request_endpoint_with_json(
context: Context, endpoint: str, hostname: str, port: int
) -> None:
"""Perform a request to the local server with a given JSON in the request."""
"""Perform a request to the local server with a given JSON in the request.

The JSON payload is parsed from `context.text`, which must not
be None in order for this step to succeed. The response is
saved to `context.response` attribute.
"""
# initial value
context.response = None

Expand All @@ -53,7 +58,12 @@ def request_endpoint_with_json(
def request_endpoint_with_url_params(
context: Context, endpoint: str, hostname: str, port: int
) -> None:
"""Perform a request to the server defined by URL to a given endpoint."""
"""Perform a request to the server defined by URL to a given endpoint.

The function asserts that `context.table` is provided and uses
its rows to build the query parameters for the request. The
HTTP response is stored in `context.response` attribute.
"""
params = {}

assert context.table is not None, "Request parameters needs to be specified"
Expand Down Expand Up @@ -122,7 +132,12 @@ def check_content_type(context: Context, content_type: str) -> None:

@then("The body of the response has the following schema")
def check_response_body_schema(context: Context) -> None:
"""Check that response body is compliant with a given schema."""
"""Check that response body is compliant with a given schema.

Asserts that a response has been received and that a schema is
present in `context.text` attribute. Loads the schema from
`context.text` attribute and validates the response body.
"""
assert context.response is not None, "Request needs to be performed first"
assert context.text is not None, "Response does not contain any payload"
schema = json.loads(context.text)
Expand All @@ -142,7 +157,12 @@ def check_response_body_contains(context: Context, substring: str) -> None:

@then("The body of the response is the following")
def check_prediction_result(context: Context) -> None:
"""Check the content of the response to be exactly the same."""
"""Check the content of the response to be exactly the same.

Raises an assertion error if the response is missing, the
expected payload is not provided, or if the actual and expected
JSON objects differ.
"""
assert context.response is not None, "Request needs to be performed first"
assert context.text is not None, "Response does not contain any payload"
expected_body = json.loads(context.text)
Expand All @@ -154,7 +174,14 @@ def check_prediction_result(context: Context) -> None:

@then('The body of the response, ignoring the "{field}" field, is the following')
def check_prediction_result_ignoring_field(context: Context, field: str) -> None:
"""Check the content of the response to be exactly the same."""
"""Check the content of the response to be exactly the same.

Asserts that the JSON response body matches the expected JSON
payload, ignoring a specified field.

Parameters:
field (str): The name of the field to exclude from both the actual and expected JSON objects during comparison.
"""
assert context.response is not None, "Request needs to be performed first"
assert context.text is not None, "Response does not contain any payload"
expected_body = json.loads(context.text).copy()
Expand Down Expand Up @@ -219,7 +246,12 @@ def access_rest_api_endpoint_get(context: Context, endpoint: str) -> None:

@when("I access endpoint {endpoint:w} using HTTP POST method")
def access_rest_api_endpoint_post(context: Context, endpoint: str) -> None:
"""Send GET HTTP request to tested service."""
"""Send POST HTTP request with JSON payload to tested service.

The JSON payload is retrieved from `context.text` attribute,
which must not be None. The response is stored in
`context.response` attribute.
"""
base = f"http://{context.hostname}:{context.port}"
path = f"{context.api_prefix}/{endpoint}".replace("//", "/")
url = base + path
Expand Down
10 changes: 9 additions & 1 deletion tests/e2e/features/steps/llm_query_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ def check_llm_response_not_truncated(context: Context) -> None:

@then("The response should contain following fragments")
def check_fragments_in_response(context: Context) -> None:
"""Check if the LLM response contain list of fragments."""
"""Check that all specified fragments are present in the LLM response.

First checks that the HTTP response exists and contains a
"response" field. For each fragment listed in the scenario's
table under "Fragments in LLM response", asserts that it
appears as a substring in the LLM's response. Raises an
assertion error if any fragment is missing or if the fragments
table is not provided.
"""
assert context.response is not None
response_json = context.response.json()
response = response_json["response"]
Expand Down