-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c5985e
commit 8b3f82b
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Use fastapi to create Chart object below | ||
|
||
from fastapi import FastAPI | ||
from pydantic import BaseModel | ||
from core import T5 | ||
|
||
app = FastAPI() | ||
|
||
|
||
class FastChart(BaseModel): | ||
income_summary_account: str | ||
retained_earnings_account: str | ||
accounts: dict[str, tuple[T5, list[str]]] | ||
|
||
|
||
class ChartRequest(BaseModel): | ||
pass | ||
|
||
|
||
@app.post("/chart/new") | ||
def create_chart( | ||
income_summary_account: str = "isa", retained_earnings_account: str = "re" | ||
) -> FastChart: | ||
return FastChart( | ||
income_summary_account=income_summary_account, | ||
retained_earnings_account=retained_earnings_account, | ||
accounts={retained_earnings_account: (T5.Capital, [])}, | ||
) | ||
|
||
from fastapi.testclient import TestClient | ||
|
||
client = TestClient(app) | ||
|
||
def test_chart_new(): | ||
payload = { | ||
"income_summary_account": "current_profit", | ||
"retained_earnings_account": "retained_earnings", | ||
} | ||
response = client.post("/chart/new", params=payload) | ||
assert response.status_code == 200 | ||
assert response.json() == { | ||
"income_summary_account": "current_profit", | ||
"retained_earnings_account": "retained_earnings", | ||
"accounts": {"retained_earnings": ["capital", []]}, | ||
} | ||
|
||
|
||
test_chart_new() | ||
print(create_chart()) |