Best Python code snippet using localstack_python
test_ami.py
Source:test_ami.py
...15 mock_response = {"Images": []}16 executor.ec2_client.describe_images = MagicMock(return_value=mock_response)17 with pytest.raises(cf_utils.DeployException) as ex:18 result = executor.execute(artifact_id="artifact")19 self.assertEqual([call.describe_images(Filters=[{'Values': ['artifact'], 'Name': 'tag:ArtifactID'}])],20 executor.ec2_client.mock_calls)21 self.assertEqual("No images found for search 'artifact'", ex.value.message)22 def test_by_artifact_id_with_single_result(self):23 executor = ami.AMIExecutor(None)24 executor.ec2_client = MagicMock()25 mock_response = {"Images": [{"ImageId": "id-1234", "Name": "mock-image", "CreationDate": "today"}]}26 executor.ec2_client.describe_images = MagicMock(return_value=mock_response)27 executor.execute(artifact_id="artifact")28 self.assertEqual([call.describe_images(Filters=[{'Values': ['artifact'], 'Name': 'tag:ArtifactID'}])],29 executor.ec2_client.mock_calls)30 def test_by_artifact_id_with_duplicate_result(self):31 executor = ami.AMIExecutor(None)32 executor.ec2_client = MagicMock()33 mock_response = {"Images": [{"ImageId": "id-1234", "Name": "mock-image", "CreationDate": "today"},34 {"ImageId": "id-1235", "Name": "mock-image", "CreationDate": "today"}]}35 executor.ec2_client.describe_images = MagicMock(return_value=mock_response)36 with pytest.raises(cf_utils.DeployException) as ex:37 result = executor.execute(artifact_id="artifact")38 self.assertEqual([call.describe_images(Filters=[{'Values': ['artifact'], 'Name': 'tag:ArtifactID'}])],39 executor.ec2_client.mock_calls)40 self.assertEqual("More than 1 image found for search 'artifact'", ex.value.message)41 def test_by_ami_id_with_no_result(self):42 executor = ami.AMIExecutor(None)43 executor.ec2_client = MagicMock()44 mock_response = {"Images": []}45 executor.ec2_client.describe_images = MagicMock(return_value=mock_response)46 with pytest.raises(cf_utils.DeployException) as ex:47 executor.execute(ami_id="ami-1234")48 self.assertEqual([call.describe_images(ImageIds=['ami-1234'])],49 executor.ec2_client.mock_calls)50 self.assertEqual("No images found for search 'ami-1234'", ex.value.message)51 def test_by_ami_id_with_single_result(self):52 executor = ami.AMIExecutor(None)53 executor.ec2_client = MagicMock()54 mock_response = {"Images": [{"ImageId": "id-1234", "Name": "mock-image", "CreationDate": "today"}]}55 executor.ec2_client.describe_images = MagicMock(return_value=mock_response)56 executor.execute(ami_id="ami-1234")57 self.assertEqual([call.describe_images(ImageIds=['ami-1234'])],58 executor.ec2_client.mock_calls)59 def test_by_ami_id_with_multiple_results(self):60 executor = ami.AMIExecutor(None)61 executor.ec2_client = MagicMock()62 mock_response = {"Images": [{"ImageId": "id-1234", "Name": "mock-image", "CreationDate": "today"},63 {"ImageId": "id-1235", "Name": "mock-image", "CreationDate": "today"}]}64 executor.ec2_client.describe_images = MagicMock(return_value=mock_response)65 with pytest.raises(cf_utils.DeployException) as ex:66 executor.execute(ami_id="ami-1234")67 self.assertEqual([call.describe_images(ImageIds=['ami-1234'])],68 executor.ec2_client.mock_calls)...
list_ubuntu_amis.py
Source:list_ubuntu_amis.py
...35for region in region_names:36 ec2 = boto3.client('ec2', region)3738 if region == "ap-northeast-1":39 resp = ec2.describe_images(Filters=apfilters)40 print(' ' + region + ':')41 print(' AMI: ' + resp['Images'][0]['ImageId'])42 elif region == "ca-central-1":43 resp = ec2.describe_images(Filters=cafilters)44 print(' ' + region + ':')45 print(' AMI: ' + resp['Images'][0]['ImageId'])46 else:47 resp = ec2.describe_images(Filters=filters)48 print(' ' + region + ':')49 print(' AMI: ' + resp['Images'][0]['ImageId'])
...
ecr.py
Source:ecr.py
...6 return response.get('repositories')7def describe_repository(repository):8 response = client.describe_repositories(repositoryNames=[repository])9 return response.get('repositories')10def describe_images(repositoryName):11 response = client.describe_images(repositoryName=repositoryName)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!