Initial roborto accounting implementation
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from decimal import Decimal
|
||||
from sqlalchemy import text
|
||||
from roborto_accounting.persistence.db import make_engine, make_session_factory, session_scope
|
||||
from roborto_accounting.persistence.money import from_minor_units, to_minor_units
|
||||
|
||||
def test_sqlite_session_scope_commits(tmp_path):
|
||||
engine = make_engine("sqlite:///" + str(tmp_path / "test.db"))
|
||||
factory = make_session_factory(engine)
|
||||
with engine.begin() as connection:
|
||||
connection.execute(text("create table marker (value integer not null)"))
|
||||
with session_scope(factory) as session:
|
||||
session.execute(text("insert into marker (value) values (1)"))
|
||||
with factory() as session:
|
||||
assert session.scalar(text("select value from marker")) == 1
|
||||
engine.dispose()
|
||||
|
||||
def test_money_uses_exact_integer_micro_units():
|
||||
amount = Decimal("12.345678")
|
||||
assert to_minor_units(amount) == 12345678
|
||||
assert from_minor_units(12345678) == amount
|
||||
|
||||
def test_money_type_rejects_binary_float():
|
||||
try:
|
||||
to_minor_units(1.5) # type: ignore[arg-type]
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("float monetary values must be rejected")
|
||||
Reference in New Issue
Block a user