Skip to content

Commit fe6b676

Browse files
authored
Merge pull request lightspeed-core#511 from tisnik/lcore-636-split-config-customization-unit-tests
LCORE-636: split config Customization unit tests
2 parents 373b707 + aca5d0f commit fe6b676

2 files changed

Lines changed: 64 additions & 58 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""Unit tests for Customization model."""
2+
3+
import pytest
4+
5+
from pydantic import ValidationError
6+
7+
from models.config import Customization
8+
9+
10+
def test_service_customization(subtests) -> None:
11+
"""Check the service customization class."""
12+
with subtests.test(msg="System prompt is enabled"):
13+
c = Customization()
14+
assert c is not None
15+
assert c.disable_query_system_prompt is False
16+
assert c.system_prompt_path is None
17+
assert c.system_prompt is None
18+
19+
with subtests.test(msg="System prompt is disabled"):
20+
c = Customization(disable_query_system_prompt=True)
21+
assert c is not None
22+
assert c.disable_query_system_prompt is True
23+
assert c.system_prompt_path is None
24+
assert c.system_prompt is None
25+
26+
with subtests.test(
27+
msg="Disabled overrides provided path, but the prompt is still loaded"
28+
):
29+
c = Customization(
30+
disable_query_system_prompt=True,
31+
system_prompt_path="tests/configuration/system_prompt.txt",
32+
)
33+
assert c.system_prompt is not None
34+
# check that the system prompt has been loaded from the provided file
35+
assert c.system_prompt == "This is system prompt."
36+
# but it is still disabled
37+
assert c.disable_query_system_prompt is True
38+
39+
40+
def test_service_customization_wrong_system_prompt_path() -> None:
41+
"""Check the service customization class."""
42+
with pytest.raises(ValidationError, match="Path does not point to a file"):
43+
_ = Customization(system_prompt_path="/path/does/not/exists")
44+
45+
46+
def test_service_customization_correct_system_prompt_path(subtests) -> None:
47+
"""Check the service customization class."""
48+
with subtests.test(msg="One line system prompt"):
49+
# pass a file containing system prompt
50+
c = Customization(system_prompt_path="tests/configuration/system_prompt.txt")
51+
assert c is not None
52+
# check that the system prompt has been loaded from the provided file
53+
assert c.system_prompt == "This is system prompt."
54+
55+
with subtests.test(msg="Multi line system prompt"):
56+
# pass a file containing system prompt
57+
c = Customization(
58+
system_prompt_path="tests/configuration/multiline_system_prompt.txt"
59+
)
60+
assert c is not None
61+
# check that the system prompt has been loaded from the provided file
62+
assert "You are OpenShift Lightspeed" in c.system_prompt
63+
assert "Here are your instructions" in c.system_prompt
64+
assert "Here are some basic facts about OpenShift" in c.system_prompt

tests/unit/models/test_config.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
PostgreSQLDatabaseConfiguration,
3636
SQLiteDatabaseConfiguration,
3737
DatabaseConfiguration,
38-
Customization,
3938
)
4039

4140

@@ -1165,60 +1164,3 @@ def test_jwt_role_rule_invalid_regexp() -> None:
11651164
roles=["admin", "user"],
11661165
operator=JsonPathOperator.MATCH,
11671166
)
1168-
1169-
1170-
def test_service_customization(subtests) -> None:
1171-
"""Check the service customization class."""
1172-
with subtests.test(msg="System prompt is enabled"):
1173-
c = Customization()
1174-
assert c is not None
1175-
assert c.disable_query_system_prompt is False
1176-
assert c.system_prompt_path is None
1177-
assert c.system_prompt is None
1178-
1179-
with subtests.test(msg="System prompt is disabled"):
1180-
c = Customization(disable_query_system_prompt=True)
1181-
assert c is not None
1182-
assert c.disable_query_system_prompt is True
1183-
assert c.system_prompt_path is None
1184-
assert c.system_prompt is None
1185-
1186-
with subtests.test(
1187-
msg="Disabled overrides provided path, but the prompt is still loaded"
1188-
):
1189-
c = Customization(
1190-
disable_query_system_prompt=True,
1191-
system_prompt_path="tests/configuration/system_prompt.txt",
1192-
)
1193-
assert c.system_prompt is not None
1194-
# check that the system prompt has been loaded from the provided file
1195-
assert c.system_prompt == "This is system prompt."
1196-
# but it is still disabled
1197-
assert c.disable_query_system_prompt is True
1198-
1199-
1200-
def test_service_customization_wrong_system_prompt_path() -> None:
1201-
"""Check the service customization class."""
1202-
with pytest.raises(ValidationError, match="Path does not point to a file"):
1203-
_ = Customization(system_prompt_path="/path/does/not/exists")
1204-
1205-
1206-
def test_service_customization_correct_system_prompt_path(subtests) -> None:
1207-
"""Check the service customization class."""
1208-
with subtests.test(msg="One line system prompt"):
1209-
# pass a file containing system prompt
1210-
c = Customization(system_prompt_path="tests/configuration/system_prompt.txt")
1211-
assert c is not None
1212-
# check that the system prompt has been loaded from the provided file
1213-
assert c.system_prompt == "This is system prompt."
1214-
1215-
with subtests.test(msg="Multi line system prompt"):
1216-
# pass a file containing system prompt
1217-
c = Customization(
1218-
system_prompt_path="tests/configuration/multiline_system_prompt.txt"
1219-
)
1220-
assert c is not None
1221-
# check that the system prompt has been loaded from the provided file
1222-
assert "You are OpenShift Lightspeed" in c.system_prompt
1223-
assert "Here are your instructions" in c.system_prompt
1224-
assert "Here are some basic facts about OpenShift" in c.system_prompt

0 commit comments

Comments
 (0)