| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | from moto.ssm.utils import convert_to_tree, convert_to_params | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SOURCE_PARAMS = [ | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |         "ARN": ( | 
					
						
							|  |  |  |             "arn:aws:ssm:us-west-1::parameter/aws/service" | 
					
						
							|  |  |  |             "/global-infrastructure/regions/af-south-1" | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |         "DataType": "text", | 
					
						
							|  |  |  |         "Name": "/aws/service/global-infrastructure/regions/af-south-1", | 
					
						
							|  |  |  |         "Type": "String", | 
					
						
							|  |  |  |         "Value": "af-south-1", | 
					
						
							|  |  |  |         "Version": 1, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |         "ARN": ( | 
					
						
							|  |  |  |             "arn:aws:ssm:us-west-1::parameter/aws/service" | 
					
						
							|  |  |  |             "/global-infrastructure/regions/ap-northeast-2" | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |         "DataType": "text", | 
					
						
							|  |  |  |         "Name": "/aws/service/global-infrastructure/regions/ap-northeast-2", | 
					
						
							|  |  |  |         "Type": "String", | 
					
						
							|  |  |  |         "Value": "ap-northeast-2", | 
					
						
							|  |  |  |         "Version": 1, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |         "ARN": ( | 
					
						
							|  |  |  |             "arn:aws:ssm:us-west-1::parameter/aws/service" | 
					
						
							|  |  |  |             "/global-infrastructure/regions/cn-north-1" | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |         "DataType": "text", | 
					
						
							|  |  |  |         "Name": "/aws/service/global-infrastructure/regions/cn-north-1", | 
					
						
							|  |  |  |         "Type": "String", | 
					
						
							|  |  |  |         "Value": "cn-north-1", | 
					
						
							|  |  |  |         "Version": 1, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |         "ARN": ( | 
					
						
							|  |  |  |             "arn:aws:ssm:us-west-1::parameter/aws/service" | 
					
						
							|  |  |  |             "/global-infrastructure/regions/ap-northeast-2/services" | 
					
						
							|  |  |  |             "/codestar-notifications" | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |         "DataType": "text", | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |         "Name": ( | 
					
						
							|  |  |  |             "/aws/service/global-infrastructure/regions" | 
					
						
							|  |  |  |             "/ap-northeast-2/services/codestar-notifications" | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |         "Type": "String", | 
					
						
							|  |  |  |         "Value": "codestar-notifications", | 
					
						
							|  |  |  |         "Version": 1, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EXPECTED_TREE = { | 
					
						
							|  |  |  |     "aws": { | 
					
						
							|  |  |  |         "service": { | 
					
						
							|  |  |  |             "global-infrastructure": { | 
					
						
							|  |  |  |                 "regions": { | 
					
						
							|  |  |  |                     "af-south-1": {"Value": "af-south-1"}, | 
					
						
							|  |  |  |                     "cn-north-1": {"Value": "cn-north-1"}, | 
					
						
							|  |  |  |                     "ap-northeast-2": { | 
					
						
							|  |  |  |                         "Value": "ap-northeast-2", | 
					
						
							|  |  |  |                         "services": { | 
					
						
							|  |  |  |                             "codestar-notifications": { | 
					
						
							|  |  |  |                                 "Value": "codestar-notifications" | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CONVERTED_PARAMS = [ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         "Name": "/aws/service/global-infrastructure/regions/af-south-1", | 
					
						
							|  |  |  |         "Value": "af-south-1", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         "Name": "/aws/service/global-infrastructure/regions/cn-north-1", | 
					
						
							|  |  |  |         "Value": "cn-north-1", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         "Name": "/aws/service/global-infrastructure/regions/ap-northeast-2", | 
					
						
							|  |  |  |         "Value": "ap-northeast-2", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |         "Name": ( | 
					
						
							|  |  |  |             "/aws/service/global-infrastructure/regions/ap-northeast-2" | 
					
						
							|  |  |  |             "/services/codestar-notifications" | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |         "Value": "codestar-notifications", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_convert_to_tree(): | 
					
						
							|  |  |  |     tree = convert_to_tree(SOURCE_PARAMS) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert tree == EXPECTED_TREE | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_convert_to_params(): | 
					
						
							|  |  |  |     actual = convert_to_params(EXPECTED_TREE) | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert len(actual) == len(CONVERTED_PARAMS) | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |     for param in CONVERTED_PARAMS: | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |         assert param in actual | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_input_is_correct(): | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     """Test input should match.""" | 
					
						
							| 
									
										
										
										
											2022-02-12 12:59:15 -01:00
										 |  |  |     for src in SOURCE_PARAMS: | 
					
						
							|  |  |  |         minimized_src = {"Name": src["Name"], "Value": src["Value"]} | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |         assert minimized_src in CONVERTED_PARAMS |