1- """Unit tests for ConversationCache model."""
1+ """Unit tests for ConversationCacheConfiguration model."""
22
33from pathlib import Path
44
88
99import constants
1010from models .config import (
11- ConversationCache ,
11+ ConversationCacheConfiguration ,
1212 InMemoryCacheConfig ,
1313 SQLiteDatabaseConfiguration ,
1414 PostgreSQLDatabaseConfiguration ,
1717
1818def 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
3232def 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
5353def 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
7781def 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
121125def 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:
133137def 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
148152def 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:
161165def 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:
194198def 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 )
0 commit comments