from pathlib import Path import magic from fastapi.testclient import TestClient from mocka.artefact import Artefact from mocka.main import get_application from mocka.configuration import Configuration, Server client = TestClient(get_application(Configuration(Server("localhost", 8585)))) # def test_read_main(): # response = client.get("/", headers={}) # assert response.status_code == 201 # assert response.json() == { # "port": "ok", # "output": { # "artefact_1": "", # "artefact_2": "", # } # } 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, file_path.name, mime) mock_input = { "ctrl": "cin", "input": { "din": input_artefact.as_dict() } } response = client.post("/template/", json=mock_input) assert response.status_code == 200 expected_artefact = Artefact("inline", requirements + "\n\nChecked!", file_path.name, mime) assert response.json() == { "ctrl": "ok", "output": { "dout": expected_artefact.as_dict() } }