@@ -138,3 +138,37 @@ def test_avoid_sensitive_info_in_public(app_settings: ApplicationSettings):
138138 assert not any ("token" in key for key in app_settings .public_dict ())
139139 assert not any ("secret" in key for key in app_settings .public_dict ())
140140 assert not any ("private" in key for key in app_settings .public_dict ())
141+
142+
143+ def test_backwards_compatibility_with_bool_env_vars_turned_into_objects (
144+ monkeypatch : pytest .MonkeyPatch ,
145+ mock_webserver_service_environment : EnvVarsDict ,
146+ ):
147+ # Sometimes we turn `WEBSERVER_VAR: bool` into `WEBSERVER_VAR: VarSettings`
148+ with monkeypatch .context () as patch :
149+ patch .setenv ("WEBSERVER_LICENSES" , "true" )
150+
151+ settings = ApplicationSettings .create_from_envs ()
152+ assert settings .WEBSERVER_LICENSES is True
153+
154+ with monkeypatch .context () as patch :
155+ patch .setenv ("WEBSERVER_LICENSES" , "{}" )
156+ patch .setenv ("LICENSES_ITIS_VIP_SYNCER_ENABLED" , "1" )
157+ patch .setenv ("LICENSES_ITIS_VIP_API_URL" , "https://some-api/{category}" )
158+ patch .setenv (
159+ "LICENSES_ITIS_VIP_CATEGORIES" ,
160+ '{"HumanWholeBody": "Humans", "HumanBodyRegion": "Humans (Region)", "AnimalWholeBody": "Animal"}' ,
161+ )
162+
163+ settings = ApplicationSettings .create_from_envs ()
164+ assert settings .WEBSERVER_LICENSES is not None
165+ assert not isinstance (settings .WEBSERVER_LICENSES , bool )
166+ assert settings .WEBSERVER_LICENSES .LICENSES_ITIS_VIP
167+ assert settings .WEBSERVER_LICENSES .LICENSES_ITIS_VIP .LICENSES_ITIS_VIP_API_URL
168+ assert settings .WEBSERVER_LICENSES .LICENSES_ITIS_VIP_SYNCER_ENABLED
169+
170+ with monkeypatch .context () as patch :
171+ patch .setenv ("WEBSERVER_LICENSES" , "null" )
172+
173+ settings = ApplicationSettings .create_from_envs ()
174+ assert settings .WEBSERVER_LICENSES is None
0 commit comments