Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/__snapshots__/test_json_api-test_api_context-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"t": "Open"
},
"sha256sum": "ENTRY_HASH260d384e80c9af182390e419d4a0bbc8",
"sha256sum": "7198a732bba60e03bfebbf4368637a66260d384e80c9af182390e419d4a0bbc8",
"slice": "1980-05-12 open Expenses:Food:Alcohol"
}
2 changes: 1 addition & 1 deletion tests/__snapshots__/test_json_api-test_api_context.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@
"t": "Transaction",
"tags": []
},
"sha256sum": "ENTRY_HASH045ed99d2af148ec815727c3b136906e",
"sha256sum": "b8d184b8ffadddbdc915a9dbf7e4d94a045ed99d2af148ec815727c3b136906e",
"slice": "2016-05-09 * \"Investing 40% of cash in VBMPX\"\n Assets:US:Vanguard:VBMPX 15.957 VBMPX {30.08 USD}\n Assets:US:Vanguard:Cash -479.99 USD"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"account": "Expenses:Food",
"date": "2012-12-15",
"filename": "TEST_DATA_DIR/import.csv",
"filename": "/tmp/import.csv",
"links": [
"link1"
],
Expand All @@ -18,7 +18,7 @@
{
"account": "Expenses:Food",
"date": "2012-12-15",
"filename": "TEST_DATA_DIR/receipt.pdf",
"filename": "/tmp/receipt.pdf",
"links": [],
"meta": {
"filename": "TEST_DATA_DIR/example.beancount",
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ def snapshot_data(
today = local_today()
out = out.replace(str(today), "TODAY")
# replace entry hashes
out = re.sub(r'"[0-9a-f]{32}', '"ENTRY_HASH', out)
out = re.sub(r"context-[0-9a-f]{32}", "context-ENTRY_HASH", out)
out = re.sub(r'_hash": "[0-9a-f]+', '_hash": "ENTRY_HASH', out)
out = re.sub(r"context-[0-9a-f]+", "context-ENTRY_HASH", out)
out = re.sub(
r"data-entry=\\\"[0-9a-f]+", 'data-entry=\\"ENTRY_HASH', out
)
# replace mtimes
out = re.sub(r"mtime=\d+", "mtime=MTIME", out)
out = re.sub(r'id="ledger-mtime">\d+', 'id="ledger-mtime">MTIME', out)
Expand Down
4 changes: 2 additions & 2 deletions tests/data/example.beancount
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ plugin "beancount.plugins.auto_accounts"
test: TRUE
account: Expenses:Food

2012-12-15 document Expenses:Food "import.csv" #tag ^link1
2012-12-15 document Expenses:Food "receipt.pdf" #discovered
2012-12-15 document Expenses:Food "/tmp/import.csv" #tag ^link1
2012-12-15 document Expenses:Food "/tmp/receipt.pdf" #discovered

2014-01-01 close Assets:Account1
2 changes: 1 addition & 1 deletion tests/data/off-by-one.beancount
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ option "operating_currency" "USD"

2022-01-01 * "Buy"
Assets:Cash -100 USD
Assets:Commodity 1 COM {{100 USD}}
Assets:Commodity 1 COM {100 USD}

2022-01-01 price COM 101 USD
2022-01-02 price COM 102 USD
Expand Down
3 changes: 3 additions & 0 deletions tests/test_core_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ def test_net_worth_off_by_one(
) -> None:
off_by_one = get_ledger("off-by-one")
off_by_one_filtered = off_by_one.get_filtered()
assert not off_by_one.errors
assert len(off_by_one_filtered.entries) == 9

for interval in [Interval.DAY, Interval.MONTH]:
data = off_by_one.charts.net_worth(
off_by_one_filtered,
interval,
"at_value",
)
assert len(data) == 4 if interval == Interval.DAY else 1
snapshot(data, json=True)


Expand Down
21 changes: 20 additions & 1 deletion tests/test_json_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import datetime
import sys
from http import HTTPStatus
from io import BytesIO
from pathlib import Path
Expand Down Expand Up @@ -661,11 +662,29 @@ def test_api_filter_error(
assert_api_error(response, status=HTTPStatus.BAD_REQUEST)


@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
@pytest.mark.parametrize(
("name", "url"),
[
("commodities", "/long-example/api/commodities"),
("documents", "/example/api/documents"),
],
)
def test_api_unix_only(
test_client: FlaskClient,
snapshot: SnapshotFunc,
name: str,
url: str,
) -> None:
response = test_client.get(url)
data = assert_api_success(response)
assert data
snapshot(data, name=name, json=True)


@pytest.mark.parametrize(
("name", "url"),
[
("commodities", "/long-example/api/commodities"),
("events", "/long-example/api/events"),
("income_statement", "/long-example/api/income_statement?time=2014"),
("trial_balance", "/long-example/api/trial_balance?time=2014"),
Expand Down
Loading