|
10 | 10 | import os |
11 | 11 |
|
12 | 12 | from slips_files.core.flows.zeek import Conn |
| 13 | +from slips_files.core.database.database_manager import DBManager |
13 | 14 | from slips_files.core.database.redis_db.database import RedisDB |
14 | 15 | from tests.module_factory import ModuleFactory |
15 | 16 |
|
@@ -163,44 +164,33 @@ def test_setup_config_file_uses_isolated_path_and_preserves_save( |
163 | 164 | ) |
164 | 165 |
|
165 | 166 | monkeypatch.setattr(RedisDB, "_conf_file_template", str(template)) |
166 | | - monkeypatch.setattr(RedisDB, "output_dir", tmp_path) |
167 | | - monkeypatch.setattr(RedisDB, "redis_port", 6379) |
168 | | - monkeypatch.setattr(RedisDB, "args", Mock(save=False)) |
| 167 | + monkeypatch.setattr(RedisDB, "output_dir", tmp_path, raising=False) |
| 168 | + monkeypatch.setattr(RedisDB, "redis_port", 6379, raising=False) |
| 169 | + monkeypatch.setattr(RedisDB, "args", Mock(save=False), raising=False) |
169 | 170 |
|
170 | 171 | RedisDB._setup_config_file() |
171 | 172 |
|
172 | 173 | expected_conf = ( |
173 | | - tmp_path / f"redis-server-port-{RedisDB.redis_port}-{os.getpid()}.conf" |
| 174 | + tmp_path / "redis" / f"redis-server-port-{RedisDB.redis_port}.conf" |
174 | 175 | ) |
175 | 176 | assert RedisDB._conf_file == str(expected_conf) |
176 | 177 |
|
177 | 178 | conf_contents = expected_conf.read_text(encoding="utf-8").splitlines() |
178 | 179 | assert 'save ""' in conf_contents |
179 | 180 | assert ( |
180 | | - f"logfile {tmp_path / f'redis-server-port-{RedisDB.redis_port}.log'}" |
| 181 | + f"logfile {tmp_path / 'redis' / f'redis-server-port-{RedisDB.redis_port}.log'}" |
181 | 182 | in conf_contents |
182 | 183 | ) |
183 | 184 |
|
184 | 185 |
|
185 | | -def test_get_permanent_database_path_uses_configured_dir( |
186 | | - tmp_path, monkeypatch |
187 | | -): |
188 | | - db = ModuleFactory().create_db_manager_obj(6379) |
189 | | - monkeypatch.chdir(tmp_path) |
190 | | - db.conf.permanent_dir = Mock(return_value="persistent_state") |
191 | | - |
192 | | - path = db.get_permanent_database_path("shared.sqlite") |
193 | | - |
194 | | - assert path == os.path.join( |
195 | | - "persistent_state", "databases", "shared.sqlite" |
196 | | - ) |
197 | | - assert os.path.isdir(os.path.join("persistent_state", "databases")) |
198 | | - |
199 | | - |
200 | 186 | def test_init_p2p_trust_db_uses_permanent_dir(tmp_path, monkeypatch): |
201 | 187 | db = ModuleFactory().create_db_manager_obj(6379) |
202 | 188 | monkeypatch.chdir(tmp_path) |
203 | | - db.conf.permanent_dir = Mock(return_value="persistent_state") |
| 189 | + db.init_p2p_trust_db = DBManager.init_p2p_trust_db.__get__(db, DBManager) |
| 190 | + monkeypatch.setattr( |
| 191 | + "slips_files.core.database.database_manager.get_this_filepath_inside_permanent_dir", |
| 192 | + lambda filename: os.path.join("persistent_state", filename), |
| 193 | + ) |
204 | 194 |
|
205 | 195 | db_path = db.init_p2p_trust_db() |
206 | 196 |
|
|
0 commit comments