test_extension.py 1.5 KB

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