`add` method replaced with `insert`. `insert` and `select` implemented for new database base class. Database unit test added. Due to SQLite implementation of the primary key autoinc, the type of the IDs on the database for SQLite changed to Integer. https://www.sqlite.org/autoinc.html
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
from datetime import date
|
|
from decimal import Decimal
|
|
from typing import Sequence
|
|
import pytest
|
|
|
|
from pfbudget.db.client import Client
|
|
from pfbudget.db.model import BankTransaction, Transaction
|
|
from pfbudget.load.database import DatabaseLoader
|
|
from pfbudget.load.load import Loader
|
|
|
|
|
|
class FakeDatabaseClient(Client):
|
|
def __init__(self, url: str) -> None:
|
|
super().__init__(url)
|
|
|
|
def insert(self, transactions: Sequence[Transaction]) -> None:
|
|
pass
|
|
|
|
|
|
@pytest.fixture
|
|
def loader() -> Loader:
|
|
url = "postgresql://user:pass@127.0.0.1:5432/db"
|
|
client = FakeDatabaseClient(url)
|
|
return DatabaseLoader(client)
|
|
|
|
|
|
class TestDatabaseLoad:
|
|
def test_empty_url(self):
|
|
with pytest.raises(AssertionError):
|
|
_ = FakeDatabaseClient("")
|
|
|
|
def test_insert(self, loader: Loader):
|
|
transactions = [
|
|
BankTransaction(date(2023, 1, 1), "", Decimal("-500"), "Bank#1"),
|
|
BankTransaction(date(2023, 1, 2), "", Decimal("500"), "Bank#2"),
|
|
]
|
|
|
|
loader.load(transactions)
|