@@ -1033,7 +1033,7 @@ def _get_multiple(self, path: str, **kwargs) -> dict[str, str]: ...
10331033
10341034 monkeypatch .setitem (parameters .base .DEFAULT_PROVIDERS , "ssm" , TestProvider ())
10351035 monkeypatch .setitem (parameters .base .DEFAULT_PROVIDERS , "secrets" , TestProvider ())
1036- monkeypatch .setitem (parameters .base .DEFAULT_PROVIDERS , "appconfig" , TestProvider ())
1036+ monkeypatch .setitem (parameters .base .DEFAULT_PROVIDERS , "appconfig:test:test " , TestProvider ())
10371037
10381038 parameters .get_parameter (mock_name )
10391039 parameters .get_secret (mock_name )
@@ -3103,7 +3103,7 @@ def _get(self, name: str, **kwargs) -> bytes:
31033103 def _get_multiple (self , path : str , ** kwargs ) -> dict [str , str ]:
31043104 raise NotImplementedError ()
31053105
3106- monkeypatch .setitem (parameters .base .DEFAULT_PROVIDERS , "appconfig" , TestProvider ())
3106+ monkeypatch .setitem (parameters .base .DEFAULT_PROVIDERS , "appconfig:dev:myapp " , TestProvider ())
31073107
31083108 environment = "dev"
31093109 application = "myapp"
@@ -3128,7 +3128,7 @@ def _get(self, name: str, **kwargs) -> str:
31283128 def _get_multiple (self , path : str , ** kwargs ) -> dict [str , str ]:
31293129 raise NotImplementedError ()
31303130
3131- monkeypatch .setitem (parameters .base .DEFAULT_PROVIDERS , "appconfig" , TestProvider ())
3131+ monkeypatch .setitem (parameters .base .DEFAULT_PROVIDERS , "appconfig:dev:myapp " , TestProvider ())
31323132
31333133 environment = "dev"
31343134 application = "myapp"
@@ -3158,10 +3158,36 @@ def _get_multiple(self, path: str, **kwargs) -> dict[str, str]:
31583158 value = parameters .get_app_config (mock_name , environment = "dev" , application = "myapp" )
31593159
31603160 # THEN
3161- assert parameters .appconfig .DEFAULT_PROVIDERS ["appconfig" ] is not None
3161+ assert parameters .appconfig .DEFAULT_PROVIDERS ["appconfig:dev:myapp " ] is not None
31623162 assert value == mock_value
31633163
31643164
3165+ def test_appconf_get_app_config_different_environment_and_application (monkeypatch , mock_name ):
3166+ # GIVEN a provider that reports which environment/application it was built for
3167+ class TestProvider (BaseProvider ):
3168+ def __init__ (self , environment : str , application : str ):
3169+ super ().__init__ ()
3170+ self .environment = environment
3171+ self .application = application
3172+
3173+ def _get (self , name : str , ** kwargs ) -> str :
3174+ return f"{ self .application } /{ self .environment } "
3175+
3176+ def _get_multiple (self , path : str , ** kwargs ) -> dict [str , str ]:
3177+ raise NotImplementedError ()
3178+
3179+ monkeypatch .setattr (parameters .appconfig , "DEFAULT_PROVIDERS" , {})
3180+ monkeypatch .setattr (parameters .appconfig , "AppConfigProvider" , TestProvider )
3181+
3182+ # WHEN get_app_config is called with different applications and environments
3183+ first = parameters .get_app_config (mock_name , environment = "dev" , application = "app-a" , max_age = 0 )
3184+ second = parameters .get_app_config (mock_name , environment = "prod" , application = "app-b" , max_age = 0 )
3185+
3186+ # THEN each call uses its own environment and application
3187+ assert first == "app-a/dev"
3188+ assert second == "app-b/prod"
3189+
3190+
31653191def test_transform_value_auto (mock_value : str ):
31663192 # GIVEN
31673193 json_data = json .dumps ({"A" : mock_value })
0 commit comments