| 
									
										
										
										
											2019-09-03 14:54:46 +02:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2019-09-03 16:10:32 +02:00
										 |  |  | from botocore.exceptions import ClientError | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 14:08:22 +01:00
										 |  |  | from moto import mock_elasticbeanstalk | 
					
						
							| 
									
										
										
										
											2019-09-03 14:54:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 14:08:22 +01:00
										 |  |  | @mock_elasticbeanstalk | 
					
						
							| 
									
										
										
										
											2019-09-03 16:10:32 +02:00
										 |  |  | def test_create_application(): | 
					
						
							| 
									
										
										
										
											2019-09-03 14:54:46 +02:00
										 |  |  |     # Create Elastic Beanstalk Application | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     conn = boto3.client("elasticbeanstalk", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     app = conn.create_application(ApplicationName="myapp") | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     app["Application"]["ApplicationName"].should.equal("myapp") | 
					
						
							| 
									
										
										
										
											2020-12-04 02:31:28 -08:00
										 |  |  |     app["Application"]["ApplicationArn"].should.contain("myapp") | 
					
						
							| 
									
										
										
										
											2019-09-03 16:10:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 14:08:22 +01:00
										 |  |  | @mock_elasticbeanstalk | 
					
						
							| 
									
										
										
										
											2019-09-03 16:10:32 +02:00
										 |  |  | def test_create_application_dup(): | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     conn = boto3.client("elasticbeanstalk", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     conn.create_application(ApplicationName="myapp") | 
					
						
							|  |  |  |     conn.create_application.when.called_with(ApplicationName="myapp").should.throw( | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |         ClientError | 
					
						
							| 
									
										
										
										
											2019-09-03 16:10:32 +02:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-09-03 14:54:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-03 16:10:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 14:08:22 +01:00
										 |  |  | @mock_elasticbeanstalk | 
					
						
							| 
									
										
										
										
											2019-09-03 16:10:32 +02:00
										 |  |  | def test_describe_applications(): | 
					
						
							|  |  |  |     # Create Elastic Beanstalk Application | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     conn = boto3.client("elasticbeanstalk", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     conn.create_application(ApplicationName="myapp") | 
					
						
							| 
									
										
										
										
											2019-09-03 14:54:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-03 16:10:32 +02:00
										 |  |  |     apps = conn.describe_applications() | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     len(apps["Applications"]).should.equal(1) | 
					
						
							|  |  |  |     apps["Applications"][0]["ApplicationName"].should.equal("myapp") | 
					
						
							| 
									
										
										
										
											2020-12-04 02:31:28 -08:00
										 |  |  |     apps["Applications"][0]["ApplicationArn"].should.contain("myapp") | 
					
						
							| 
									
										
										
										
											2019-09-04 15:33:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 14:08:22 +01:00
										 |  |  | @mock_elasticbeanstalk | 
					
						
							| 
									
										
										
										
											2019-09-04 15:33:15 +02:00
										 |  |  | def test_create_environment(): | 
					
						
							|  |  |  |     # Create Elastic Beanstalk Environment | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     conn = boto3.client("elasticbeanstalk", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  |     conn.create_application(ApplicationName="myapp") | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     env = conn.create_environment(ApplicationName="myapp", EnvironmentName="myenv") | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     env["EnvironmentName"].should.equal("myenv") | 
					
						
							| 
									
										
										
										
											2021-02-17 01:06:22 -08:00
										 |  |  |     env["EnvironmentArn"].should.contain("myapp/myenv") | 
					
						
							| 
									
										
										
										
											2019-09-04 15:33:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 14:08:22 +01:00
										 |  |  | @mock_elasticbeanstalk | 
					
						
							| 
									
										
										
										
											2019-09-04 15:33:15 +02:00
										 |  |  | def test_describe_environments(): | 
					
						
							|  |  |  |     # List Elastic Beanstalk Envs | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     conn = boto3.client("elasticbeanstalk", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     conn.create_application(ApplicationName="myapp") | 
					
						
							|  |  |  |     conn.create_environment(ApplicationName="myapp", EnvironmentName="myenv") | 
					
						
							| 
									
										
										
										
											2019-09-04 15:33:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     envs = conn.describe_environments() | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     envs = envs["Environments"] | 
					
						
							| 
									
										
										
										
											2019-09-04 15:33:15 +02:00
										 |  |  |     len(envs).should.equal(1) | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     envs[0]["ApplicationName"].should.equal("myapp") | 
					
						
							|  |  |  |     envs[0]["EnvironmentName"].should.equal("myenv") | 
					
						
							| 
									
										
										
										
											2021-02-17 01:06:22 -08:00
										 |  |  |     envs[0]["EnvironmentArn"].should.contain("myapp/myenv") | 
					
						
							| 
									
										
										
										
											2019-09-04 15:33:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  | def tags_dict_to_list(tag_dict): | 
					
						
							|  |  |  |     tag_list = [] | 
					
						
							|  |  |  |     for key, value in tag_dict.items(): | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |         tag_list.append({"Key": key, "Value": value}) | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  |     return tag_list | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def tags_list_to_dict(tag_list): | 
					
						
							|  |  |  |     tag_dict = {} | 
					
						
							|  |  |  |     for tag in tag_list: | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |         tag_dict[tag["Key"]] = tag["Value"] | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  |     return tag_dict | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 14:08:22 +01:00
										 |  |  | @mock_elasticbeanstalk | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  | def test_create_environment_tags(): | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     conn = boto3.client("elasticbeanstalk", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     conn.create_application(ApplicationName="myapp") | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     env_tags = {"initial key": "initial value"} | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  |     env = conn.create_environment( | 
					
						
							|  |  |  |         ApplicationName="myapp", | 
					
						
							|  |  |  |         EnvironmentName="myenv", | 
					
						
							|  |  |  |         Tags=tags_dict_to_list(env_tags), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     tags = conn.list_tags_for_resource(ResourceArn=env["EnvironmentArn"]) | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     tags["ResourceArn"].should.equal(env["EnvironmentArn"]) | 
					
						
							|  |  |  |     tags_list_to_dict(tags["ResourceTags"]).should.equal(env_tags) | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 14:08:22 +01:00
										 |  |  | @mock_elasticbeanstalk | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  | def test_update_tags(): | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     conn = boto3.client("elasticbeanstalk", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     conn.create_application(ApplicationName="myapp") | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  |     env_tags = { | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |         "initial key": "initial value", | 
					
						
							|  |  |  |         "to remove": "delete me", | 
					
						
							|  |  |  |         "to update": "original", | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     env = conn.create_environment( | 
					
						
							|  |  |  |         ApplicationName="myapp", | 
					
						
							|  |  |  |         EnvironmentName="myenv", | 
					
						
							|  |  |  |         Tags=tags_dict_to_list(env_tags), | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     extra_env_tags = { | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |         "to update": "new", | 
					
						
							|  |  |  |         "extra key": "extra value", | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     conn.update_tags_for_resource( | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |         ResourceArn=env["EnvironmentArn"], | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  |         TagsToAdd=tags_dict_to_list(extra_env_tags), | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |         TagsToRemove=["to remove"], | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     total_env_tags = env_tags.copy() | 
					
						
							|  |  |  |     total_env_tags.update(extra_env_tags) | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     del total_env_tags["to remove"] | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     tags = conn.list_tags_for_resource(ResourceArn=env["EnvironmentArn"]) | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     tags["ResourceArn"].should.equal(env["EnvironmentArn"]) | 
					
						
							|  |  |  |     tags_list_to_dict(tags["ResourceTags"]).should.equal(total_env_tags) | 
					
						
							| 
									
										
										
										
											2019-09-04 16:56:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 14:08:22 +01:00
										 |  |  | @mock_elasticbeanstalk | 
					
						
							| 
									
										
										
										
											2019-09-04 15:33:15 +02:00
										 |  |  | def test_list_available_solution_stacks(): | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     conn = boto3.client("elasticbeanstalk", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2019-09-04 15:33:15 +02:00
										 |  |  |     stacks = conn.list_available_solution_stacks() | 
					
						
							| 
									
										
										
										
											2020-03-30 13:42:00 +01:00
										 |  |  |     len(stacks["SolutionStacks"]).should.be.greater_than(0) | 
					
						
							|  |  |  |     len(stacks["SolutionStacks"]).should.be.equal(len(stacks["SolutionStackDetails"])) |