test_status.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. import inspect
  12. from unittest.mock import patch
  13. from taipy.gui import Gui
  14. def test_get_status(gui: Gui):
  15. with patch("sys.argv", ["prog"]):
  16. gui.run(run_server=False)
  17. flask_client = gui._server.test_client()
  18. ret = flask_client.get("/taipy.status.json")
  19. assert ret.status_code == 200, f"status_code => {ret.status_code} != 200"
  20. assert ret.mimetype == "application/json", f"mimetype => {ret.mimetype} != application/json"
  21. assert ret.json, "json is not defined"
  22. assert "gui" in ret.json, "json has no key gui"
  23. gui = ret.json.get("gui")
  24. assert isinstance(gui, dict), "json.gui is not a dict"
  25. assert "user_status" in gui, "json.gui has no key user_status"
  26. assert gui.get("user_status") == "", "json.gui.user_status is not empty"
  27. def test_get_extended_status(gui: Gui):
  28. with patch("sys.argv", ["prog"]):
  29. gui.run(run_server=False, extended_status=True)
  30. flask_client = gui._server.test_client()
  31. ret = flask_client.get("/taipy.status.json")
  32. assert ret.status_code == 200, f"status_code => {ret.status_code} != 200"
  33. assert ret.mimetype == "application/json", f"mimetype => {ret.mimetype} != application/json"
  34. assert ret.json, "json is not defined"
  35. gui_ret = ret.json.get("gui")
  36. assert "backend_version" in gui_ret, "json.gui has no key backend_version"
  37. assert "flask_version" in gui_ret, "json.gui has no key flask_version"
  38. assert "frontend_version" in gui_ret, "json.gui has no key frontend_version"
  39. assert "host" in gui_ret, "json.gui has no key host"
  40. assert "python_version" in gui_ret, "json.gui has no key python_version"
  41. assert "user_status" in gui_ret, "json.gui has no key user_status"
  42. assert gui_ret.get("user_status") == "", "json.gui.user_status is not empty"
  43. def test_get_status_with_user_status(gui: Gui):
  44. user_status = "user_status"
  45. def on_status(state):
  46. return user_status
  47. gui._set_frame(inspect.currentframe())
  48. with patch("sys.argv", ["prog"]):
  49. gui.run(run_server=False)
  50. flask_client = gui._server.test_client()
  51. ret = flask_client.get("/taipy.status.json")
  52. assert ret.status_code == 200, f"status_code => {ret.status_code} != 200"
  53. assert ret.json, "json is not defined"
  54. gui_ret = ret.json.get("gui")
  55. assert "user_status" in gui_ret, "json.gui has no key user_status"
  56. assert gui_ret.get("user_status") == user_status
  57. assert f'json.gui.user_status => {gui_ret.get("user_status")} != {user_status}'