2025-01-13 16:58:10 +00:00
|
|
|
|
2025-01-23 09:16:42 +00:00
|
|
|
from auto_archiver.modules.csv_db import CSVDb
|
2025-01-13 16:58:10 +00:00
|
|
|
from auto_archiver.core import Metadata
|
|
|
|
|
|
|
|
|
2025-01-28 13:40:12 +00:00
|
|
|
def test_store_item(tmp_path, setup_module):
|
2025-01-14 15:28:39 +00:00
|
|
|
"""Tests storing an item in the CSV database"""
|
2025-01-13 16:58:10 +00:00
|
|
|
|
2025-01-14 15:28:39 +00:00
|
|
|
temp_db = tmp_path / "temp_db.csv"
|
2025-01-28 13:40:12 +00:00
|
|
|
db = setup_module(CSVDb, {"csv_file": temp_db.as_posix()})
|
2025-01-13 16:58:10 +00:00
|
|
|
|
2025-01-14 15:28:39 +00:00
|
|
|
item = Metadata().set_url("http://example.com").set_title("Example").set_content("Example content").success("my-archiver")
|
2025-01-13 16:58:10 +00:00
|
|
|
|
2025-01-14 15:28:39 +00:00
|
|
|
db.done(item)
|
2025-01-13 16:58:10 +00:00
|
|
|
|
2025-01-14 15:28:39 +00:00
|
|
|
with open(temp_db, "r", encoding="utf-8") as f:
|
|
|
|
assert f.read().strip() == f"status,metadata,media\nmy-archiver: success,\"{{'_processed_at': {repr(item.get('_processed_at'))}, 'url': 'http://example.com', 'title': 'Example', 'content': 'Example content'}}\",[]"
|
2025-01-13 16:58:10 +00:00
|
|
|
|
2025-01-14 15:28:39 +00:00
|
|
|
# TODO: csv db doesn't have a fetch method - need to add it (?)
|
|
|
|
# assert db.fetch(item) == item
|