test_user_content.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. import pytest
  13. from taipy.gui import Gui
  14. def test_user_content_without_callback(gui: Gui, helpers):
  15. gui.run(run_server=False, single_client=True)
  16. server_client = gui._server.test_client()
  17. with pytest.warns(UserWarning):
  18. ret = server_client.get(gui._get_user_content_url("path"))
  19. assert ret.status_code == 404
  20. def test_user_content_with_wrong_callback(gui: Gui, helpers):
  21. def on_user_content_cb(state, path, args):
  22. return None
  23. on_user_content = on_user_content_cb # noqa: F841
  24. gui._set_frame(inspect.currentframe())
  25. gui.run(run_server=False, single_client=True)
  26. server_client = gui._server.test_client()
  27. with pytest.warns(UserWarning):
  28. ret = server_client.get(gui._get_user_content_url("path", {"a": "b"}))
  29. assert ret.status_code == 404
  30. def test_user_content_with_callback(gui: Gui, helpers):
  31. def on_user_content_cb(state, path, args):
  32. return ""
  33. on_user_content = on_user_content_cb # noqa: F841
  34. gui._set_frame(inspect.currentframe())
  35. gui.run(run_server=False, single_client=True)
  36. server_client = gui._server.test_client()
  37. ret = server_client.get(gui._get_user_content_url("path"))
  38. assert ret.status_code == 200