33import json
44
55import requests
6- from behave import given , then , when
6+ from behave import given , then , when # pyright: ignore[reportAttributeAccessIssue]
77from behave .runner import Context
88from tests .e2e .utils .utils import normalize_endpoint , validate_json
99
@@ -37,6 +37,8 @@ def request_endpoint_with_json(
3737 # initial value
3838 context .response = None
3939
40+ assert context .text is not None , "Payload needs to be specified"
41+
4042 # perform REST API call
4143 context .response = requests .get (
4244 f"http://{ hostname } :{ port } /{ endpoint } " ,
@@ -54,6 +56,8 @@ def request_endpoint_with_url_params(
5456 """Perform a request to the server defined by URL to a given endpoint."""
5557 params = {}
5658
59+ assert context .table is not None , "Request parameters needs to be specified"
60+
5761 for row in context .table :
5862 name = row ["param" ]
5963 value = row ["value" ]
@@ -120,6 +124,7 @@ def check_content_type(context: Context, content_type: str) -> None:
120124def check_response_body_schema (context : Context ) -> None :
121125 """Check that response body is compliant with a given schema."""
122126 assert context .response is not None , "Request needs to be performed first"
127+ assert context .text is not None , "Response does not contain any payload"
123128 schema = json .loads (context .text )
124129 body = context .response .json ()
125130
@@ -139,6 +144,7 @@ def check_response_body_contains(context: Context, substring: str) -> None:
139144def check_prediction_result (context : Context ) -> None :
140145 """Check the content of the response to be exactly the same."""
141146 assert context .response is not None , "Request needs to be performed first"
147+ assert context .text is not None , "Response does not contain any payload"
142148 expected_body = json .loads (context .text )
143149 result = context .response .json ()
144150
@@ -150,6 +156,7 @@ def check_prediction_result(context: Context) -> None:
150156def check_prediction_result_ignoring_field (context : Context , field : str ) -> None :
151157 """Check the content of the response to be exactly the same."""
152158 assert context .response is not None , "Request needs to be performed first"
159+ assert context .text is not None , "Response does not contain any payload"
153160 expected_body = json .loads (context .text ).copy ()
154161 result = context .response .json ().copy ()
155162
@@ -217,6 +224,7 @@ def access_rest_api_endpoint_post(context: Context, endpoint: str) -> None:
217224 path = f"{ context .api_prefix } /{ endpoint } " .replace ("//" , "/" )
218225 url = base + path
219226
227+ assert context .text is not None , "Payload needs to be specified"
220228 data = json .loads (context .text )
221229 # initial value
222230 context .response = None
0 commit comments