How to use associate_vpc_with_hosted_zone method in localstack

Best Python code snippet using localstack_python

test_route53_actions.py

Source:test_route53_actions.py Github

copy

Full Screen

1import json2import os3from unittest.mock import MagicMock, patch4import pytest5from botocore.exceptions import ClientError6from chaoslib.exceptions import FailedActivity7from chaosaws.route53.actions import associate_vpc_with_zone, disassociate_vpc_from_zone8module_path = os.path.dirname(os.path.abspath(__file__))9def read_in_data(filename):10 with open(os.path.join(module_path, "data", filename)) as fh:11 data = json.loads(fh.read())12 return data13def mocked_client_error(op: str):14 return ClientError(15 operation_name=op,16 error_response={"Error": {"Message": "Test Error", "Code": "Test Error"}},17 )18@patch("chaosaws.route53.actions.aws_client", autospec=True)19def test_associate_vpc_with_zone(m_client):20 mock_response = read_in_data("associate_vpc_1.json")21 client = MagicMock()22 m_client.return_value = client23 client.associate_vpc_with_hosted_zone.return_value = mock_response24 response = associate_vpc_with_zone(25 zone_id="AAAAAAAAAAAAA",26 vpc_id="vpc-00000000",27 vpc_region="us-east-1",28 comment="CTK Associate",29 )30 client.associate_vpc_with_hosted_zone.assert_called_with(31 HostedZoneId="AAAAAAAAAAAAA",32 VPC={"VPCId": "vpc-00000000", "VPCRegion": "us-east-1"},33 Comment="CTK Associate",34 )35 assert response["ChangeInfo"]["Status"] == "Pending"36@patch("chaosaws.route53.actions.aws_client", autospec=True)37def test_associate_vpc_with_zone_exception(m_client):38 client = MagicMock()39 m_client.return_value = client40 client.associate_vpc_with_hosted_zone.side_effect = mocked_client_error(41 "associate_vpc_with_hosted_zone"42 )43 with pytest.raises(FailedActivity) as e:44 associate_vpc_with_zone(45 zone_id="1234567890123", vpc_id="vpc-00000000", vpc_region="us-east-1"46 )47 assert "Test Error" in str(e)48@patch("chaosaws.route53.actions.aws_client", autospec=True)49def test_disassociate_vpc_from_zone(m_client):50 mock_response = read_in_data("disassociate_vpc_1.json")51 client = MagicMock()52 m_client.return_value = client53 client.disassociate_vpc_from_hosted_zone.return_value = mock_response54 response = disassociate_vpc_from_zone(55 zone_id="AAAAAAAAAAAAA",56 vpc_id="vpc-00000000",57 vpc_region="us-east-1",58 comment="CTK Disassociate",59 )60 client.disassociate_vpc_from_hosted_zone.assert_called_with(61 HostedZoneId="AAAAAAAAAAAAA",62 VPC={"VPCId": "vpc-00000000", "VPCRegion": "us-east-1"},63 Comment="CTK Disassociate",64 )65 assert response["ChangeInfo"]["Status"] == "Pending"66@patch("chaosaws.route53.actions.aws_client", autospec=True)67def test_disassociate_vpc_with_zone_exception(m_client):68 client = MagicMock()69 m_client.return_value = client70 client.disassociate_vpc_from_hosted_zone.side_effect = mocked_client_error(71 "disassociate_vpc_from_hosted_zone"72 )73 with pytest.raises(FailedActivity) as e:74 disassociate_vpc_from_zone(75 zone_id="1234567890123", vpc_id="vpc-00000000", vpc_region="us-east-1"76 )...

Full Screen

Full Screen

route53_associate_vpc_with_zone.py

Source:route53_associate_vpc_with_zone.py Github

copy

Full Screen

...42print ("Zone: ", args.zone)43print ("VPCId: ", args.vpc)44print ("Region: ", args.region)45try:46 response = client.associate_vpc_with_hosted_zone(47 HostedZoneId=args.zone,48 VPC={49 'VPCRegion': args.region,50 'VPCId': args.vpc51 }52 )53except ClientError as e:54 print ("Unexpected error: %s" % e)55 sys.exit(1)...

Full Screen

Full Screen

associatevpc_r53.py

Source:associatevpc_r53.py Github

copy

Full Screen

1import config2def main(zoneid,region,vpcId):3 try:4 client_r53 = config.boto3.client('route53')5 associatevpc = client_r53.associate_vpc_with_hosted_zone(6 HostedZoneId=zoneid,7 VPC={8 'VPCRegion': region,9 'VPCId': vpcId10 },11 Comment='VPC ID: ' + vpcId + 'Region: ' + region,12 )13 return associatevpc14 except Exception as e:15 response = {}16 config.logger.error('ERROR: {}'.format(e))17 traceback.print_exc()18 response["statusCode"] = "500"19 response["body"] = str(e)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful