test_partial.py 2.1 KB

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