diff --git a/tests/test_tax.py b/tests/test_tax.py index 2b38f71..fa9eeb3 100644 --- a/tests/test_tax.py +++ b/tests/test_tax.py @@ -34,7 +34,15 @@ TRANSACTION_DEFAULTS = { RATE_2024 = 106037489 -def create_market(name, kind="exchange", taxable=1, custody_market_id=None): +def create_market(name, kind="exchange", taxable=1, custody_market_id=None, + kroner_ore=100000000): + """Create an account, funded from the bank unless kroner_ore is 0. + + No real account may go negative (docs/spec.md section 3.11), so a fixture that + pays kroner has to be funded first. The funding is dated before every other + row, so the replay sees it first and no figure moves: it is a transfer. + """ + bank = int(database.get_setting("bank_market_id")) conn = database.connect() try: with conn: @@ -43,7 +51,22 @@ def create_market(name, kind="exchange", taxable=1, custody_market_id=None): " VALUES (?, ?, ?, ?)", (name, kind, taxable, custody_market_id), ) - return cursor.lastrowid + market_id = cursor.lastrowid + if kroner_ore: + group = "fund-%d" % market_id + conn.execute( + "INSERT INTO transactions (date, type, market_id, leg_out_ore," + " to_market_id, transfer_group, created_at, updated_at)" + " VALUES ('2000-01-01', 'transfer_out', ?, ?, ?, ?, 'x', 'x')", + (bank, kroner_ore, market_id, group), + ) + conn.execute( + "INSERT INTO transactions (date, type, market_id, leg_in_ore," + " to_market_id, transfer_group, generated, created_at, updated_at)" + " VALUES ('2000-01-01', 'transfer_in', ?, ?, ?, ?, 1, 'x', 'x')", + (market_id, kroner_ore, bank, group), + ) + return market_id finally: conn.close()