Skip to content

Commit 36225c9

Browse files
authored
Merge pull request lightspeed-core#228 from tisnik/lcore-303-fix-e2e-tests
LCORE-303: fixes made in E2E tests
2 parents b074aea + 8dfdd6e commit 36225c9

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

tests/e2e/features/steps/common_http.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44

55
import requests
6-
from behave import given, then, when
6+
from behave import given, then, when # pyright: ignore[reportAttributeAccessIssue]
77
from behave.runner import Context
88
from 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:
120124
def 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:
139144
def 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:
150156
def 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

tests/e2e/features/steps/llm_query_response.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""LLM query and response steps."""
22

33
import requests
4-
from behave import then, when
4+
from behave import then, when # pyright: ignore[reportAttributeAccessIssue]
55
from behave.runner import Context
66

77
DEFAULT_LLM_TIMEOUT = 60
@@ -41,6 +41,8 @@ def check_fragments_in_response(context: Context) -> None:
4141
response_json = context.response.json()
4242
response = response_json["response"]
4343

44+
assert context.table is not None, "Fragments are not specified in table"
45+
4446
for fragment in context.table:
4547
expected = fragment["Fragments in LLM response"]
4648
assert (

tests/e2e/gen_scenario_list.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
import os
2323

24+
# repository URL
25+
REPO_URL = "https://github.com/lightspeed-core/lightspeed-stack/"
26+
2427
# URL prefix to create links to feature files
25-
FEATURES_URL_PREFIX = "https://github.com/lightspeed-core/lightspeed-stack/blob/main/tests/e2e/features" # noqa E501
28+
FEATURES_URL_PREFIX = f"{REPO_URL}blob/main/tests/e2e/features"
2629

2730
# list of prefixes for scenarios or scenario outlines
2831
PREFIXES = ("Scenario: ", "Scenario Outline: ")
@@ -40,16 +43,18 @@
4043
print()
4144

4245
# generage list of scenarios
43-
directory = FEATURE_DIRECTORY
46+
4447
# files within one subdirectory needs to be sorted so the
4548
# resulting scenario list will have stable structure across versions
46-
files = sorted(os.listdir(directory))
49+
files = sorted(os.listdir(FEATURE_DIRECTORY))
4750
for filename in files:
4851
# grep all .feature files
4952
if filename.endswith(".feature"):
5053
# feature file header
51-
print("## [`{}`]({}/{})\n".format(filename, FEATURES_URL_PREFIX, filename))
52-
with open(os.path.join(directory, filename), "r") as fin:
54+
print(f"## [`{filename}`]({FEATURES_URL_PREFIX}/{filename})\n")
55+
with open(
56+
os.path.join(FEATURE_DIRECTORY, filename), "r", encoding="utf-8"
57+
) as fin:
5358
for line in fin.readlines():
5459
line = line.strip()
5560
# process all scenarios and scenario outlines

0 commit comments

Comments
 (0)