test_mock.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from pathlib import Path
  2. from fastapi.testclient import TestClient
  3. from mocka.main import get_application
  4. from mocka.configuration import Configuration, Server
  5. client = TestClient(get_application(Configuration(Server("localhost", 8585))))
  6. # def test_read_main():
  7. # response = client.get("/", headers={})
  8. # assert response.status_code == 201
  9. # assert response.json() == {
  10. # "port": "ok",
  11. # "output": {
  12. # "artefact_1": "<uri>",
  13. # "artefact_2": "<uri>",
  14. # }
  15. # }
  16. def test_post_main():
  17. requirements = (Path(__file__).parent.parent / Path("data/mock_requirements.txt")).read_text()
  18. mock_input = {
  19. "ctrl": "cin",
  20. "input": {
  21. "din": {
  22. "type": "inline",
  23. "content": requirements,
  24. "encoding": "text/plain"
  25. }
  26. }
  27. }
  28. response = client.post("/", json=mock_input)
  29. assert response.status_code == 201
  30. assert response.json() == {
  31. "ctrl": "ok",
  32. "output": {
  33. "dout": {
  34. "type": "inline",
  35. "content": requirements + "\n\nChecked!",
  36. "encoding": "text/plain"
  37. }
  38. }
  39. }