Skip to content

Commit 4a4e90c

Browse files
committed
LCORE-303: updated docstrings
1 parent 36225c9 commit 4a4e90c

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

tests/e2e/features/steps/common_http.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ def request_endpoint_with_body(
3333
def request_endpoint_with_json(
3434
context: Context, endpoint: str, hostname: str, port: int
3535
) -> None:
36-
"""Perform a request to the local server with a given JSON in the request."""
36+
"""Perform a request to the local server with a given JSON in the request.
37+
38+
The JSON payload is parsed from `context.text`, which must not
39+
be None in order for this step to succeed. The response is
40+
saved to `context.response` attribute.
41+
"""
3742
# initial value
3843
context.response = None
3944

@@ -53,7 +58,12 @@ def request_endpoint_with_json(
5358
def request_endpoint_with_url_params(
5459
context: Context, endpoint: str, hostname: str, port: int
5560
) -> None:
56-
"""Perform a request to the server defined by URL to a given endpoint."""
61+
"""Perform a request to the server defined by URL to a given endpoint.
62+
63+
The function asserts that `context.table` is provided and uses
64+
its rows to build the query parameters for the request. The
65+
HTTP response is stored in `context.response` attribute.
66+
"""
5767
params = {}
5868

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

123133
@then("The body of the response has the following schema")
124134
def check_response_body_schema(context: Context) -> None:
125-
"""Check that response body is compliant with a given schema."""
135+
"""Check that response body is compliant with a given schema.
136+
137+
Asserts that a response has been received and that a schema is
138+
present in `context.text` attribute. Loads the schema from
139+
`context.text` attribute and validates the response body.
140+
"""
126141
assert context.response is not None, "Request needs to be performed first"
127142
assert context.text is not None, "Response does not contain any payload"
128143
schema = json.loads(context.text)
@@ -142,7 +157,12 @@ def check_response_body_contains(context: Context, substring: str) -> None:
142157

143158
@then("The body of the response is the following")
144159
def check_prediction_result(context: Context) -> None:
145-
"""Check the content of the response to be exactly the same."""
160+
"""Check the content of the response to be exactly the same.
161+
162+
Raises an assertion error if the response is missing, the
163+
expected payload is not provided, or if the actual and expected
164+
JSON objects differ.
165+
"""
146166
assert context.response is not None, "Request needs to be performed first"
147167
assert context.text is not None, "Response does not contain any payload"
148168
expected_body = json.loads(context.text)
@@ -154,7 +174,14 @@ def check_prediction_result(context: Context) -> None:
154174

155175
@then('The body of the response, ignoring the "{field}" field, is the following')
156176
def check_prediction_result_ignoring_field(context: Context, field: str) -> None:
157-
"""Check the content of the response to be exactly the same."""
177+
"""Check the content of the response to be exactly the same.
178+
179+
Asserts that the JSON response body matches the expected JSON
180+
payload, ignoring a specified field.
181+
182+
Parameters:
183+
field (str): The name of the field to exclude from both the actual and expected JSON objects during comparison.
184+
"""
158185
assert context.response is not None, "Request needs to be performed first"
159186
assert context.text is not None, "Response does not contain any payload"
160187
expected_body = json.loads(context.text).copy()
@@ -219,7 +246,12 @@ def access_rest_api_endpoint_get(context: Context, endpoint: str) -> None:
219246

220247
@when("I access endpoint {endpoint:w} using HTTP POST method")
221248
def access_rest_api_endpoint_post(context: Context, endpoint: str) -> None:
222-
"""Send GET HTTP request to tested service."""
249+
"""Send POST HTTP request with JSON payload to tested service.
250+
251+
The JSON payload is retrieved from `context.text` attribute,
252+
which must not be None. The response is stored in
253+
`context.response` attribute.
254+
"""
223255
base = f"http://{context.hostname}:{context.port}"
224256
path = f"{context.api_prefix}/{endpoint}".replace("//", "/")
225257
url = base + path

tests/e2e/features/steps/llm_query_response.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ def check_llm_response_not_truncated(context: Context) -> None:
3636

3737
@then("The response should contain following fragments")
3838
def check_fragments_in_response(context: Context) -> None:
39-
"""Check if the LLM response contain list of fragments."""
39+
"""Check that all specified fragments are present in the LLM response.
40+
41+
First checks that the HTTP response exists and contains a
42+
"response" field. For each fragment listed in the scenario's
43+
table under "Fragments in LLM response", asserts that it
44+
appears as a substring in the LLM's response. Raises an
45+
assertion error if any fragment is missing or if the fragments
46+
table is not provided.
47+
"""
4048
assert context.response is not None
4149
response_json = context.response.json()
4250
response = response_json["response"]

0 commit comments

Comments
 (0)