test_status.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright 2021-2025 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 os import path
  13. from taipy.gui import Gui
  14. def test_get_status(gui: Gui):
  15. gui.run(run_server=False)
  16. flask_client = gui._server.test_client()
  17. ret = flask_client.get("/taipy.status.json")
  18. assert ret.status_code == 200, f"status_code => {ret.status_code} != 200"
  19. assert ret.mimetype == "application/json", f"mimetype => {ret.mimetype} != application/json"
  20. assert ret.json, "json is not defined"
  21. assert "gui" in ret.json, "json has no key gui"
  22. gui = ret.json.get("gui")
  23. assert isinstance(gui, dict), "json.gui is not a dict"
  24. assert "user_status" in gui, "json.gui has no key user_status"
  25. assert gui.get("user_status") == "", "json.gui.user_status is not empty"
  26. def test_get_extended_status(gui: Gui):
  27. gui.run(run_server=False, extended_status=True)
  28. flask_client = gui._server.test_client()
  29. ret = flask_client.get("/taipy.status.json")
  30. assert ret.status_code == 200, f"status_code => {ret.status_code} != 200"
  31. assert ret.mimetype == "application/json", f"mimetype => {ret.mimetype} != application/json"
  32. assert ret.json, "json is not defined"
  33. gui_json = ret.json.get("gui")
  34. assert "backend_version" in gui_json, "json.gui has no key backend_version"
  35. assert "flask_version" in gui_json, "json.gui has no key flask_version"
  36. if path.exists(gui._get_webapp_path()):
  37. assert "frontend_version" in gui_json, "json.gui has no key frontend_version"
  38. assert "host" in gui_json, "json.gui has no key host"
  39. assert "python_version" in gui_json, "json.gui has no key python_version"
  40. assert "user_status" in gui_json, "json.gui has no key user_status"
  41. assert gui_json.get("user_status") == "", "json.gui.user_status is not empty"
  42. def test_get_status_with_user_status(gui: Gui):
  43. user_status = "user_status"
  44. def on_status(state):
  45. return user_status
  46. gui._set_frame(inspect.currentframe())
  47. gui.run(run_server=False)
  48. flask_client = gui._server.test_client()
  49. ret = flask_client.get("/taipy.status.json")
  50. assert ret.status_code == 200, f"status_code => {ret.status_code} != 200"
  51. assert ret.json, "json is not defined"
  52. gui_ret = ret.json.get("gui")
  53. assert "user_status" in gui_ret, "json.gui has no key user_status"
  54. assert gui_ret.get("user_status") == user_status
  55. assert f'json.gui.user_status => {gui_ret.get("user_status")} != {user_status}'