You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""Unit tests for file_store module."""
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def tmp_data_root(tmp_path, monkeypatch):
|
|
"""Redirect data root to tmp for isolation."""
|
|
from libs.common import config
|
|
config.get_settings.cache_clear()
|
|
monkeypatch.setenv("DATA_ROOT", str(tmp_path))
|
|
yield tmp_path
|
|
config.get_settings.cache_clear()
|
|
|
|
|
|
def test_write_and_read_exhibit(tmp_data_root):
|
|
from libs.common.file_store import read_exhibit, write_exhibit
|
|
content = "This is exhibit content."
|
|
checksum = write_exhibit("ACC123", "EX-99.1", content)
|
|
assert len(checksum) == 64
|
|
result = read_exhibit("ACC123", "EX-99.1")
|
|
assert result == content
|
|
|
|
|
|
def test_exists_exhibit(tmp_data_root):
|
|
from libs.common.file_store import exists_exhibit, write_exhibit
|
|
assert not exists_exhibit("ACC999", "EX-99.1")
|
|
write_exhibit("ACC999", "EX-99.1", "content")
|
|
assert exists_exhibit("ACC999", "EX-99.1")
|
|
|
|
|
|
def test_checksum_deterministic(tmp_data_root):
|
|
from libs.common.file_store import get_checksum, write_exhibit
|
|
write_exhibit("ACC456", "EX-99.1", "hello world")
|
|
c = get_checksum("ACC456", "EX-99.1")
|
|
assert c is not None
|
|
# Second call returns same
|
|
assert get_checksum("ACC456", "EX-99.1") == c
|
|
|
|
|
|
def test_exhibit_path_safe_chars(tmp_data_root):
|
|
from libs.common.file_store import exhibit_path
|
|
p = exhibit_path("ACC789", "EX-99.1")
|
|
assert "EX-99.1.txt" in str(p)
|