Skip to content

Commit 6863925

Browse files
Merge pull request #2524 from tisnik/fix-wrong-return-value
Fix wrong return value, added missing assertions, provide correct values for tested functions
2 parents 8f1554b + d4a4de6 commit 6863925

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

tests/config/test_app_endpoints.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ ols_config:
1818
logging_level: INFO
1919
default_provider: bam
2020
default_model: model-name
21+
query_filters:
22+
[]
2123
dev_config:
2224
disable_auth: true
2325
disable_tls: true

tests/e2e/utils/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def list_path(pod_name: str, path: str) -> list[str]:
222222
"No such file or directory" in e.stdout
223223
or "No such file or directory" in e.stderr
224224
):
225-
return None
225+
return []
226226
raise Exception("Error listing pod path") from e
227227

228228

tests/unit/app/endpoints/test_ols.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def test_retrieve_conversation_id_existing_id():
6666
@pytest.mark.usefixtures("_load_config")
6767
def test_retrieve_previous_input_no_previous_history():
6868
"""Check how function to retrieve previous input handle empty history."""
69-
llm_request = LLMRequest(query="Tell me about Kubernetes", conversation_id=None)
69+
llm_request = LLMRequest(query="Tell me about Kubernetes", conversation_id="")
70+
assert llm_request.conversation_id is not None
7071
llm_input = ols.retrieve_previous_input(
7172
constants.DEFAULT_USER_UID, llm_request.conversation_id
7273
)
@@ -80,6 +81,7 @@ def test_retrieve_previous_input_empty_user_id():
8081
llm_request = LLMRequest(
8182
query="Tell me about Kubernetes", conversation_id=conversation_id
8283
)
84+
assert llm_request.conversation_id is not None
8385
# cache must check if user ID is correct
8486
with pytest.raises(HTTPException, match="Invalid user ID"):
8587
ols.retrieve_previous_input("", llm_request.conversation_id)
@@ -94,6 +96,7 @@ def test_retrieve_previous_input_improper_user_id():
9496
llm_request = LLMRequest(
9597
query="Tell me about Kubernetes", conversation_id=conversation_id
9698
)
99+
assert llm_request.conversation_id is not None
97100
# cache must check if user ID is correct
98101
with pytest.raises(HTTPException, match="Invalid user ID improper_user_id"):
99102
ols.retrieve_previous_input("improper_user_id", llm_request.conversation_id)
@@ -108,6 +111,7 @@ def test_retrieve_previous_input_for_previous_history():
108111
llm_request = LLMRequest(
109112
query="Tell me about Kubernetes", conversation_id=conversation_id
110113
)
114+
assert llm_request.conversation_id is not None
111115
previous_input = ols.retrieve_previous_input(
112116
constants.DEFAULT_USER_UID, llm_request.conversation_id
113117
)
@@ -150,11 +154,11 @@ def test_retrieve_attachments_on_proper_input():
150154
query="Tell me about Kubernetes",
151155
conversation_id=conversation_id,
152156
attachments=[
153-
{
154-
"attachment_type": "log",
155-
"content_type": "text/plain",
156-
"content": "this is attachment",
157-
},
157+
Attachment(
158+
attachment_type="log",
159+
content_type="text/plain",
160+
content="this is attachment",
161+
),
158162
],
159163
)
160164
attachments = ols.retrieve_attachments(llm_request)
@@ -176,11 +180,11 @@ def test_retrieve_attachments_on_improper_attachment_type():
176180
query="Tell me about Kubernetes",
177181
conversation_id=conversation_id,
178182
attachments=[
179-
{
180-
"attachment_type": "not-correct-one",
181-
"content_type": "text/plain",
182-
"content": "this is attachment",
183-
},
183+
Attachment(
184+
attachment_type="not-correct-one",
185+
content_type="text/plain",
186+
content="this is attachment",
187+
),
184188
],
185189
)
186190
with pytest.raises(
@@ -197,11 +201,11 @@ def test_retrieve_attachments_on_improper_content_type():
197201
query="Tell me about Kubernetes",
198202
conversation_id=conversation_id,
199203
attachments=[
200-
{
201-
"attachment_type": "log",
202-
"content_type": "not/known",
203-
"content": "this is attachment",
204-
},
204+
Attachment(
205+
attachment_type="log",
206+
content_type="not/known",
207+
content="this is attachment",
208+
),
205209
],
206210
)
207211
with pytest.raises(
@@ -226,7 +230,7 @@ def test_store_conversation_history():
226230
llm_request,
227231
response,
228232
[],
229-
[],
233+
{},
230234
)
231235

232236
expected_history = CacheEntry(query=HumanMessage(query))
@@ -269,11 +273,11 @@ def test_store_conversation_history_empty_user_id():
269273
llm_request = LLMRequest(query="Tell me about Kubernetes")
270274
with pytest.raises(HTTPException, match="Invalid user ID"):
271275
ols.store_conversation_history(
272-
user_id, conversation_id, llm_request, "", [], []
276+
user_id, conversation_id, llm_request, "", [], {}
273277
)
274278
with pytest.raises(HTTPException, match="Invalid user ID"):
275279
ols.store_conversation_history(
276-
user_id, conversation_id, llm_request, None, [], []
280+
user_id, conversation_id, llm_request, None, [], {}
277281
)
278282

279283

@@ -285,7 +289,7 @@ def test_store_conversation_history_improper_user_id():
285289
llm_request = LLMRequest(query="Tell me about Kubernetes")
286290
with pytest.raises(HTTPException, match="Invalid user ID"):
287291
ols.store_conversation_history(
288-
user_id, conversation_id, llm_request, "", [], []
292+
user_id, conversation_id, llm_request, "", [], {}
289293
)
290294

291295

@@ -296,7 +300,7 @@ def test_store_conversation_history_improper_conversation_id():
296300
llm_request = LLMRequest(query="Tell me about Kubernetes")
297301
with pytest.raises(HTTPException, match="Invalid conversation ID"):
298302
ols.store_conversation_history(
299-
constants.DEFAULT_USER_UID, conversation_id, llm_request, "", [], []
303+
constants.DEFAULT_USER_UID, conversation_id, llm_request, "", [], {}
300304
)
301305

302306

@@ -465,6 +469,7 @@ def test_query_filter_with_one_redact_filter():
465469
llm_request = LLMRequest(query=query, conversation_id=conversation_id)
466470

467471
# use one custom filter
472+
assert config.ols_config.query_filters is not None
468473
q = Redactor(config.ols_config.query_filters)
469474
q.regex_filters = [
470475
RegexFilter(
@@ -488,6 +493,7 @@ def test_query_filter_with_two_redact_filters():
488493
llm_request = LLMRequest(query=query, conversation_id=conversation_id)
489494

490495
# use two custom filters
496+
assert config.ols_config.query_filters is not None
491497
q = Redactor(config.ols_config.query_filters)
492498
q.regex_filters = [
493499
RegexFilter(
@@ -562,6 +568,7 @@ def test_attachments_redact_with_one_filter_defined():
562568
]
563569

564570
# use two custom filters
571+
assert config.ols_config.query_filters is not None
565572
q = Redactor(config.ols_config.query_filters)
566573
q.regex_filters = [
567574
RegexFilter(
@@ -608,6 +615,7 @@ def test_attachments_redact_with_two_filters_defined():
608615
]
609616

610617
# use two custom filters
618+
assert config.ols_config.query_filters is not None
611619
q = Redactor(config.ols_config.query_filters)
612620
q.regex_filters = [
613621
RegexFilter(
@@ -1106,6 +1114,8 @@ def test_consume_tokens_with_existing_quota_limiter():
11061114
"""Test the function consume_tokens for configured quota limiter."""
11071115

11081116
class MockQuotaLimiter:
1117+
"""Mocked quota limiter."""
1118+
11091119
def consume_tokens(self, input_tokens=0, output_tokens=0, subject_id=""):
11101120
self._input_tokens = input_tokens
11111121
self._output_tokens = output_tokens

0 commit comments

Comments
 (0)