add tests and types for pipeline interface
This commit is contained in:
parent
1849df94c9
commit
f4907a73e9
@ -4,12 +4,15 @@ from datetime import datetime as Datetime
|
|||||||
|
|
||||||
from delta_barth.analysis import forecast
|
from delta_barth.analysis import forecast
|
||||||
from delta_barth.management import SESSION
|
from delta_barth.management import SESSION
|
||||||
|
from delta_barth.types import JsonResponse, JsonStatus
|
||||||
|
|
||||||
|
|
||||||
def pipeline_sales_forecast(
|
def pipeline_sales_forecast(
|
||||||
company_id: int | None,
|
company_id: int | None,
|
||||||
start_date: Datetime | None,
|
start_date: Datetime | None,
|
||||||
) -> str:
|
) -> tuple[JsonResponse, JsonStatus]:
|
||||||
result = forecast.pipeline(SESSION, company_id=company_id, start_date=start_date)
|
result = forecast.pipeline(SESSION, company_id=company_id, start_date=start_date)
|
||||||
|
response = JsonResponse(result.response.model_dump_json())
|
||||||
|
status = JsonStatus(result.status.model_dump_json())
|
||||||
|
|
||||||
return result.model_dump_json()
|
return response, status
|
||||||
|
|||||||
@ -110,6 +110,10 @@ class PipeResult(t.Generic[R]):
|
|||||||
self.results = response
|
self.results = response
|
||||||
|
|
||||||
|
|
||||||
|
JsonResponse = t.NewType("JsonResponse", str)
|
||||||
|
JsonStatus = t.NewType("JsonStatus", str)
|
||||||
|
|
||||||
|
|
||||||
# ** API
|
# ** API
|
||||||
class ApiCredentials(BaseModel):
|
class ApiCredentials(BaseModel):
|
||||||
model_config: ConfigDict = ConfigDict(str_strip_whitespace=True)
|
model_config: ConfigDict = ConfigDict(str_strip_whitespace=True)
|
||||||
|
|||||||
31
tests/test_pipelines.py
Normal file
31
tests/test_pipelines.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import importlib
|
||||||
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import delta_barth.pipelines
|
||||||
|
from delta_barth import pipelines as pl
|
||||||
|
from delta_barth.errors import STATUS_HANDLER
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.new
|
||||||
|
def test_sales_prognosis_pipeline(exmpl_api_sales_prognosis_resp):
|
||||||
|
def mock_request(*args, **kwargs):
|
||||||
|
return exmpl_api_sales_prognosis_resp, STATUS_HANDLER.SUCCESS
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"delta_barth.api.requests.get_sales_prognosis_data",
|
||||||
|
new=mock_request,
|
||||||
|
):
|
||||||
|
importlib.reload(delta_barth.pipelines)
|
||||||
|
json_resp, json_stat = pl.pipeline_sales_forecast(None, None)
|
||||||
|
|
||||||
|
assert isinstance(json_resp, str)
|
||||||
|
assert isinstance(json_stat, str)
|
||||||
|
parsed_resp = json.loads(json_resp)
|
||||||
|
assert "daten" in parsed_resp
|
||||||
|
assert len(parsed_resp["daten"]) > 0
|
||||||
|
parsed_stat = json.loads(json_stat)
|
||||||
|
assert "code" in parsed_stat
|
||||||
|
assert parsed_stat["code"] == 0
|
||||||
Loading…
x
Reference in New Issue
Block a user