test_template.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from pathlib import Path
  2. import magic
  3. from fastapi.testclient import TestClient
  4. from mocka.artefact import Artefact
  5. from mocka.main import get_application
  6. from mocka.configuration import Configuration, Server
  7. client = TestClient(get_application(Configuration(Server("localhost", 8585))))
  8. # def test_read_main():
  9. # response = client.get("/", headers={})
  10. # assert response.status_code == 201
  11. # assert response.json() == {
  12. # "port": "ok",
  13. # "output": {
  14. # "artefact_1": "<uri>",
  15. # "artefact_2": "<uri>",
  16. # }
  17. # }
  18. def test_post_template():
  19. file_path = Path(__file__).parent / Path("template/mock_requirements.txt")
  20. requirements = file_path.read_text()
  21. mime = magic.Magic(mime=True).from_file(file_path)
  22. input_artefact = Artefact("inline", requirements, file_path.name, mime)
  23. mock_input = {
  24. "ctrl": "cin",
  25. "input": {
  26. "din": input_artefact.as_dict()
  27. }
  28. }
  29. response = client.post("/template/", json=mock_input)
  30. assert response.status_code == 200
  31. expected_artefact = Artefact("inline", requirements + "\n\nChecked!", file_path.name, mime)
  32. assert response.json() == {
  33. "ctrl": "ok",
  34. "output": {
  35. "dout": expected_artefact.as_dict()
  36. }
  37. }