test_extension.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright 2023 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. import pytest
  14. from taipy.gui import Gui
  15. from taipy.gui.extension import Element, ElementLibrary
  16. class MyLibrary(ElementLibrary):
  17. def get_name(self) -> str:
  18. return "taipy_extension_example"
  19. def get_elements(self):
  20. return dict()
  21. def test_extension_no_config(gui: Gui, helpers):
  22. with patch("sys.argv", ["prog"]):
  23. gui.run(run_server=False, single_client=True)
  24. flask_client = gui._server.test_client()
  25. with pytest.warns(UserWarning):
  26. ret = flask_client.get("/taipy-extension/toto/titi")
  27. assert ret.status_code == 404
  28. def test_extension_config_wrong_path(gui: Gui, helpers):
  29. Gui.add_library(MyLibrary())
  30. with patch("sys.argv", ["prog"]):
  31. gui.run(run_server=False, single_client=True)
  32. flask_client = gui._server.test_client()
  33. with pytest.warns(UserWarning):
  34. ret = flask_client.get("/taipy-extension/taipy_extension_example/titi")
  35. assert ret.status_code == 404