Browse Source

Add test code

Arkadiusz Ryś 3 years ago
parent
commit
e4f9b45d37

+ 61 - 0
data/notchFilter.mo

@@ -0,0 +1,61 @@
+model notchFilter
+// Parameters
+  parameter Modelica.Units.SI.PotentialDifference Vt "testAmplitude";
+  parameter Modelica.Units.SI.Frequency Ft "testFrequency";
+// Components
+  Modelica.Electrical.Analog.Basic.Ground ground_in annotation(
+    Placement(visible = true, transformation(origin = {-80, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Ground ground annotation(
+    Placement(transformation(origin = {28, -18}, extent = {{-10, -10}, {10, 10}})));
+  Modelica.Electrical.Analog.Basic.Ground ground_out annotation(
+    Placement(visible = true, transformation(origin = {80, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Capacitor C1(C(displayUnit = "nF") = 1e-9, v(start = 0)) annotation(
+    Placement(visible = true, transformation(origin = {-20, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Capacitor C2(C(displayUnit = "pF") = 1e-9, v(start = 0)) annotation(
+    Placement(visible = true, transformation(origin = {20, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Capacitor C3(C(displayUnit = "pF") = 2e-9, v(start = 0)) annotation(
+    Placement(visible = true, transformation(origin = {0, 20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
+  Modelica.Electrical.Analog.Basic.Resistor R1(R(displayUnit = "kOhm") = 1600) annotation(
+    Placement(visible = true, transformation(origin = {-20, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Resistor R2(R(displayUnit = "kOhm") = 1600) annotation(
+    Placement(visible = true, transformation(origin = {20, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Resistor R3a(R(displayUnit = "kOhm") = 1600) annotation(
+    Placement(transformation(origin = {12, -18}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
+  Modelica.Electrical.Analog.Basic.Resistor R3b(R(displayUnit = "kOhm") = 1600) annotation(
+    Placement(transformation(origin = {-12, -18}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
+  Modelica.Electrical.Analog.Sensors.VoltageSensor V_out annotation(
+    Placement(visible = true, transformation(origin = {60, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Sources.SineVoltage V_in(V(displayUnit = "V") = Vt, f(displayUnit = "Hz") = Ft) annotation(
+    Placement(visible = true, transformation(origin = {-60, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
+// Equations
+  equation
+  connect(C3.n, R3a.p) annotation(
+    Line(points = {{0, 10}, {0, -1}, {12, -1}, {12, -8}}, color = {0, 0, 255}));
+  connect(V_out.p, C2.n) annotation(
+    Line(points = {{50, 0}, {40, 0}, {40, -40}, {30, -40}}, color = {0, 0, 255}));
+  connect(R1.n, R2.p) annotation(
+    Line(points = {{-10, 40}, {10, 40}}, color = {0, 0, 255}));
+  connect(C3.p, R2.p) annotation(
+    Line(points = {{0, 30}, {0, 40}, {10, 40}}, color = {0, 0, 255}));
+  connect(V_out.n, ground_out.p) annotation(
+    Line(points = {{70, 0}, {80, 0}, {80, -20}}, color = {0, 0, 255}));
+  connect(V_in.p, C1.p) annotation(
+    Line(points = {{-50, 0}, {-40, 0}, {-40, -40}, {-30, -40}}, color = {0, 0, 255}));
+  connect(R2.n, C2.n) annotation(
+    Line(points = {{30, 40}, {40, 40}, {40, -40}, {30, -40}}, color = {0, 0, 255}));
+  connect(V_in.n, ground_in.p) annotation(
+    Line(points = {{-70, 0}, {-80, 0}, {-80, -20}}, color = {0, 0, 255}));
+  connect(R1.p, C1.p) annotation(
+    Line(points = {{-30, 40}, {-40, 40}, {-40, -40}, {-30, -40}}, color = {0, 0, 255}));
+  connect(R3b.p, C3.n) annotation(
+    Line(points = {{-12, -8}, {-12, -1}, {0, -1}, {0, 10}}, color = {0, 0, 255}));
+  connect(C1.n, C2.p) annotation(
+    Line(points = {{-10, -40}, {10, -40}}, color = {0, 0, 255}));
+  connect(R3a.n, C2.p) annotation(
+    Line(points = {{12, -28}, {12, -32}, {0, -32}, {0, -40}, {10, -40}}, color = {0, 0, 255}));
+  connect(R3b.n, C1.n) annotation(
+    Line(points = {{-12, -28}, {-12, -32}, {0, -32}, {0, -40}, {-10, -40}}, color = {0, 0, 255}));
+  connect(ground.p, C3.n) annotation(
+    Line(points = {{28, -8}, {28, -1}, {0, -1}, {0, 10}}, color = {0, 0, 255}));
+  annotation(uses(Modelica(version = "4.0.0")), Diagram);
+end notchFilter;

+ 3 - 1
mocka/artefact.py

@@ -5,7 +5,7 @@ from typing import Tuple
 @dataclass
 class Artefact:
     """"""
-    type: str
+    type: str # TODO Create enum with possibilities or maybe Subclasses (InlineArtefact, ...)
     content: str
     name: str
     encoding: str
@@ -23,3 +23,5 @@ class Artefact:
 #     if type and content and encoding:
 #         return Artefact(type, content, encoding)
 #     raise ValueError
+
+# TODO Add a 'set from file' method. It will fill out the attributes and to the base64 stuff if type is inline

+ 2 - 1
mocka/endpoint.py

@@ -4,7 +4,7 @@ import time
 from typing import Any
 from fastapi import FastAPI, Request, Response
 from fastapi.middleware.cors import CORSMiddleware
-from mocka.routers import ExampleRouter, OctivaRouter, TemplateRouter
+from mocka.routers import *
 
 arklog.set_config_logging()
 
@@ -23,6 +23,7 @@ class MockActivityEndpoint(FastAPI):
         self.include_router(ExampleRouter(title=title, description=description, version=version, configuration=configuration))
         self.include_router(OctivaRouter(title=title, description=description, version=version, configuration=configuration), prefix="/octiva")
         self.include_router(TemplateRouter(title=title, description=description, version=version, configuration=configuration), prefix="/template")
+        self.include_router(NotchRouter(title=title, description=description, version=version, configuration=configuration), prefix="/notch")
 
         self.add_middleware(
             CORSMiddleware,

+ 3 - 1
mocka/routers/__init__.py

@@ -1,9 +1,11 @@
 from mocka.routers.octiva import OctivaRouter
 from mocka.routers.template import TemplateRouter
 from mocka.routers.example import ExampleRouter
+from mocka.routers.notch import NotchRouter
 
-all = [
+__all__ = [
     "OctivaRouter",
     "TemplateRouter",
     "ExampleRouter",
+    "NotchRouter",
 ]

+ 136 - 0
mocka/routers/notch.py

@@ -0,0 +1,136 @@
+import base64
+import json
+from pathlib import Path
+from typing import Any
+import arklog
+import magic
+from fastapi import APIRouter, Query, Request, Response
+from fastapi.responses import JSONResponse
+from OMPython import OMCSessionZMQ, ModelicaSystem
+from datetime import datetime
+import struct
+import pyarrow
+from pyarrow import parquet
+
+from mocka.artefact import Artefact
+
+
+def single_simulation_om_python(model_file_path, test_frequency, test_amplitude, sampling_ratio, tolerance, data_cycles, output_stabilisation_time, output):
+    arklog.debug(f"Performing simulation")
+    arklog.debug(f"\t{test_frequency=}")
+    arklog.debug(f"\t{test_amplitude=}")
+    arklog.debug(f"\t{sampling_ratio=}")
+    sampling_frequency = test_frequency * sampling_ratio
+    omc = OMCSessionZMQ()
+    model = ModelicaSystem(str(model_file_path),model_file_path.stem)
+    model.buildModel("(V_in.v)|(V_out.v)")
+    model.setSimulationOptions([
+        f"stepSize={1/sampling_frequency}",
+        f"tolerance={tolerance}",
+        f"startTime={output_stabilisation_time}",
+        f"stopTime={output_stabilisation_time + (data_cycles / test_frequency)}",
+    ])
+    model.setParameters([
+        f"Vt={test_amplitude}",
+        f"Ft={test_frequency}",
+    ])
+    model.simulate()
+    samples = model.getSolutions(output)
+    # for fileName in os.listdir():
+    #     if re.search("notchFilter.*", fileName) and fileName != "notchFilter.mo":
+    #         os.remove(fileName)
+    return save_data(samples, test_frequency, test_amplitude, sampling_ratio, model_file_path)
+
+
+def save_data(samples, test_frequency, test_amplitude, sampling_ratio, file_path):
+    time = datetime.timestamp(datetime.now())
+    common_column_metadata = {
+        "test_frequency": struct.pack("d", test_frequency),
+        "test_amplitude": struct.pack("d", test_amplitude),
+        "sampling_ratio": struct.pack("d", sampling_ratio),
+        "time": struct.pack("d", time),
+        "type": b"input"
+    }
+    input_field = pyarrow.field(f"i_{time}", pyarrow.float64(), False, metadata=common_column_metadata)
+    common_column_metadata["type"]=b"output"
+    output_field = pyarrow.field(f"o_{time}", pyarrow.float64(), False, metadata=common_column_metadata)
+    common_column_metadata["type"]=b"time"
+    time_field = pyarrow.field(f"ft_{time}",pyarrow.float64(), False, metadata=common_column_metadata)
+    # TODO In FTGPM terms we don't want to append to existing experiments
+    storage_file_path = Path(__file__).parent.parent.parent / Path("data") / Path(f"{file_path.stem}_results.parquet")
+    if storage_file_path.exists():
+        experiment_data = parquet.read_table(str(storage_file_path))
+        experiment_data = experiment_data.append_column(time_field, [samples[0]]).append_column(output_field, [samples[1]]).append_column(input_field, [samples[2]])
+    else:
+        experiment_data = pyarrow.Table.from_arrays(samples, schema=pyarrow.schema([time_field, input_field, output_field]))
+    parquet.write_table(experiment_data,str(storage_file_path))
+    return storage_file_path
+
+
+class NotchRouter(APIRouter):
+    """"""
+
+    def __init__(self, *args: Any, title: str, description: str, version: str, configuration, **kwargs: Any):
+        self.title = title
+        self.description = description
+        self.version = version
+        self.configuration = configuration
+        super().__init__(*args, **kwargs)
+
+        @self.get("/simulation/")
+        async def simulation_notch(request: Request, query: str | None = Query(None)) -> Response:
+            """Notch simulation request response for a simulated activity."""
+            body = await request.json()
+            control = body.get("ctrl")
+            # The predefined activity expects the control to be on the cin or rep port.
+            if control not in ["cin"]:
+                return JSONResponse(status_code=400, content={"ctrl": "error", "debug": "This activity expects the control flow input on port 'cin'."})
+            body_artefacts = body.get("input", {})
+            model = body_artefacts.get("model")
+            parameters = body_artefacts.get("parameters")
+            if not model or not parameters:
+                return JSONResponse(status_code=400, content={"ctrl": "error", "debug": "Input artefacts are missing."})
+
+            model_file_path = Path(__file__).parent.parent.parent / Path("data") / Path(model.get("name"))
+            model_file_path.write_text(model.get("content"))
+            parsed_parameters = json.loads(parameters.get("content"))
+            frequency = parsed_parameters.get("frequency")
+            amplitude = parsed_parameters.get("amplitude")
+            sampling_ratio = parsed_parameters.get("sampling_ratio")
+            tolerance = parsed_parameters.get("tolerance")
+            data_cycles = parsed_parameters.get("data_cycles")
+            output_stabilisation_time = parsed_parameters.get("output_stabilisation_time")
+            output = parsed_parameters.get("output")
+            arklog.debug(f"{frequency=}")
+            arklog.debug(f"{amplitude=}")
+            arklog.debug(f"{sampling_ratio=}")
+            arklog.debug(f"{tolerance=}")
+            arklog.debug(f"{data_cycles=}")
+            arklog.debug(f"{output_stabilisation_time=}")
+            arklog.debug(f"{output=}")
+            artefact_file_path = single_simulation_om_python(model_file_path, frequency, amplitude, sampling_ratio, tolerance,data_cycles,output_stabilisation_time, output)
+            data = base64.b64encode(artefact_file_path.read_bytes()).decode()
+            mime = magic.Magic(mime=True).from_file(artefact_file_path)
+            simulation_artefact = Artefact("inline", data, artefact_file_path.name, mime)
+            return JSONResponse(status_code=200, content={"ctrl": "ok", "output": {"experiment": simulation_artefact.as_dict()}})
+
+        @self.put("/simulation/")
+        async def simulation_put_notch(request: Request, query: str | None = Query(None)) -> Response:
+            return await simulation_notch(request, query)
+
+        @self.post("/simulation/")
+        async def simulation_post_notch(request: Request, query: str | None = Query(None)) -> Response:
+            return await simulation_notch(request, query)
+
+        @self.get("/validation/")
+        async def validation_notch(request: Request, query: str | None = Query(None)) -> Response:
+            """Notch simulation request response for a simulated activity."""
+            raise NotImplementedError
+
+        @self.put("/validation/")
+        async def validation_put_notch(request: Request, query: str | None = Query(None)) -> Response:
+            return await validation_notch(request, query)
+
+        @self.post("/validation/")
+        async def validation_post_notch(request: Request, query: str | None = Query(None)) -> Response:
+            return await validation_notch(request, query)

+ 18 - 11
mocka/routers/octiva.py

@@ -8,7 +8,7 @@ import arklog
 from fastapi import APIRouter, Query, Request, Response
 from fastapi.responses import JSONResponse
 import base64
-
+import requests
 from mocka.artefact import Artefact
 
 
@@ -50,9 +50,11 @@ def rail_finder_algo_one(filename: str) -> (Artefact, Artefact):
     # cv.imshow("Probabilistic Line Transform", source_color_image)
     temp_image_loc = Path(__file__).parent.parent.parent / Path("data") / Path("rail_image_annotated.jpg")
     cv.imwrite(str(temp_image_loc), source_color_image)
-    with temp_image_loc.open("rb") as image_file:
-        data = base64.b64encode(image_file.read()).decode()
-    return Artefact("inline", data, "", "base64"), Artefact("inline", f"D: {detected_lines}\nP: {parallel_line_indices}", "", "text/plain")
+
+    # with temp_image_loc.open("rb") as image_file:
+    #     data = base64.b64encode(image_file.read()).decode()
+    # return Artefact("inline", data, "", "base64"), Artefact("inline", f"D: {detected_lines}\nP: {parallel_line_indices}", "", "text/plain")
+    return Artefact("inline", "Hello", "", "text/plain"), Artefact("inline", f"D: {detected_lines}\nP: {parallel_line_indices}", "", "text/plain")
 
 
 def rail_finder_algo_two(filename):
@@ -104,14 +106,19 @@ class OctivaRouter(APIRouter):
             # rail_image = fill_artefact(rail_image_data)
             # algorithm = fill_artefact(algorithm_data)
 
-            # TODO Error checking
-            # rail_image = Image.open(BytesIO(base64.b64decode(rail_image_data.get("content"))))
+            # # TODO Error checking
+            # # rail_image = Image.open(BytesIO(base64.b64decode(rail_image_data.get("content"))))
+            # temp_image_loc = Path(__file__).parent.parent.parent / Path("data") / Path("rail_image.jpg")
+            # # rail_image.save(str(temp_image_loc), temp_image_loc.suffix[1:])
+            # orig = base64.b64decode(rail_image_data.get("content"))
+            # with temp_image_loc.open("wb") as f_output:
+            #     f_output.write(orig)
+            # # TODO Actually use the provided code
+
+            r = requests.get(rail_image_data.get("content"), allow_redirects=True)
             temp_image_loc = Path(__file__).parent.parent.parent / Path("data") / Path("rail_image.jpg")
-            # rail_image.save(str(temp_image_loc), temp_image_loc.suffix[1:])
-            orig = base64.b64decode(rail_image_data.get("content"))
-            with temp_image_loc.open("wb") as f_output:
-                f_output.write(orig)
-            # TODO Actually use the provided code
+            temp_image_loc.write_bytes(r.content)
+
             annotated_image_artefact, data_artefact = rail_finder_algo_one(str(temp_image_loc))
             # mime = magic.Magic(mime=True).from_file(file_path)
             response = {

+ 2 - 0
requirements.txt

@@ -9,6 +9,8 @@ starlette         ~= 0.27.0
 python-magic      ~= 0.4.27
 opencv-python     ~= 4.8.0.76
 uvicorn[standard] ~= 0.23.2
+#pydelica ~= 0.4.5 # VaFL Notch
+ompython ~= 3.4.0 # VaFL Notch
 # Test
 httpx  ~= 0.25.0
 pytest ~= 7.4.0

+ 61 - 0
tests/notch/notchFilter.mo

@@ -0,0 +1,61 @@
+model notchFilter
+// Parameters
+  parameter Modelica.Units.SI.PotentialDifference Vt "testAmplitude";
+  parameter Modelica.Units.SI.Frequency Ft "testFrequency";
+// Components
+  Modelica.Electrical.Analog.Basic.Ground ground_in annotation(
+    Placement(visible = true, transformation(origin = {-80, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Ground ground annotation(
+    Placement(transformation(origin = {28, -18}, extent = {{-10, -10}, {10, 10}})));
+  Modelica.Electrical.Analog.Basic.Ground ground_out annotation(
+    Placement(visible = true, transformation(origin = {80, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Capacitor C1(C(displayUnit = "nF") = 1e-9, v(start = 0)) annotation(
+    Placement(visible = true, transformation(origin = {-20, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Capacitor C2(C(displayUnit = "pF") = 1e-9, v(start = 0)) annotation(
+    Placement(visible = true, transformation(origin = {20, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Capacitor C3(C(displayUnit = "pF") = 2e-9, v(start = 0)) annotation(
+    Placement(visible = true, transformation(origin = {0, 20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
+  Modelica.Electrical.Analog.Basic.Resistor R1(R(displayUnit = "kOhm") = 1600) annotation(
+    Placement(visible = true, transformation(origin = {-20, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Resistor R2(R(displayUnit = "kOhm") = 1600) annotation(
+    Placement(visible = true, transformation(origin = {20, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Basic.Resistor R3a(R(displayUnit = "kOhm") = 1600) annotation(
+    Placement(transformation(origin = {12, -18}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
+  Modelica.Electrical.Analog.Basic.Resistor R3b(R(displayUnit = "kOhm") = 1600) annotation(
+    Placement(transformation(origin = {-12, -18}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
+  Modelica.Electrical.Analog.Sensors.VoltageSensor V_out annotation(
+    Placement(visible = true, transformation(origin = {60, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Electrical.Analog.Sources.SineVoltage V_in(V(displayUnit = "V") = Vt, f(displayUnit = "Hz") = Ft) annotation(
+    Placement(visible = true, transformation(origin = {-60, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
+// Equations
+  equation
+  connect(C3.n, R3a.p) annotation(
+    Line(points = {{0, 10}, {0, -1}, {12, -1}, {12, -8}}, color = {0, 0, 255}));
+  connect(V_out.p, C2.n) annotation(
+    Line(points = {{50, 0}, {40, 0}, {40, -40}, {30, -40}}, color = {0, 0, 255}));
+  connect(R1.n, R2.p) annotation(
+    Line(points = {{-10, 40}, {10, 40}}, color = {0, 0, 255}));
+  connect(C3.p, R2.p) annotation(
+    Line(points = {{0, 30}, {0, 40}, {10, 40}}, color = {0, 0, 255}));
+  connect(V_out.n, ground_out.p) annotation(
+    Line(points = {{70, 0}, {80, 0}, {80, -20}}, color = {0, 0, 255}));
+  connect(V_in.p, C1.p) annotation(
+    Line(points = {{-50, 0}, {-40, 0}, {-40, -40}, {-30, -40}}, color = {0, 0, 255}));
+  connect(R2.n, C2.n) annotation(
+    Line(points = {{30, 40}, {40, 40}, {40, -40}, {30, -40}}, color = {0, 0, 255}));
+  connect(V_in.n, ground_in.p) annotation(
+    Line(points = {{-70, 0}, {-80, 0}, {-80, -20}}, color = {0, 0, 255}));
+  connect(R1.p, C1.p) annotation(
+    Line(points = {{-30, 40}, {-40, 40}, {-40, -40}, {-30, -40}}, color = {0, 0, 255}));
+  connect(R3b.p, C3.n) annotation(
+    Line(points = {{-12, -8}, {-12, -1}, {0, -1}, {0, 10}}, color = {0, 0, 255}));
+  connect(C1.n, C2.p) annotation(
+    Line(points = {{-10, -40}, {10, -40}}, color = {0, 0, 255}));
+  connect(R3a.n, C2.p) annotation(
+    Line(points = {{12, -28}, {12, -32}, {0, -32}, {0, -40}, {10, -40}}, color = {0, 0, 255}));
+  connect(R3b.n, C1.n) annotation(
+    Line(points = {{-12, -28}, {-12, -32}, {0, -32}, {0, -40}, {-10, -40}}, color = {0, 0, 255}));
+  connect(ground.p, C3.n) annotation(
+    Line(points = {{28, -8}, {28, -1}, {0, -1}, {0, 10}}, color = {0, 0, 255}));
+  annotation(uses(Modelica(version = "4.0.0")), Diagram);
+end notchFilter;

+ 49 - 0
tests/test_notch.py

@@ -0,0 +1,49 @@
+import json
+from pathlib import Path
+
+import magic
+from fastapi.testclient import TestClient
+from mocka.main import get_application
+from mocka.configuration import Configuration, Server
+from mocka.artefact import Artefact
+
+client = TestClient(get_application(Configuration(Server("localhost", 8585))))
+
+
+def test_post_octiva():
+    notch_model_file_path = Path(__file__).parent / Path("notch/notchFilter.mo")
+    mime = magic.Magic(mime=True).from_file(notch_model_file_path)
+    model_artefact = Artefact("inline", notch_model_file_path.read_text(), notch_model_file_path.name, mime)
+
+    parameters = {
+        "frequency": 500,
+        "amplitude": 1,
+        "sampling_ratio": 100,
+        "tolerance": 1e-9,
+        "data_cycles": 2,
+        "output_stabilisation_time": 1.0,
+        "output": ["time", "V_out.v","V_in.v"],
+    }
+    parameters_json = json.dumps(parameters, indent=4)
+    parameters_artefact = Artefact("inline", parameters_json, "parameters.json", "application/json")
+    mock_input = {
+        "ctrl": "cin",
+        "input": {
+            "model": model_artefact.as_dict(),
+            "parameters": parameters_artefact.as_dict(),
+        }
+    }
+    response = client.post("/notch/simulation/", json=mock_input)
+    assert response.status_code == 200
+    # orig = base64.b64decode(rail_image_data.get("content"))
+    # with temp_image_loc.open("wb") as f_output:
+    #     f_output.write(orig)
+    # annotated_image_artefact, data_artefact = rail_finder_algo_one(str(temp_image_loc))
+
+    # data_artefact = Artefact("inline", "", "", "text/plain")
+    # assert response.json() ==  {
+    #     "ctrl": "ok",
+    #     "output": {
+    #         "data": data_artefact.as_dict(),
+    #     }
+    # }

+ 2 - 2
tests/test_template.py

@@ -25,7 +25,7 @@ def test_post_template():
     file_path = Path(__file__).parent / Path("template/mock_requirements.txt")
     requirements = file_path.read_text()
     mime = magic.Magic(mime=True).from_file(file_path)
-    input_artefact = Artefact("inline", requirements, str(file_path.name), mime)
+    input_artefact = Artefact("inline", requirements, file_path.name, mime)
 
     mock_input = {
         "ctrl": "cin",
@@ -36,7 +36,7 @@ def test_post_template():
     response = client.post("/template/", json=mock_input)
     assert response.status_code == 200
 
-    expected_artefact = Artefact("inline", requirements + "\n\nChecked!", str(file_path.name), mime)
+    expected_artefact = Artefact("inline", requirements + "\n\nChecked!", file_path.name, mime)
     assert response.json() == {
         "ctrl": "ok",
         "output": {