Skip to content
Snippets Groups Projects
Commit b1daab76 authored by Detourne Gwenaelle's avatar Detourne Gwenaelle
Browse files

fakeAPI first try

parent a0f84047
No related branches found
No related tags found
1 merge request!15fakeAPI disk spectra sim result
This commit is part of merge request !15. Comments created here will be created in the context of that merge request.
......@@ -9,12 +9,13 @@ sdb-v2-155113.93+353926.6-mnest/phoenix_m+modbb_disk_r_.json
# Standard imports
import json
from pathlib import Path
# Third party imports
import panel
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.templating import Jinja2Templates
from panel.pane import Markdown
......@@ -113,3 +114,24 @@ async def disk_infos(request: Request) -> HTMLResponse:
name="disk_infos_fragment.html.jinja",
context={"script": script},
)
@app.get("/fake/diskspectrasimresult", response_class=JSONResponse)
async def diskspectrasimresult(request: Request) -> JSONResponse:
"""
Collect disk spectra simulation data.
Args:
request: Informations from JSON request.
Returns:
A JSON file, ready to be input for DiskPlot function.
It is copied from an example JSON file for the moment but
it will be collected from an HTTP request/JSONResponse in the end.
"""
with open("phoenix_m+modbb_disk_r_.json") as source_file:
data = json.load(source_file)
# TODO: move this file_path to a parameter to be ready to accept a JSONResponse
# after a request to GRaTeR. But I am not sure how to do that.
return JSONResponse(content=data)
"""Tests for fake API in main.py file"""
# Test imports
import pytest
from assertpy import assert_that
# Standard imports
import json
# First party imports
from main import DiskPlot, diskspectrasimresult
# from fastapi.testclient import TestClient
def test_disk_plot_fails_with_empty_json():
with pytest.raises(Exception):
disk_plot = DiskPlot("")
def test_disk_plot_fails_with_bad_diskspectrasimresult_response():
with pytest.raises(Exception):
# client = TestClient(app)
disk_plot = DiskPlot(client.get("/fake/diskspectrasimresult").json())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment