test_extension.py 1.4 KB

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