test_partial.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 warnings
  12. from types import SimpleNamespace
  13. from taipy.gui import Gui, Markdown
  14. def test_partial(gui: Gui, helpers):
  15. with warnings.catch_warnings(record=True):
  16. gui.add_partial(Markdown("#This is a partial"))
  17. gui.run(run_server=False)
  18. client = gui._server.test_client()
  19. response = client.get(f"/taipy-jsx/{gui._config.partial_routes[0]}")
  20. response_data = helpers.get_response_data(response)
  21. assert response.status_code == 200
  22. assert "jsx" in response_data and "This is a partial" in response_data["jsx"]
  23. def test_partial_update(gui: Gui, helpers):
  24. with warnings.catch_warnings(record=True):
  25. partial = gui.add_partial(Markdown("#This is a partial"))
  26. gui.run(run_server=False, single_client=True)
  27. client = gui._server.test_client()
  28. response = client.get(f"/taipy-jsx/{gui._config.partial_routes[0]}")
  29. response_data = helpers.get_response_data(response)
  30. assert response.status_code == 200
  31. assert "jsx" in response_data and "This is a partial" in response_data["jsx"]
  32. # update partial
  33. fake_state = SimpleNamespace()
  34. fake_state._gui = gui
  35. partial.update_content(fake_state, "#partial updated") # type: ignore
  36. response = client.get(f"/taipy-jsx/{gui._config.partial_routes[0]}")
  37. response_data = helpers.get_response_data(response)
  38. assert response.status_code == 200
  39. assert "jsx" in response_data and "partial updated" in response_data["jsx"]