test_StatusModel.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import pytest
  2. import json
  3. import sys
  4. import os
  5. sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
  6. from models.StatusModel import StatusModel
  7. def test_model():
  8. # Create an instance of StatusModel
  9. model = StatusModel()
  10. # Test the parser_command attribute
  11. assert model.parser_command == "status", "Parser command should be 'status'"
  12. # 1. Status version tests
  13. r_version = model.version()
  14. assert isinstance(r_version, dict), f"Expected a dict but received: {json.dumps(r_version, indent=2)}"
  15. assert "version" in r_version, f"'version' key missing in response: {json.dumps(r_version, indent=2)}"
  16. # 2. Status vmail tests
  17. r_vmail = model.vmail()
  18. assert isinstance(r_vmail, dict), f"Expected a dict but received: {json.dumps(r_vmail, indent=2)}"
  19. assert "type" in r_vmail, f"'type' key missing in response: {json.dumps(r_vmail, indent=2)}"
  20. assert "disk" in r_vmail, f"'disk' key missing in response: {json.dumps(r_vmail, indent=2)}"
  21. assert "used" in r_vmail, f"'used' key missing in response: {json.dumps(r_vmail, indent=2)}"
  22. assert "total" in r_vmail, f"'total' key missing in response: {json.dumps(r_vmail, indent=2)}"
  23. assert "used_percent" in r_vmail, f"'used_percent' key missing in response: {json.dumps(r_vmail, indent=2)}"
  24. # 3. Status containers tests
  25. r_containers = model.containers()
  26. assert isinstance(r_containers, dict), f"Expected a dict but received: {json.dumps(r_containers, indent=2)}"
  27. if __name__ == "__main__":
  28. print("Running StatusModel tests...")
  29. test_model()
  30. print("All tests passed!")