| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | from moto.ssm.models import ParameterDict | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_simple_setget(): | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  |     store = ParameterDict("accnt", "region") | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |     store["/a/b/c"] = "some object" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert store.get("/a/b/c") == "some object" | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_get_none(): | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  |     store = ParameterDict("accnt", "region") | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert store.get(None) is None | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_get_aws_param(): | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  |     store = ParameterDict("accnt", "region") | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     p = store["/aws/service/global-infrastructure/regions/us-west-1/longName"] | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert len(p) == 1 | 
					
						
							|  |  |  |     assert p[0].value == "US West (N. California)" | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_iter(): | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  |     store = ParameterDict("accnt", "region") | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |     store["/a/b/c"] = "some object" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert "/a/b/c" in store | 
					
						
							|  |  |  |     assert "/a/b/d" not in store | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_iter_none(): | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  |     store = ParameterDict("accnt", "region") | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert None not in store | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_iter_aws(): | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  |     store = ParameterDict("accnt", "region") | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert "/aws/service/global-infrastructure/regions/us-west-1/longName" in store | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_get_key_beginning_with(): | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  |     store = ParameterDict("accnt", "region") | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |     store["/a/b/c"] = "some object" | 
					
						
							|  |  |  |     store["/b/c/d"] = "some other object" | 
					
						
							|  |  |  |     store["/a/c/d"] = "some third object" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  |     begins_with_ab = list(store.get_keys_beginning_with("/a/b", recursive=False)) | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert begins_with_ab == ["/a/b/c"] | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  |     begins_with_a = list(store.get_keys_beginning_with("/a", recursive=False)) | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert not begins_with_a | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  |     begins_with_a_recursive = list(store.get_keys_beginning_with("/a", recursive=True)) | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert set(begins_with_a_recursive) == {"/a/b/c", "/a/c/d"} | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_get_key_beginning_with_aws(): | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     """Test ParameterDict loads default params for key starting with '/aws'.""" | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  |     store = ParameterDict("accnt", "region") | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     uswest_params = set( | 
					
						
							|  |  |  |         store.get_keys_beginning_with( | 
					
						
							|  |  |  |             "/aws/service/global-infrastructure/regions/us-west-1", recursive=False | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert uswest_params == { | 
					
						
							|  |  |  |         "/aws/service/global-infrastructure/regions/us-west-1", | 
					
						
							|  |  |  |         "/aws/service/global-infrastructure/regions/us-west-1/domain", | 
					
						
							|  |  |  |         "/aws/service/global-infrastructure/regions/us-west-1/geolocationCountry", | 
					
						
							|  |  |  |         "/aws/service/global-infrastructure/regions/us-west-1/geolocationRegion", | 
					
						
							|  |  |  |         "/aws/service/global-infrastructure/regions/us-west-1/longName", | 
					
						
							|  |  |  |         "/aws/service/global-infrastructure/regions/us-west-1/partition", | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-08-28 22:30:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_ssm_parameter_from_unknown_region(): | 
					
						
							|  |  |  |     store = ParameterDict("accnt", "region") | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert not list( | 
					
						
							| 
									
										
										
										
											2022-08-28 22:30:11 +00:00
										 |  |  |         store.get_keys_beginning_with( | 
					
						
							|  |  |  |             "/aws/service/ami-amazon-linux-latest", recursive=False | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     ) |