How to use disassociate_vpc_from_hosted_zone method in localstack

Best Python code snippet using localstack_python

test_route53.py

Source:test_route53.py Github

copy

Full Screen

...40 result = route53.list_hosted_zones_by_name(DNSName=name).get("HostedZones")41 self.assertEqual("zone123.", result[0]["Name"])42 result = route53.list_hosted_zones_by_name(DNSName="%s." % name).get("HostedZones")43 self.assertEqual("zone123.", result[0]["Name"])44 result = route53.disassociate_vpc_from_hosted_zone(45 HostedZoneId=zone_id,46 VPC={"VPCRegion": aws_stack.get_region(), "VPCId": vpc_id},47 Comment="test2",48 )49 self.assertIn(response["ResponseMetadata"]["HTTPStatusCode"], [200, 201])50 # subsequent call (after disassociation) should fail with 404 error51 with self.assertRaises(Exception):52 route53.disassociate_vpc_from_hosted_zone(53 HostedZoneId=zone_id,54 VPC={"VPCRegion": aws_stack.get_region(), "VPCId": vpc_id},55 )56 def test_reusable_delegation_sets(self):57 client = aws_stack.connect_to_service("route53")58 sets_before = client.list_reusable_delegation_sets().get("DelegationSets", [])59 call_ref_1 = "c-%s" % short_uid()60 result_1 = client.create_reusable_delegation_set(CallerReference=call_ref_1)[61 "DelegationSet"62 ]63 set_id_1 = result_1["Id"]64 call_ref_2 = "c-%s" % short_uid()65 result_2 = client.create_reusable_delegation_set(CallerReference=call_ref_2)[66 "DelegationSet"...

Full Screen

Full Screen

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

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