Пример #1
0
def test_collapse_account(app: Flask, monkeypatch: MonkeyPatch) -> None:
    with app.test_request_context("/long-example/"):
        app.preprocess_request()

        monkeypatch.setattr(
            g.ledger.fava_options,
            "collapse_pattern",
            [
                re.compile("^Assets:Stock$"),
                re.compile("^Assets:Property:.*"),
            ],
        )
        monkeypatch.setitem(g.ledger.accounts, "Assets:Stock", AccountData())
        monkeypatch.setitem(g.ledger.accounts, "Assets:Property",
                            AccountData())

        assert collapse_account("Assets:Cash") is False
        assert collapse_account("Assets:Cash") is False

        assert collapse_account("Assets:Stock") is True
        assert collapse_account("Assets:Stock") is True
        assert collapse_account("Assets:Stock") is True

        assert collapse_account("Assets:Property") is False
        assert collapse_account("Assets:Property:Real") is True
        assert collapse_account("Assets:Property:Real:Land") is True
Пример #2
0
def test_api_add_document(
    app: Flask,
    test_client: FlaskClient,
    tmp_path: Path,
    monkeypatch: MonkeyPatch,
) -> None:
    with app.test_request_context("/long-example/"):
        app.preprocess_request()

        monkeypatch.setitem(
            g.ledger.options, "documents", [str(tmp_path)]  # type: ignore
        )
        request_data = {
            "folder": str(tmp_path),
            "account": "Expenses:Food:Restaurant",
            "file": (BytesIO(b"asdfasdf"), "2015-12-12 test"),
        }
        url = url_for("json_api.put_add_document")

        response = test_client.put(url)
        assert_api_error(response, "No file uploaded.")

        filename = (
            tmp_path / "Expenses" / "Food" / "Restaurant" / "2015-12-12 test"
        )

        response = test_client.put(url, data=request_data)
        assert_api_success(response, f"Uploaded to {filename}")
        assert Path(filename).is_file()

        request_data["file"] = (BytesIO(b"asdfasdf"), "2015-12-12 test")
        response = test_client.put(url, data=request_data)
        assert_api_error(response, f"{filename} already exists.")
Пример #3
0
def test_incognito(app: Flask, test_client: FlaskClient,
                   monkeypatch: MonkeyPatch) -> None:
    """Numbers get obfuscated in incognito mode."""
    monkeypatch.setitem(app.config, "INCOGNITO", True)
    result = test_client.get("/long-example/balance_sheet/")
    assert result.status_code == 200
    assert "XXX" in result.get_data(True)
Пример #4
0
def test_paths_to_watch(example_ledger: FavaLedger,
                        monkeypatch: MonkeyPatch) -> None:
    assert example_ledger.paths_to_watch() == (
        [example_ledger.beancount_file_path],
        [],
    )
    monkeypatch.setitem(
        example_ledger.options,
        "documents",
        ["folder"]  # type: ignore
    )
    base = Path(example_ledger.beancount_file_path).parent / "folder"
    assert example_ledger.paths_to_watch() == (
        [example_ledger.beancount_file_path],
        [
            str(base / account) for account in [
                "Assets",
                "Liabilities",
                "Equity",
                "Income",
                "Expenses",
            ]
        ],
    )
Пример #5
0
 def test_glibc_version_string_ctypes_missing(
         self, monkeypatch: pytest.MonkeyPatch) -> None:
     monkeypatch.setitem(sys.modules, "ctypes", None)
     assert glibc_version_string_ctypes() is None