コード例 #1
0
ファイル: test_serialisation.py プロジェクト: stephas/fava
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
コード例 #2
0
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
コード例 #3
0
ファイル: test_serialisation.py プロジェクト: tbm/fava
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,
    }
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
ファイル: test_serialisation.py プロジェクト: stephas/fava
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
コード例 #9
0
ファイル: json_api.py プロジェクト: rainsunny/fava
def payee_transaction():
    """Last transaction for the given payee."""
    entry = g.ledger.attributes.payee_transaction(request.args.get('payee'))
    return {'payload': serialise(entry)}
コード例 #10
0
ファイル: json_api.py プロジェクト: adamgibbins/fava
def payee_transaction():
    """Last transaction for the given payee."""
    entry = g.ledger.attributes.payee_transaction(request.args.get('payee'))
    return {'payload': serialise(entry)}
コード例 #11
0
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
コード例 #12
0
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
コード例 #13
0
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_)
コード例 #14
0
ファイル: json_api.py プロジェクト: edwardtheharris/fava
def payee_transaction() -> Any:
    """Last transaction for the given payee."""
    entry = g.ledger.attributes.payee_transaction(request.args.get(
        "payee", ""))
    return serialise(entry)
コード例 #15
0
ファイル: test_serialisation.py プロジェクト: sulemankm/fava
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