test_image_path.py 1.7 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 pathlib
  12. from taipy.gui import Gui
  13. def test_image_path_not_found(gui: Gui, helpers):
  14. gui.run(run_server=False)
  15. flask_client = gui._server.test_client()
  16. # Get the jsx once so that the page will be evaluated -> variable will be registered
  17. sid = helpers.create_scope_and_get_sid(gui)
  18. ret = flask_client.get(f"/taipy-images/images/img.png?client_id={sid}")
  19. assert ret.status_code == 404
  20. def test_image_path_found(gui: Gui, helpers):
  21. url = gui._get_content(
  22. "img", str((pathlib.Path(__file__).parent.parent.parent / "resources" / "fred.png").resolve()), True
  23. )
  24. gui.run(run_server=False)
  25. flask_client = gui._server.test_client()
  26. # Get the jsx once so that the page will be evaluated -> variable will be registered
  27. sid = helpers.create_scope_and_get_sid(gui)
  28. ret = flask_client.get(f"{url}?client_id={sid}")
  29. assert ret.status_code == 200
  30. def test_image_data_too_big(gui: Gui, helpers):
  31. with open((pathlib.Path(__file__).parent.parent.parent / "resources" / "taipan.jpg"), "rb") as big_file:
  32. url = gui._get_content("img", big_file.read(), True)
  33. assert not url.startswith("data:")