Fix BatchCredentials tests: add required reference_photo

- Add sample_reference_photo fixture for test data
- Update sample_credentials fixture to include reference_photo
- Update all BatchCredentials test dicts to include reference_photo
- Add 'phrase' as legacy key in BatchCredentials.from_dict()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Aaron D. Lee
2026-01-02 17:28:14 -05:00
parent 6b21190f97
commit 9c45e0d0f8
2 changed files with 32 additions and 11 deletions

View File

@@ -105,10 +105,10 @@ class BatchCredentials:
""" """
Create BatchCredentials from a dictionary. Create BatchCredentials from a dictionary.
Handles both v3.2.0 format (passphrase) and legacy format (day_phrase). Handles both v3.2.0 format (passphrase) and legacy formats (day_phrase, phrase).
""" """
# Handle legacy 'day_phrase' key # Handle legacy 'day_phrase' and 'phrase' keys
passphrase = data.get('passphrase') or data.get('day_phrase', '') passphrase = data.get('passphrase') or data.get('day_phrase') or data.get('phrase', '')
return cls( return cls(
reference_photo=data['reference_photo'], reference_photo=data['reference_photo'],

View File

@@ -49,9 +49,23 @@ def sample_images(temp_dir):
@pytest.fixture @pytest.fixture
def sample_credentials(): def sample_reference_photo():
"""Create a sample reference photo as bytes."""
from io import BytesIO
from PIL import Image
img = Image.new('RGB', (100, 100), color=(128, 128, 128))
buf = BytesIO()
img.save(buf, 'PNG')
return buf.getvalue()
@pytest.fixture
def sample_credentials(sample_reference_photo):
"""Create sample v3.2.0 credentials dict.""" """Create sample v3.2.0 credentials dict."""
return { return {
"reference_photo": sample_reference_photo,
"passphrase": "test phrase four words", # v3.2.0: single passphrase "passphrase": "test phrase four words", # v3.2.0: single passphrase
"pin": "123456" "pin": "123456"
} }
@@ -109,9 +123,10 @@ class TestBatchResult:
class TestBatchCredentials: class TestBatchCredentials:
"""Tests for BatchCredentials dataclass (v3.2.0).""" """Tests for BatchCredentials dataclass (v3.2.0)."""
def test_from_dict_new_format(self): def test_from_dict_new_format(self, sample_reference_photo):
"""Should parse v3.2.0 format with 'passphrase' key.""" """Should parse v3.2.0 format with 'passphrase' key."""
data = { data = {
"reference_photo": sample_reference_photo,
"passphrase": "test phrase four words", "passphrase": "test phrase four words",
"pin": "123456" "pin": "123456"
} }
@@ -119,9 +134,10 @@ class TestBatchCredentials:
assert creds.passphrase == "test phrase four words" assert creds.passphrase == "test phrase four words"
assert creds.pin == "123456" assert creds.pin == "123456"
def test_from_dict_legacy_format(self): def test_from_dict_legacy_format(self, sample_reference_photo):
"""Should parse legacy format with 'day_phrase' key for migration.""" """Should parse legacy format with 'day_phrase' key for migration."""
data = { data = {
"reference_photo": sample_reference_photo,
"day_phrase": "legacy phrase here", # Old key name "day_phrase": "legacy phrase here", # Old key name
"pin": "123456" "pin": "123456"
} }
@@ -130,9 +146,10 @@ class TestBatchCredentials:
assert creds.passphrase == "legacy phrase here" assert creds.passphrase == "legacy phrase here"
assert creds.pin == "123456" assert creds.pin == "123456"
def test_to_dict(self): def test_to_dict(self, sample_reference_photo):
"""Should serialize to v3.2.0 format.""" """Should serialize to v3.2.0 format."""
creds = BatchCredentials( creds = BatchCredentials(
reference_photo=sample_reference_photo,
passphrase="test phrase four words", passphrase="test phrase four words",
pin="123456" pin="123456"
) )
@@ -141,9 +158,10 @@ class TestBatchCredentials:
assert result['pin'] == "123456" assert result['pin'] == "123456"
assert 'day_phrase' not in result # Old key should not be present assert 'day_phrase' not in result # Old key should not be present
def test_passphrase_is_string(self): def test_passphrase_is_string(self, sample_reference_photo):
"""Passphrase should be a string, not a dict.""" """Passphrase should be a string, not a dict."""
creds = BatchCredentials( creds = BatchCredentials(
reference_photo=sample_reference_photo,
passphrase="test phrase four words", passphrase="test phrase four words",
pin="123456" pin="123456"
) )
@@ -380,9 +398,10 @@ class TestPrintBatchResult:
class TestCredentialsMigration: class TestCredentialsMigration:
"""Tests for v3.1.x to v3.2.0 credentials migration.""" """Tests for v3.1.x to v3.2.0 credentials migration."""
def test_old_phrase_key_accepted(self): def test_old_phrase_key_accepted(self, sample_reference_photo):
"""Old 'phrase' key should be accepted for migration.""" """Old 'phrase' key should be accepted for migration."""
old_format = { old_format = {
"reference_photo": sample_reference_photo,
"phrase": "old style phrase", "phrase": "old style phrase",
"pin": "123456" "pin": "123456"
} }
@@ -390,18 +409,20 @@ class TestCredentialsMigration:
creds = BatchCredentials.from_dict(old_format) creds = BatchCredentials.from_dict(old_format)
assert creds.passphrase == "old style phrase" assert creds.passphrase == "old style phrase"
def test_old_day_phrase_key_accepted(self): def test_old_day_phrase_key_accepted(self, sample_reference_photo):
"""Old 'day_phrase' key should be accepted for migration.""" """Old 'day_phrase' key should be accepted for migration."""
old_format = { old_format = {
"reference_photo": sample_reference_photo,
"day_phrase": "old day phrase", "day_phrase": "old day phrase",
"pin": "123456" "pin": "123456"
} }
creds = BatchCredentials.from_dict(old_format) creds = BatchCredentials.from_dict(old_format)
assert creds.passphrase == "old day phrase" assert creds.passphrase == "old day phrase"
def test_new_passphrase_key_preferred(self): def test_new_passphrase_key_preferred(self, sample_reference_photo):
"""New 'passphrase' key should take precedence if both present.""" """New 'passphrase' key should take precedence if both present."""
mixed_format = { mixed_format = {
"reference_photo": sample_reference_photo,
"passphrase": "new style passphrase", "passphrase": "new style passphrase",
"day_phrase": "old day phrase", "day_phrase": "old day phrase",
"pin": "123456" "pin": "123456"