test_mock.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. file_path = Path(__file__).parent.parent / Path("data/mock_requirements.txt")
  18. requirements = file_path.read_text()
  19. mock_input = {
  20. "ctrl": "cin",
  21. "input": {
  22. "din": {
  23. "type": "inline",
  24. "content": requirements,
  25. "encoding": "text/plain"
  26. }
  27. }
  28. }
  29. response = client.post("/", json=mock_input)
  30. assert response.status_code == 200
  31. assert response.json() == {
  32. "ctrl": "ok",
  33. "output": {
  34. "dout": {
  35. "type": "inline",
  36. "content": requirements + "\n\nChecked!",
  37. "name": file_path.name,
  38. "encoding": "text/plain"
  39. }
  40. }
  41. }