test_multiple_instances.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  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. from taipy.gui.gui import Gui
  13. def test_multiple_instance():
  14. gui1 = Gui("<|gui1|>")
  15. gui2 = Gui("<|gui2|>")
  16. gui1.run(run_server=False)
  17. gui2.run(run_server=False)
  18. client1 = gui1._server.test_client()
  19. client2 = gui2._server.test_client()
  20. assert_multiple_instance(client1, 'value="gui1"')
  21. assert_multiple_instance(client2, 'value="gui2"')
  22. def assert_multiple_instance(client, expected_value):
  23. response = client.get("/taipy-jsx/TaiPy_root_page")
  24. response_data = json.loads(response.get_data().decode("utf-8", "ignore"))
  25. assert response.status_code == 200
  26. assert isinstance(response_data, dict)
  27. assert "jsx" in response_data
  28. assert expected_value in response_data["jsx"]