test_notch.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import json
  2. from pathlib import Path
  3. import magic
  4. from fastapi.testclient import TestClient
  5. from mocka.main import get_application
  6. from mocka.configuration import Configuration, Server
  7. from mocka.artefact import Artefact
  8. client = TestClient(get_application(Configuration(Server("localhost", 8585))))
  9. def test_post_notch():
  10. notch_model_file_path = Path(__file__).parent / Path("notch/notchFilter.mo")
  11. mime = magic.Magic(mime=True).from_file(notch_model_file_path)
  12. model_artefact = Artefact("inline", notch_model_file_path.read_text(), notch_model_file_path.name, mime)
  13. parameters = {
  14. "frequency": 500,
  15. "amplitude": 1,
  16. "sampling_ratio": 100,
  17. "tolerance": 1e-9,
  18. "data_cycles": 2,
  19. "output_stabilisation_time": 1.0,
  20. "output": ["time", "V_out.v","V_in.v"],
  21. }
  22. parameters_json = json.dumps(parameters, indent=4)
  23. parameters_artefact = Artefact("inline", parameters_json, "parameters.json", "application/json")
  24. mock_input = {
  25. "ctrl": "cin",
  26. "input": {
  27. "model": model_artefact.as_dict(),
  28. "parameters": parameters_artefact.as_dict(),
  29. }
  30. }
  31. response = client.post("/notch/simulation/", json=mock_input)
  32. assert response.status_code == 200
  33. # orig = base64.b64decode(rail_image_data.get("content"))
  34. # with temp_image_loc.open("wb") as f_output:
  35. # f_output.write(orig)
  36. # annotated_image_artefact, data_artefact = rail_finder_algo_one(str(temp_image_loc))
  37. # data_artefact = Artefact("inline", "", "", "text/plain")
  38. # assert response.json() == {
  39. # "ctrl": "ok",
  40. # "output": {
  41. # "data": data_artefact.as_dict(),
  42. # }
  43. # }