def test_deserialise():
    postings = [
        {
            'account': 'Assets:ETrade:Cash',
            'amount': '100 USD',
        },
        {
            'account': 'Assets:ETrade:GLD',
        },
    ]
    json_txn = {
        'type': 'Transaction',
        'date': '2017-12-12',
        'flag': '*',
        'payee': 'Test3',
        'narration': 'asdfasd #tag ^link',
        'meta': {},
        'postings': postings,
    }

    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)
    assert deserialise(json_txn) == txn

    with pytest.raises(KeyError):
        deserialise({})

    with pytest.raises(FavaAPIException):
        deserialise({'type': 'NoEntry'})
Exemple #2
0
def test_deserialise():
    postings = [
        {
            'account': 'Assets:ETrade:Cash',
            'number': '100',
            'currency': 'USD',
        },
        {
            'account': 'Assets:ETrade:GLD',
        },
    ]
    json_txn = {
        'type': 'Transaction',
        'date': '2017-12-12',
        'flag': '*',
        'payee': 'Test3',
        'narration': 'asdfasd #tag ^link',
        'meta': {},
        'postings': postings,
    }

    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)
    assert deserialise(json_txn) == txn

    with pytest.raises(KeyError):
        deserialise({})

    with pytest.raises(FavaAPIException):
        deserialise({'type': 'NoEntry'})
Exemple #3
0
def test_deserialise():
    postings = [
        {"account": "Assets:ETrade:Cash", "amount": "100 USD"},
        {"account": "Assets:ETrade:GLD"},
    ]
    json_txn = {
        "type": "Transaction",
        "date": "2017-12-12",
        "flag": "*",
        "payee": "Test3",
        "narration": "asdfasd #tag ^link",
        "meta": {},
        "postings": postings,
    }

    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)
    assert deserialise(json_txn) == txn

    with pytest.raises(KeyError):
        deserialise({})

    with pytest.raises(FavaAPIException):
        deserialise({"type": "NoEntry"})
Exemple #4
0
def add_entries(request_data):
    """Add multiple entries."""
    try:
        entries = [deserialise(entry) for entry in request_data['entries']]
    except KeyError as error:
        raise FavaAPIException('KeyError: {}'.format(str(error)))

    g.ledger.file.insert_entries(entries)

    return {'message': 'Stored {} entries.'.format(len(entries))}
Exemple #5
0
def add_entries(request_data):
    """Add multiple entries."""
    try:
        entries = [deserialise(entry) for entry in request_data["entries"]]
    except KeyError as error:
        raise FavaAPIException(f"KeyError: {error}") from error

    g.ledger.file.insert_entries(entries)

    return f"Stored {len(entries)} entries."
Exemple #6
0
def put_add_entries(entries: list[Any]) -> str:
    """Add multiple entries."""
    try:
        entries = [deserialise(entry) for entry in entries]
    except KeyError as error:
        raise FavaAPIException(f"KeyError: {error}") from error

    g.ledger.file.insert_entries(entries)

    return f"Stored {len(entries)} entries."
Exemple #7
0
def add_entries(request_data):
    """Add multiple entries."""
    try:
        entries = [deserialise(entry) for entry in request_data["entries"]]
    except KeyError as error:
        raise FavaAPIException("KeyError: {}".format(str(error)))

    g.ledger.file.insert_entries(entries)

    return "Stored {} entries.".format(len(entries))
def test_deserialise_note():
    json_note = {
        'type': 'Note',
        'date': '2017-12-12',
        'account': 'Assets:ETrade:Cash',
        'comment': 'This is some comment or note""',
        'meta': {},
    }
    note = Note({}, datetime.date(2017, 12, 12), 'Assets:ETrade:Cash',
                'This is some comment or note')
    assert deserialise(json_note) == note
Exemple #9
0
def test_deserialise_note():
    json_note = {
        'type': 'Note',
        'date': '2017-12-12',
        'account': 'Assets:ETrade:Cash',
        'comment': 'This is some comment or note""',
        'meta': {},
    }
    note = Note({}, datetime.date(2017, 12, 12), 'Assets:ETrade:Cash',
                'This is some comment or note')
    assert deserialise(json_note) == note
def test_deserialise_balance():
    json_bal = {
        'type': 'Balance',
        'date': '2017-12-12',
        'account': 'Assets:ETrade:Cash',
        'number': '100',
        'currency': 'USD',
        'meta': {},
    }
    bal = Balance({}, datetime.date(2017, 12, 12), 'Assets:ETrade:Cash',
                  A('100 USD'), None, None)
    assert deserialise(json_bal) == bal
Exemple #11
0
def add_entries(request_data):
    """Add multiple entries."""
    try:
        entries = [
            deserialise(entry) for entry in request_data['entries']
        ]
    except KeyError as error:
        raise FavaAPIException('KeyError: {}'.format(str(error)))

    g.ledger.file.insert_entries(entries)

    return {'message': 'Stored {} entries.'.format(len(entries))}
Exemple #12
0
def test_deserialise_balance():
    json_bal = {
        'type': 'Balance',
        'date': '2017-12-12',
        'account': 'Assets:ETrade:Cash',
        'number': '100',
        'currency': 'USD',
        'meta': {},
    }
    bal = Balance({}, datetime.date(2017, 12, 12), 'Assets:ETrade:Cash',
                  A('100 USD'), None, None)
    assert deserialise(json_bal) == bal
Exemple #13
0
def test_deserialise_note():
    json_note = {
        "type": "Note",
        "date": "2017-12-12",
        "account": "Assets:ETrade:Cash",
        "comment": 'This is some comment or note""',
        "meta": {},
    }
    note = Note(
        {},
        datetime.date(2017, 12, 12),
        "Assets:ETrade:Cash",
        "This is some comment or note",
    )
    assert deserialise(json_note) == note
Exemple #14
0
def test_deserialise_balance() -> None:
    json_bal = {
        "type": "Balance",
        "date": "2017-12-12",
        "account": "Assets:ETrade:Cash",
        "amount": {"number": "100", "currency": "USD"},
        "meta": {},
    }
    bal = Balance(
        {},
        datetime.date(2017, 12, 12),
        "Assets:ETrade:Cash",
        A("100 USD"),
        None,
        None,
    )
    assert deserialise(json_bal) == bal