test: unit, integration and e2e tests
Task: MIL-002#6
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""Shared fakes of the ports for the unit tests."""
|
||||
|
||||
import pytest
|
||||
|
||||
from password_manager.domain.errors import DataFileNotFoundError, EntryNotFoundError
|
||||
from password_manager.domain.password_entry import PasswordEntry
|
||||
|
||||
|
||||
class FakePasswordRepository:
|
||||
"""In-memory PasswordRepository; `has_file` False mimics a missing file."""
|
||||
|
||||
def __init__(self, has_file: bool = True) -> None:
|
||||
self.entries: dict[str, PasswordEntry] = {}
|
||||
self.has_file = has_file
|
||||
|
||||
def add(self, entry: PasswordEntry) -> None:
|
||||
self.entries[entry.website] = entry
|
||||
self.has_file = True
|
||||
|
||||
def find(self, website: str) -> PasswordEntry:
|
||||
if not self.has_file:
|
||||
raise DataFileNotFoundError
|
||||
if website not in self.entries:
|
||||
raise EntryNotFoundError(website)
|
||||
return self.entries[website]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def repository() -> FakePasswordRepository:
|
||||
return FakePasswordRepository()
|
||||
Reference in New Issue
Block a user