def test_serialise(app): assert serialise(None) is None txn = Transaction({}, datetime.date(2017, 12, 12), '*', 'Test3', 'asdfasd', frozenset(['tag']), frozenset(['link']), []) create_simple_posting(txn, 'Assets:ETrade:Cash', '100', 'USD') create_simple_posting(txn, 'Assets:ETrade:GLD', None, None) json_txn = { 'date': '2017-12-12', 'flag': '*', 'meta': {}, 'narration': 'asdfasd #tag ^link', 'payee': 'Test3', 'type': 'Transaction', 'postings': [ { 'account': 'Assets:ETrade:Cash', 'amount': '100 USD', }, { 'account': 'Assets:ETrade:GLD', 'amount': '', }, ], } with app.test_request_context(): serialised = loads(dumps(serialise(txn))) assert serialised == json_txn
def test_serialise(app): assert serialise(None) is None txn = Transaction({}, datetime.date(2017, 12, 12), '*', 'Test3', 'asdfasd', frozenset(['tag']), frozenset(['link']), []) create_simple_posting(txn, 'Assets:ETrade:Cash', '100', 'USD') create_simple_posting(txn, 'Assets:ETrade:GLD', None, None) json_txn = { 'type': 'Transaction', 'date': '2017-12-12', 'flag': '*', 'payee': 'Test3', 'narration': 'asdfasd #tag ^link', 'meta': {}, } with app.test_request_context(): serialised = loads(dumps(serialise(txn))) for key, value in json_txn.items(): assert serialised[key] == value or str(serialised[key]) == value assert serialised['postings'][0]['account'] == 'Assets:ETrade:Cash' assert serialised['postings'][0]['units'] == { 'currency': 'USD', 'number': 100, }
def test_serialise(app): assert serialise(None) is None txn = Transaction( {}, datetime.date(2017, 12, 12), "*", "Test3", "asdfasd", frozenset(["tag"]), frozenset(["link"]), [], ) create_simple_posting(txn, "Assets:ETrade:Cash", "100", "USD") create_simple_posting(txn, "Assets:ETrade:GLD", None, None) json_txn = { "date": "2017-12-12", "flag": "*", "meta": {}, "narration": "asdfasd #tag ^link", "payee": "Test3", "type": "Transaction", "postings": [ { "account": "Assets:ETrade:Cash", "amount": "100 USD" }, { "account": "Assets:ETrade:GLD", "amount": "" }, ], } with app.test_request_context(): serialised = loads(dumps(serialise(txn))) assert serialised == json_txn txn = txn._replace(payee="") json_txn["payee"] = "" serialised = loads(dumps(serialise(txn))) assert serialised == json_txn txn = txn._replace(payee=None) serialised = loads(dumps(serialise(txn))) assert serialised == json_txn
def test_serialise_balance() -> None: bal = Balance( {}, datetime.date(2019, 9, 17), "Assets:ETrade:Cash", A("0.1234567891011121314151617 CHF"), None, None, ) json = { "date": "2019-09-17", "amount": { "currency": "CHF", "number": "0.1234567891011121314151617" }, "diff_amount": None, "meta": {}, "tolerance": None, "account": "Assets:ETrade:Cash", "type": "Balance", } serialised = loads(dumps(serialise(bal))) assert serialised == json
def test_serialise_posting(pos, amount): pos = Posting('Assets:ETrade:Cash', *pos) json = { 'account': 'Assets:ETrade:Cash', 'amount': amount, } assert loads(dumps(serialise(pos))) == json assert deserialise_posting(json) == pos
def test_serialise_posting( amount_cost_price: Tuple[Amount, Optional[CostSpec], Amount], amount_string: str, ) -> None: pos = Posting("Assets", *amount_cost_price, None, None) json = {"account": "Assets", "amount": amount_string} assert loads(dumps(serialise(pos))) == json assert deserialise_posting(json) == pos
def payee_transaction(): """Last transaction for the given payee.""" entry = g.ledger.attributes.payee_transaction(request.args.get('payee')) return {'payload': serialise(entry)}
def test_serialise_posting(pos, amount): pos = Posting("Assets:ETrade:Cash", *pos) json = {"account": "Assets:ETrade:Cash", "amount": amount} assert loads(dumps(serialise(pos))) == json assert deserialise_posting(json) == pos
def get_payee_transaction(payee: str) -> Any: """Last transaction for the given payee.""" entry = g.ledger.attributes.payee_transaction(payee) return serialise(entry) if entry else None
def get_context(entry_hash: str) -> Context: """Entry context.""" entry, before, after, slice_, sha256sum = g.ledger.context(entry_hash) return Context(serialise(entry), before, after, sha256sum, slice_)
def payee_transaction() -> Any: """Last transaction for the given payee.""" entry = g.ledger.attributes.payee_transaction(request.args.get( "payee", "")) return serialise(entry)
def test_serialise_posting(amount_cost_price, amount_string): pos = Posting("Assets", *amount_cost_price, None, None) json = {"account": "Assets", "amount": amount_string} assert loads(dumps(serialise(pos))) == json assert deserialise_posting(json) == pos