@@ -33,7 +33,12 @@ def request_endpoint_with_body(
3333def 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(
5358def 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" )
124134def 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" )
144159def 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' )
156176def 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" )
221248def 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
0 commit comments