diff --git a/src/delta_barth/pipelines.py b/src/delta_barth/pipelines.py index 4dafe38..280d7c3 100644 --- a/src/delta_barth/pipelines.py +++ b/src/delta_barth/pipelines.py @@ -4,12 +4,15 @@ from datetime import datetime as Datetime from delta_barth.analysis import forecast from delta_barth.management import SESSION +from delta_barth.types import JsonResponse, JsonStatus def pipeline_sales_forecast( company_id: int | None, start_date: Datetime | None, -) -> str: +) -> tuple[JsonResponse, JsonStatus]: 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 diff --git a/src/delta_barth/types.py b/src/delta_barth/types.py index 3b070e2..3769cb9 100644 --- a/src/delta_barth/types.py +++ b/src/delta_barth/types.py @@ -110,6 +110,10 @@ class PipeResult(t.Generic[R]): self.results = response +JsonResponse = t.NewType("JsonResponse", str) +JsonStatus = t.NewType("JsonStatus", str) + + # ** API class ApiCredentials(BaseModel): model_config: ConfigDict = ConfigDict(str_strip_whitespace=True) diff --git a/tests/test_pipelines.py b/tests/test_pipelines.py new file mode 100644 index 0000000..5ec6a3f --- /dev/null +++ b/tests/test_pipelines.py @@ -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