소스 검색

Shorten artefact preparation code

Arkadiusz Ryś 2 년 전
부모
커밋
12baefb3cf
2개의 변경된 파일9개의 추가작업 그리고 42개의 파일을 삭제
  1. 5 17
      mocka/routers/octiva.py
  2. 4 25
      tests/test_octiva.py

+ 5 - 17
mocka/routers/octiva.py

@@ -12,8 +12,6 @@ import base64
 from mocka.artefact import Artefact
 
 
-
-
 def find_parallel(lines) -> []:
     """Find parallel lines and return their index."""
     parallel_lines = []
@@ -95,9 +93,9 @@ class OctivaRouter(APIRouter):
             # TODO Change some of this to use buffers instead of files
             body = await request.json()
             control = body.get("ctrl")
-            # The predefined activity expects the control to be on the cin 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'."})
+            # The predefined activity expects the control to be on the cin or rep port.
+            if control not in ["cin", "rep"]:
+                return JSONResponse(status_code=400, content={"ctrl": "error", "debug": "This activity expects the control flow input on port 'cin' or 'rep'."})
             body_artefacts = body.get("input", {})
             rail_image_data = body_artefacts.get("image")
             algorithm_data = body_artefacts.get("algorithm")
@@ -119,18 +117,8 @@ class OctivaRouter(APIRouter):
             response = {
                 "ctrl": "ok",
                 "output": {
-                    "image": {
-                        "type": annotated_image_artefact.type,
-                        "content": annotated_image_artefact.content,
-                        "name": annotated_image_artefact.name,
-                        "encoding": annotated_image_artefact.encoding
-                    },
-                    "data": {
-                        "type": data_artefact.type,
-                        "content": data_artefact.content,
-                        "name": data_artefact.name,
-                        "encoding": data_artefact.encoding
-                    },
+                    "image": annotated_image_artefact.as_dict(),
+                    "data": data_artefact.as_dict()
                 }
             }
             return JSONResponse(status_code=200, content=response)

+ 4 - 25
tests/test_octiva.py

@@ -56,22 +56,11 @@ def test_post_octiva():
     data = base64.b64encode(buffer).decode()
     image_artefact = Artefact("inline", data, "", "base64")
     algo_artefact = Artefact("inline", f"print('hello')", "", "text/plain")
-
     mock_input = {
         "ctrl": "cin",
         "input": {
-            "image": {
-                "type": image_artefact.type,
-                "content": image_artefact.content,
-                "name": image_artefact.name,
-                "encoding": image_artefact.encoding,
-            },
-            "algorithm": {
-                "type": algo_artefact.type,
-                "content": algo_artefact.content,
-                "name": algo_artefact.name,
-                "encoding": algo_artefact.encoding,
-            },
+            "image": image_artefact.as_dict(),
+            "algorithm": algo_artefact.as_dict(),
         }
     }
     response = client.post("/octiva/", json=mock_input)
@@ -86,17 +75,7 @@ def test_post_octiva():
     assert response.json() ==  {
         "ctrl": "ok",
         "output": {
-            "image": {
-                "type": annotated_image_artefact.type,
-                "content": annotated_image_artefact.content,
-                "name": annotated_image_artefact.name,
-                "encoding": annotated_image_artefact.encoding
-            },
-            "data": {
-                "type": data_artefact.type,
-                "content": data_artefact.content,
-                "name": data_artefact.name,
-                "encoding": data_artefact.encoding
-            },
+            "image": annotated_image_artefact.as_dict(),
+            "data": data_artefact.as_dict(),
         }
     }