Skip to content

Commit

Permalink
fix fetch multiple params with optional body
Browse files Browse the repository at this point in the history
  • Loading branch information
dperl-dls committed Aug 13, 2024
1 parent 4736a16 commit a2b87c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/daq_config_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ParamList(BaseModel):


@app.get(ENDPOINTS.BL_PARAM)
def get_all_beamline_parameters(param_list_data: ParamList | None):
def get_all_beamline_parameters(param_list_data: ParamList | None = None):
"""Get a dict of all the current beamline parameters."""
assert BEAMLINE_PARAMS is not None
if param_list_data is None:
Expand Down Expand Up @@ -140,12 +140,20 @@ async def catch_all(request: Request, full_path: str):
}


def main(args):
global BEAMLINE_PARAM_PATH
def _load_beamline_params():
global BEAMLINE_PARAMS
if args.dev:
BEAMLINE_PARAMS = GDABeamlineParameters.from_file(BEAMLINE_PARAM_PATH)


def _set_beamline_param_path(dev: bool = True):
global BEAMLINE_PARAM_PATH
if dev:
BEAMLINE_PARAM_PATH = "tests/test_data/beamline_parameters.txt"
else:
BEAMLINE_PARAM_PATH = BEAMLINE_PARAMETER_PATHS["i03"]
BEAMLINE_PARAMS = GDABeamlineParameters.from_file(BEAMLINE_PARAM_PATH)


def main(args):
_set_beamline_param_path(args.dev)
_load_beamline_params()
uvicorn.run(app="daq_config_server.app:app", host="0.0.0.0", port=8555)
6 changes: 4 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fastapi.testclient import TestClient
from mockito import when

from daq_config_server.app import app
from daq_config_server import app
from daq_config_server.beamline_parameters import GDABeamlineParameters
from daq_config_server.constants import ENDPOINTS

Expand All @@ -17,7 +17,9 @@

@pytest.fixture
def mock_app():
return TestClient(app)
app._set_beamline_param_path(True)
app._load_beamline_params()
return TestClient(app.app)


async def _assert_get_and_response(
Expand Down

0 comments on commit a2b87c2

Please sign in to comment.