test_multiple_instances.py 1.4 KB

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