|
6 | 6 |
|
7 | 7 | from timdex_dataset_api import TIMDEXDatasetMetadata |
8 | 8 |
|
| 9 | +ORDERED_METADATA_COLUMN_NAMES = [ |
| 10 | + "timdex_record_id", |
| 11 | + "source", |
| 12 | + "run_date", |
| 13 | + "run_type", |
| 14 | + "action", |
| 15 | + "run_id", |
| 16 | + "run_record_offset", |
| 17 | + "run_timestamp", |
| 18 | + "filename", |
| 19 | +] |
| 20 | + |
9 | 21 |
|
10 | 22 | def test_tdm_init_no_metadata_file_warning_success(caplog, timdex_dataset_with_runs): |
11 | 23 | TIMDEXDatasetMetadata(timdex_dataset_with_runs.location) |
@@ -264,26 +276,44 @@ def test_tdm_current_records_most_recent_version(timdex_metadata_with_deltas): |
264 | 276 | assert current_version.iloc[0]["run_id"] == most_recent.iloc[0]["run_id"] |
265 | 277 |
|
266 | 278 |
|
267 | | -def test_tdm_merge_append_deltas(timdex_metadata_with_deltas): |
268 | | - # get record count from static db |
269 | | - metadata_db_current_count = timdex_metadata_with_deltas.conn.query( |
| 279 | +def test_tdm_merge_append_deltas_static_counts_match_records_count_before_merge( |
| 280 | + timdex_metadata_with_deltas, timdex_metadata_merged_deltas |
| 281 | +): |
| 282 | + static_count_merged_deltas = timdex_metadata_merged_deltas.conn.query( |
270 | 283 | """select count(*) as count from static_db.records;""" |
271 | 284 | ).fetchone()[0] |
272 | | - total_count = timdex_metadata_with_deltas.records_count |
| 285 | + assert static_count_merged_deltas == timdex_metadata_with_deltas.records_count |
273 | 286 |
|
274 | | - # merge append deltas into static db file |
275 | | - timdex_metadata_with_deltas.merge_append_deltas() |
276 | | - timdex_metadata_with_deltas.refresh() |
277 | 287 |
|
278 | | - # get updated record count from static db |
279 | | - metadata_db_updated_count = timdex_metadata_with_deltas.conn.query( |
280 | | - """select count(*) as count from static_db.records;""" |
281 | | - ).fetchone()[0] |
| 288 | +def test_tdm_merge_append_deltas_adds_records_to_static_db( |
| 289 | + timdex_metadata_with_deltas, timdex_metadata_merged_deltas |
| 290 | +): |
| 291 | + append_deltas = timdex_metadata_with_deltas.conn.query( |
| 292 | + f""" |
| 293 | + select |
| 294 | + {','.join(ORDERED_METADATA_COLUMN_NAMES)} |
| 295 | + from metadata.append_deltas |
| 296 | + """ |
| 297 | + ).to_df() |
| 298 | + |
| 299 | + merged_static_db = timdex_metadata_merged_deltas.conn.query( |
| 300 | + f""" |
| 301 | + select |
| 302 | + {','.join(ORDERED_METADATA_COLUMN_NAMES)} |
| 303 | + from static_db.records |
| 304 | + """ |
| 305 | + ).to_df() |
| 306 | + |
| 307 | + assert set(map(tuple, append_deltas.to_numpy())).issubset( |
| 308 | + set(map(tuple, merged_static_db.to_numpy())) |
| 309 | + ) |
| 310 | + |
282 | 311 |
|
283 | | - # verify the addition of new records |
284 | | - assert metadata_db_current_count < metadata_db_updated_count |
285 | | - assert metadata_db_updated_count == total_count |
| 312 | +def test_tdm_merge_append_deltas_deletes_append_deltas( |
| 313 | + timdex_metadata_with_deltas, timdex_metadata_merged_deltas |
| 314 | +): |
| 315 | + assert timdex_metadata_with_deltas.append_deltas_count != 0 |
| 316 | + assert os.listdir(timdex_metadata_with_deltas.append_deltas_path) |
286 | 317 |
|
287 | | - # verify append deltas are deleted |
288 | | - assert timdex_metadata_with_deltas.append_deltas_count == 0 |
289 | | - assert os.listdir(timdex_metadata_with_deltas.append_deltas_path) == [] |
| 318 | + assert timdex_metadata_merged_deltas.append_deltas_count == 0 |
| 319 | + assert not os.listdir(timdex_metadata_merged_deltas.append_deltas_path) |
0 commit comments