Skip to content

Commit

Permalink
#79 prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
epogrebnyak committed Aug 20, 2024
1 parent 5c5985e commit 8b3f82b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions playground/chart_api.py
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())

0 comments on commit 8b3f82b

Please sign in to comment.