Skip to content

Commit d7ce460

Browse files
committed
Refactoring: ConversationCache -> ConversationCacheConfiguration
1 parent 1f2311a commit d7ce460

4 files changed

Lines changed: 32 additions & 26 deletions

File tree

src/configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
AuthenticationConfiguration,
2020
InferenceConfiguration,
2121
DatabaseConfiguration,
22-
ConversationCache,
22+
ConversationCacheConfiguration,
2323
)
2424

2525

@@ -126,7 +126,7 @@ def inference(self) -> InferenceConfiguration:
126126
return self._configuration.inference
127127

128128
@property
129-
def conversation_cache(self) -> ConversationCache:
129+
def conversation_cache_configuration(self) -> ConversationCacheConfiguration:
130130
"""Return conversation cache configuration."""
131131
if self._configuration is None:
132132
raise LogicError("logic error: configuration is not loaded")

src/models/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def check_default_model_and_provider(self) -> Self:
486486
return self
487487

488488

489-
class ConversationCache(ConfigurationBase):
489+
class ConversationCacheConfiguration(ConfigurationBase):
490490
"""Conversation cache configuration."""
491491

492492
type: Literal["memory", "sqlite", "postgres"] | None = None
@@ -542,7 +542,9 @@ class Configuration(ConfigurationBase):
542542
authorization: Optional[AuthorizationConfiguration] = None
543543
customization: Optional[Customization] = None
544544
inference: InferenceConfiguration = Field(default_factory=InferenceConfiguration)
545-
conversation_cache: ConversationCache = Field(default_factory=ConversationCache)
545+
conversation_cache: ConversationCacheConfiguration = Field(
546+
default_factory=ConversationCacheConfiguration
547+
)
546548

547549
def dump(self, filename: str = "configuration.json") -> None:
548550
"""Dump actual configuration into JSON file."""

tests/unit/models/config/test_conversation_cache.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Unit tests for ConversationCache model."""
1+
"""Unit tests for ConversationCacheConfiguration model."""
22

33
from pathlib import Path
44

@@ -8,7 +8,7 @@
88

99
import constants
1010
from models.config import (
11-
ConversationCache,
11+
ConversationCacheConfiguration,
1212
InMemoryCacheConfig,
1313
SQLiteDatabaseConfiguration,
1414
PostgreSQLDatabaseConfiguration,
@@ -17,7 +17,7 @@
1717

1818
def test_conversation_cache_no_type_specified() -> None:
1919
"""Check the test for type as optional attribute."""
20-
c = ConversationCache()
20+
c = ConversationCacheConfiguration()
2121
assert c.type is None
2222

2323

@@ -26,7 +26,7 @@ def test_conversation_cache_unknown_type() -> None:
2626
with pytest.raises(
2727
ValidationError, match="Input should be 'memory', 'sqlite' or 'postgres'"
2828
):
29-
_ = ConversationCache(type="foo")
29+
_ = ConversationCacheConfiguration(type="foo")
3030

3131

3232
def test_conversation_cache_correct_type_but_not_configured(subtests) -> None:
@@ -35,19 +35,19 @@ def test_conversation_cache_correct_type_but_not_configured(subtests) -> None:
3535
with pytest.raises(
3636
ValidationError, match="Memory cache is selected, but not configured"
3737
):
38-
_ = ConversationCache(type=constants.CACHE_TYPE_MEMORY)
38+
_ = ConversationCacheConfiguration(type=constants.CACHE_TYPE_MEMORY)
3939

4040
with subtests.test(msg="SQLite cache"):
4141
with pytest.raises(
4242
ValidationError, match="SQLite cache is selected, but not configured"
4343
):
44-
_ = ConversationCache(type=constants.CACHE_TYPE_SQLITE)
44+
_ = ConversationCacheConfiguration(type=constants.CACHE_TYPE_SQLITE)
4545

4646
with subtests.test(msg="SQLite cache"):
4747
with pytest.raises(
4848
ValidationError, match="PostgreSQL cache is selected, but not configured"
4949
):
50-
_ = ConversationCache(type=constants.CACHE_TYPE_POSTGRES)
50+
_ = ConversationCacheConfiguration(type=constants.CACHE_TYPE_POSTGRES)
5151

5252

5353
def test_conversation_cache_no_type_but_configured(subtests) -> None:
@@ -56,11 +56,15 @@ def test_conversation_cache_no_type_but_configured(subtests) -> None:
5656

5757
with subtests.test(msg="Memory cache"):
5858
with pytest.raises(ValidationError, match=m):
59-
_ = ConversationCache(memory=InMemoryCacheConfig(max_entries=100))
59+
_ = ConversationCacheConfiguration(
60+
memory=InMemoryCacheConfig(max_entries=100)
61+
)
6062

6163
with subtests.test(msg="SQLite cache"):
6264
with pytest.raises(ValidationError, match=m):
63-
_ = ConversationCache(sqlite=SQLiteDatabaseConfiguration(db_path="path"))
65+
_ = ConversationCacheConfiguration(
66+
sqlite=SQLiteDatabaseConfiguration(db_path="path")
67+
)
6468

6569
with subtests.test(msg="PostgreSQL cache"):
6670
d = PostgreSQLDatabaseConfiguration(
@@ -71,7 +75,7 @@ def test_conversation_cache_no_type_but_configured(subtests) -> None:
7175
ca_cert_path=Path("tests/configuration/server.crt"),
7276
)
7377
with pytest.raises(ValidationError, match=m):
74-
_ = ConversationCache(postgres=d)
78+
_ = ConversationCacheConfiguration(postgres=d)
7579

7680

7781
def test_conversation_cache_multiple_configurations(subtests) -> None:
@@ -88,7 +92,7 @@ def test_conversation_cache_multiple_configurations(subtests) -> None:
8892
with pytest.raises(
8993
ValidationError, match="Only memory cache config must be provided"
9094
):
91-
_ = ConversationCache(
95+
_ = ConversationCacheConfiguration(
9296
type=constants.CACHE_TYPE_MEMORY,
9397
memory=InMemoryCacheConfig(max_entries=100),
9498
sqlite=SQLiteDatabaseConfiguration(db_path="path"),
@@ -99,7 +103,7 @@ def test_conversation_cache_multiple_configurations(subtests) -> None:
99103
with pytest.raises(
100104
ValidationError, match="Only SQLite cache config must be provided"
101105
):
102-
_ = ConversationCache(
106+
_ = ConversationCacheConfiguration(
103107
type=constants.CACHE_TYPE_SQLITE,
104108
memory=InMemoryCacheConfig(max_entries=100),
105109
sqlite=SQLiteDatabaseConfiguration(db_path="path"),
@@ -110,7 +114,7 @@ def test_conversation_cache_multiple_configurations(subtests) -> None:
110114
with pytest.raises(
111115
ValidationError, match="Only PostgreSQL cache config must be provided"
112116
):
113-
_ = ConversationCache(
117+
_ = ConversationCacheConfiguration(
114118
type=constants.CACHE_TYPE_POSTGRES,
115119
memory=InMemoryCacheConfig(max_entries=100),
116120
sqlite=SQLiteDatabaseConfiguration(db_path="path"),
@@ -120,7 +124,7 @@ def test_conversation_cache_multiple_configurations(subtests) -> None:
120124

121125
def test_conversation_type_memory() -> None:
122126
"""Test the memory conversation cache configuration."""
123-
c = ConversationCache(
127+
c = ConversationCacheConfiguration(
124128
type=constants.CACHE_TYPE_MEMORY, memory=InMemoryCacheConfig(max_entries=100)
125129
)
126130
assert c.type == constants.CACHE_TYPE_MEMORY
@@ -133,21 +137,21 @@ def test_conversation_type_memory() -> None:
133137
def test_conversation_type_memory_wrong_config() -> None:
134138
"""Test the memory conversation cache configuration."""
135139
with pytest.raises(ValidationError, match="Field required"):
136-
_ = ConversationCache(
140+
_ = ConversationCacheConfiguration(
137141
type=constants.CACHE_TYPE_MEMORY,
138142
memory=InMemoryCacheConfig(),
139143
)
140144

141145
with pytest.raises(ValidationError, match="Input should be greater than 0"):
142-
_ = ConversationCache(
146+
_ = ConversationCacheConfiguration(
143147
type=constants.CACHE_TYPE_MEMORY,
144148
memory=InMemoryCacheConfig(max_entries=-100),
145149
)
146150

147151

148152
def test_conversation_type_sqlite() -> None:
149153
"""Test the SQLite conversation cache configuration."""
150-
c = ConversationCache(
154+
c = ConversationCacheConfiguration(
151155
type=constants.CACHE_TYPE_SQLITE,
152156
sqlite=SQLiteDatabaseConfiguration(db_path="path"),
153157
)
@@ -161,7 +165,7 @@ def test_conversation_type_sqlite() -> None:
161165
def test_conversation_type_sqlite_wrong_config() -> None:
162166
"""Test the SQLite conversation cache configuration."""
163167
with pytest.raises(ValidationError, match="Field required"):
164-
_ = ConversationCache(
168+
_ = ConversationCacheConfiguration(
165169
type=constants.CACHE_TYPE_SQLITE,
166170
memory=SQLiteDatabaseConfiguration(),
167171
)
@@ -177,7 +181,7 @@ def test_conversation_type_postgres() -> None:
177181
ca_cert_path=Path("tests/configuration/server.crt"),
178182
)
179183

180-
c = ConversationCache(
184+
c = ConversationCacheConfiguration(
181185
type=constants.CACHE_TYPE_POSTGRES,
182186
postgres=d,
183187
)
@@ -194,7 +198,7 @@ def test_conversation_type_postgres() -> None:
194198
def test_conversation_type_postgres_wrong_config() -> None:
195199
"""Test the SQLite conversation cache configuration."""
196200
with pytest.raises(ValidationError, match="Field required"):
197-
_ = ConversationCache(
201+
_ = ConversationCacheConfiguration(
198202
type=constants.CACHE_TYPE_POSTGRES,
199203
postgres=PostgreSQLDatabaseConfiguration(),
200204
)

tests/unit/test_configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_default_configuration() -> None:
7171

7272
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
7373
# try to read property
74-
_ = cfg.conversation_cache # pylint: disable=pointless-statement
74+
_ = cfg.conversation_cache_configuration # pylint: disable=pointless-statement
7575

7676

7777
def test_configuration_is_singleton() -> None:
@@ -149,7 +149,7 @@ def test_init_from_dict() -> None:
149149
assert cfg.inference is not None
150150

151151
# check conversation cache
152-
assert cfg.conversation_cache is not None
152+
assert cfg.conversation_cache_configuration is not None
153153

154154

155155
def test_init_from_dict_with_mcp_servers() -> None:

0 commit comments

Comments
 (0)