test_global_app_config.py 1.6 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 os
  12. from unittest import mock
  13. import pytest
  14. from taipy.config.config import Config
  15. from taipy.config.exceptions.exceptions import ConfigurationUpdateBlocked
  16. def test_global_config_with_env_variable_value():
  17. with mock.patch.dict(os.environ, {"FOO": "bar", "BAZ": "qux"}):
  18. Config.configure_global_app(foo="ENV[FOO]", bar="ENV[BAZ]")
  19. assert Config.global_config.foo == "bar"
  20. assert Config.global_config.bar == "qux"
  21. def test_default_global_app_config():
  22. global_config = Config.global_config
  23. assert global_config is not None
  24. assert not global_config.notification
  25. assert len(global_config.properties) == 0
  26. def test_block_update_global_app_config():
  27. Config.block_update()
  28. with pytest.raises(ConfigurationUpdateBlocked):
  29. Config.configure_global_app(foo="bar")
  30. with pytest.raises(ConfigurationUpdateBlocked):
  31. Config.global_config.properties = {"foo": "bar"}
  32. # Test if the global_config stay as default
  33. assert Config.global_config.foo is None
  34. assert len(Config.global_config.properties) == 0