Best Python code snippet using localstack_python
test_route53resolver_endpoint.py
Source:test_route53resolver_endpoint.py
...367 assert endpoint["Status"] == "DELETING"368 assert "Deleting" in endpoint["StatusMessage"]369 assert endpoint["CreationTime"] == created_endpoint["CreationTime"]370 # Verify there are no endpoints or no network interfaces.371 response = client.list_resolver_endpoints()372 assert len(response["ResolverEndpoints"]) == 0373 result = ec2_client.describe_network_interfaces()374 assert len(result["NetworkInterfaces"]) == 0375@mock_ec2376@mock_route53resolver377def test_route53resolver_bad_delete_resolver_endpoint():378 """Test delete_resolver_endpoint API calls with a bad ID."""379 client = boto3.client("route53resolver", region_name=TEST_REGION)380 ec2_client = boto3.client("ec2", region_name=TEST_REGION)381 random_num = get_random_hex(10)382 # Use a resolver endpoint id that is too long.383 long_id = "0123456789" * 6 + "xxxxx"384 with pytest.raises(ClientError) as exc:385 client.delete_resolver_endpoint(ResolverEndpointId=long_id)386 err = exc.value.response["Error"]387 assert err["Code"] == "ValidationException"388 assert "1 validation error detected" in err["Message"]389 assert (390 f"Value '{long_id}' at 'resolverEndpointId' failed to satisfy "391 f"constraint: Member must have length less than or equal to 64"392 ) in err["Message"]393 # Delete a non-existent resolver endpoint.394 with pytest.raises(ClientError) as exc:395 client.delete_resolver_endpoint(ResolverEndpointId=random_num)396 err = exc.value.response["Error"]397 assert err["Code"] == "ResourceNotFoundException"398 assert f"Resolver endpoint with ID '{random_num}' does not exist" in err["Message"]399 # Create an endpoint and a rule referencing that endpoint. Verify the400 # endpoint can't be deleted due to that rule.401 endpoint = create_test_endpoint(client, ec2_client)402 resolver_rule = client.create_resolver_rule(403 CreatorRequestId=random_num,404 RuleType="FORWARD",405 DomainName=f"X{random_num}.com",406 ResolverEndpointId=endpoint["Id"],407 )408 with pytest.raises(ClientError) as exc:409 client.delete_resolver_endpoint(ResolverEndpointId=endpoint["Id"])410 err = exc.value.response["Error"]411 assert err["Code"] == "InvalidRequestException"412 assert (413 f"Cannot delete resolver endpoint unless its related resolver rules "414 f"are deleted. The following rules still exist for this resolver "415 f"endpoint: {resolver_rule['ResolverRule']['Id']}"416 ) in err["Message"]417@mock_ec2418@mock_route53resolver419def test_route53resolver_get_resolver_endpoint():420 """Test good get_resolver_endpoint API calls."""421 client = boto3.client("route53resolver", region_name=TEST_REGION)422 ec2_client = boto3.client("ec2", region_name=TEST_REGION)423 created_endpoint = create_test_endpoint(client, ec2_client)424 # Now get the resolver endpoint and verify the response.425 response = client.get_resolver_endpoint(ResolverEndpointId=created_endpoint["Id"])426 endpoint = response["ResolverEndpoint"]427 assert endpoint["CreatorRequestId"] == created_endpoint["CreatorRequestId"]428 assert endpoint["Id"] == created_endpoint["Id"]429 assert endpoint["Arn"] == created_endpoint["Arn"]430 assert endpoint["Name"] == created_endpoint["Name"]431 assert endpoint["SecurityGroupIds"] == created_endpoint["SecurityGroupIds"]432 assert endpoint["Direction"] == created_endpoint["Direction"]433 assert endpoint["IpAddressCount"] == created_endpoint["IpAddressCount"]434 assert endpoint["HostVPCId"] == created_endpoint["HostVPCId"]435 assert endpoint["Status"] == created_endpoint["Status"]436 assert endpoint["StatusMessage"] == created_endpoint["StatusMessage"]437 assert endpoint["CreationTime"] == created_endpoint["CreationTime"]438 assert endpoint["ModificationTime"] == created_endpoint["ModificationTime"]439@mock_route53resolver440def test_route53resolver_bad_get_resolver_endpoint():441 """Test get_resolver_endpoint API calls with a bad ID."""442 client = boto3.client("route53resolver", region_name=TEST_REGION)443 random_num = get_random_hex(10)444 # Use a resolver endpoint id that is too long.445 long_id = "0123456789" * 6 + "xxxxx"446 with pytest.raises(ClientError) as exc:447 client.get_resolver_endpoint(ResolverEndpointId=long_id)448 err = exc.value.response["Error"]449 assert err["Code"] == "ValidationException"450 assert "1 validation error detected" in err["Message"]451 assert (452 f"Value '{long_id}' at 'resolverEndpointId' failed to satisfy "453 f"constraint: Member must have length less than or equal to 64"454 ) in err["Message"]455 # Delete a non-existent resolver endpoint.456 with pytest.raises(ClientError) as exc:457 client.get_resolver_endpoint(ResolverEndpointId=random_num)458 err = exc.value.response["Error"]459 assert err["Code"] == "ResourceNotFoundException"460 assert f"Resolver endpoint with ID '{random_num}' does not exist" in err["Message"]461@mock_ec2462@mock_route53resolver463def test_route53resolver_update_resolver_endpoint():464 """Test good update_resolver_endpoint API calls."""465 client = boto3.client("route53resolver", region_name=TEST_REGION)466 ec2_client = boto3.client("ec2", region_name=TEST_REGION)467 created_endpoint = create_test_endpoint(client, ec2_client)468 # Now update the resolver endpoint name and verify the response.469 new_name = "NewName" + get_random_hex(6)470 response = client.update_resolver_endpoint(471 ResolverEndpointId=created_endpoint["Id"], Name=new_name472 )473 endpoint = response["ResolverEndpoint"]474 assert endpoint["CreatorRequestId"] == created_endpoint["CreatorRequestId"]475 assert endpoint["Id"] == created_endpoint["Id"]476 assert endpoint["Arn"] == created_endpoint["Arn"]477 assert endpoint["Name"] == new_name478 assert endpoint["SecurityGroupIds"] == created_endpoint["SecurityGroupIds"]479 assert endpoint["Direction"] == created_endpoint["Direction"]480 assert endpoint["IpAddressCount"] == created_endpoint["IpAddressCount"]481 assert endpoint["HostVPCId"] == created_endpoint["HostVPCId"]482 assert endpoint["Status"] == created_endpoint["Status"]483 assert endpoint["StatusMessage"] == created_endpoint["StatusMessage"]484 assert endpoint["CreationTime"] == created_endpoint["CreationTime"]485 assert endpoint["ModificationTime"] != created_endpoint["ModificationTime"]486@mock_route53resolver487def test_route53resolver_bad_update_resolver_endpoint():488 """Test update_resolver_endpoint API calls with a bad ID."""489 client = boto3.client("route53resolver", region_name=TEST_REGION)490 random_num = get_random_hex(10)491 random_name = "Z" + get_random_hex(10)492 # Use a resolver endpoint id that is too long.493 long_id = "0123456789" * 6 + "xxxxx"494 with pytest.raises(ClientError) as exc:495 client.update_resolver_endpoint(ResolverEndpointId=long_id, Name=random_name)496 err = exc.value.response["Error"]497 assert err["Code"] == "ValidationException"498 assert "1 validation error detected" in err["Message"]499 assert (500 f"Value '{long_id}' at 'resolverEndpointId' failed to satisfy "501 f"constraint: Member must have length less than or equal to 64"502 ) in err["Message"]503 # Delete a non-existent resolver endpoint.504 with pytest.raises(ClientError) as exc:505 client.update_resolver_endpoint(ResolverEndpointId=random_num, Name=random_name)506 err = exc.value.response["Error"]507 assert err["Code"] == "ResourceNotFoundException"508 assert f"Resolver endpoint with ID '{random_num}' does not exist" in err["Message"]509@mock_ec2510@mock_route53resolver511def test_route53resolver_list_resolver_endpoint_ip_addresses():512 """Test good list_resolver_endpoint_ip_addresses API calls."""513 client = boto3.client("route53resolver", region_name=TEST_REGION)514 ec2_client = boto3.client("ec2", region_name=TEST_REGION)515 random_num = get_random_hex(10)516 subnet_ids = create_subnets(ec2_client, create_vpc(ec2_client))517 response = client.create_resolver_endpoint(518 CreatorRequestId="B" + random_num,519 Name="B" + random_num,520 SecurityGroupIds=[create_security_group(ec2_client)],521 Direction="INBOUND",522 IpAddresses=[523 {"SubnetId": subnet_ids[0], "Ip": "10.0.1.200"},524 {"SubnetId": subnet_ids[1], "Ip": "10.0.0.20"},525 {"SubnetId": subnet_ids[0], "Ip": "10.0.1.201"},526 ],527 )528 endpoint_id = response["ResolverEndpoint"]["Id"]529 response = client.list_resolver_endpoint_ip_addresses(530 ResolverEndpointId=endpoint_id531 )532 assert len(response["IpAddresses"]) == 3533 assert response["MaxResults"] == 10534 # Set max_results to return 1 address, use next_token to get remaining.535 response = client.list_resolver_endpoint_ip_addresses(536 ResolverEndpointId=endpoint_id, MaxResults=1537 )538 ip_addresses = response["IpAddresses"]539 assert len(ip_addresses) == 1540 assert response["MaxResults"] == 1541 assert "NextToken" in response542 assert ip_addresses[0]["IpId"].startswith("rni-")543 assert ip_addresses[0]["SubnetId"] == subnet_ids[0]544 assert ip_addresses[0]["Ip"] == "10.0.1.200"545 assert ip_addresses[0]["Status"] == "ATTACHED"546 assert ip_addresses[0]["StatusMessage"] == "This IP address is operational."547 assert "CreationTime" in ip_addresses[0]548 assert "ModificationTime" in ip_addresses[0]549 response = client.list_resolver_endpoint_ip_addresses(550 ResolverEndpointId=endpoint_id, NextToken=response["NextToken"]551 )552 assert len(response["IpAddresses"]) == 2553 assert response["MaxResults"] == 10554 assert "NextToken" not in response555@mock_ec2556@mock_route53resolver557def test_route53resolver_bad_list_resolver_endpoint_ip_addresses():558 """Test bad list_resolver_endpoint_ip_addresses API calls."""559 client = boto3.client("route53resolver", region_name=TEST_REGION)560 ec2_client = boto3.client("ec2", region_name=TEST_REGION)561 # Bad endpoint id.562 with pytest.raises(ClientError) as exc:563 client.list_resolver_endpoint_ip_addresses(ResolverEndpointId="foo")564 err = exc.value.response["Error"]565 assert err["Code"] == "ResourceNotFoundException"566 assert "Resolver endpoint with ID 'foo' does not exist" in err["Message"]567 # Good endpoint id, but bad max_results.568 random_num = get_random_hex(10)569 response = create_test_endpoint(client, ec2_client, name=f"A-{random_num}")570 with pytest.raises(ClientError) as exc:571 client.list_resolver_endpoint_ip_addresses(572 ResolverEndpointId=response["Id"], MaxResults=250573 )574 err = exc.value.response["Error"]575 assert err["Code"] == "ValidationException"576 assert "1 validation error detected" in err["Message"]577 assert (578 "Value '250' at 'maxResults' failed to satisfy constraint: Member "579 "must have length less than or equal to 100"580 ) in err["Message"]581@mock_ec2582@mock_route53resolver583def test_route53resolver_list_resolver_endpoints():584 """Test good list_resolver_endpoints API calls."""585 client = boto3.client("route53resolver", region_name=TEST_REGION)586 ec2_client = boto3.client("ec2", region_name=TEST_REGION)587 random_num = get_random_hex(10)588 # List endpoints when there are none.589 response = client.list_resolver_endpoints()590 assert len(response["ResolverEndpoints"]) == 0591 assert response["MaxResults"] == 10592 assert "NextToken" not in response593 # Create 5 endpoints, verify all 5 are listed when no filters, max_results.594 for idx in range(4):595 create_test_endpoint(client, ec2_client, name=f"A{idx}-{random_num}")596 response = client.list_resolver_endpoints()597 endpoints = response["ResolverEndpoints"]598 assert len(endpoints) == 4599 assert response["MaxResults"] == 10600 for idx in range(4):601 assert endpoints[idx]["Name"].startswith(f"A{idx}")602 # Set max_results to return 1 endpoint, use next_token to get remaining 3.603 response = client.list_resolver_endpoints(MaxResults=1)604 endpoints = response["ResolverEndpoints"]605 assert len(endpoints) == 1606 assert response["MaxResults"] == 1607 assert "NextToken" in response608 assert endpoints[0]["Name"].startswith("A0")609 response = client.list_resolver_endpoints(NextToken=response["NextToken"])610 endpoints = response["ResolverEndpoints"]611 assert len(endpoints) == 3612 assert response["MaxResults"] == 10613 assert "NextToken" not in response614 for idx, endpoint in enumerate(endpoints):615 assert endpoint["Name"].startswith(f"A{idx + 1}")616@mock_ec2617@mock_route53resolver618def test_route53resolver_list_resolver_endpoints_filters():619 """Test good list_resolver_endpoints API calls that use filters."""620 client = boto3.client("route53resolver", region_name=TEST_REGION)621 ec2_client = boto3.client("ec2", region_name=TEST_REGION)622 random_num = get_random_hex(10)623 # Create some endpoints for testing purposes624 security_group_id = create_security_group(ec2_client)625 vpc_id = create_vpc(ec2_client)626 subnet_ids = create_subnets(ec2_client, vpc_id)627 ip0_values = ["10.0.1.201", "10.0.1.202", "10.0.1.203", "10.0.1.204"]628 ip1_values = ["10.0.0.21", "10.0.0.22", "10.0.0.23", "10.0.0.24"]629 endpoints = []630 for idx in range(1, 5):631 ip_addrs = [632 {"SubnetId": subnet_ids[0], "Ip": "10.0.1.200"},633 {"SubnetId": subnet_ids[1], "Ip": "10.0.0.20"},634 {"SubnetId": subnet_ids[0], "Ip": ip0_values[idx - 1]},635 {"SubnetId": subnet_ids[1], "Ip": ip1_values[idx - 1]},636 ]637 response = client.create_resolver_endpoint(638 CreatorRequestId=f"F{idx}-{random_num}",639 Name=f"F{idx}-{random_num}",640 SecurityGroupIds=[security_group_id],641 Direction="INBOUND" if idx % 2 else "OUTBOUND",642 IpAddresses=ip_addrs,643 )644 endpoints.append(response["ResolverEndpoint"])645 # Try all the valid filter names, including some of the old style names.646 response = client.list_resolver_endpoints(647 Filters=[{"Name": "CreatorRequestId", "Values": [f"F3-{random_num}"]}]648 )649 assert len(response["ResolverEndpoints"]) == 1650 assert response["ResolverEndpoints"][0]["CreatorRequestId"] == f"F3-{random_num}"651 response = client.list_resolver_endpoints(652 Filters=[653 {654 "Name": "CREATOR_REQUEST_ID",655 "Values": [f"F2-{random_num}", f"F4-{random_num}"],656 }657 ]658 )659 assert len(response["ResolverEndpoints"]) == 2660 assert response["ResolverEndpoints"][0]["CreatorRequestId"] == f"F2-{random_num}"661 assert response["ResolverEndpoints"][1]["CreatorRequestId"] == f"F4-{random_num}"662 response = client.list_resolver_endpoints(663 Filters=[{"Name": "Direction", "Values": ["INBOUND"]}]664 )665 assert len(response["ResolverEndpoints"]) == 2666 assert response["ResolverEndpoints"][0]["CreatorRequestId"] == f"F1-{random_num}"667 assert response["ResolverEndpoints"][1]["CreatorRequestId"] == f"F3-{random_num}"668 response = client.list_resolver_endpoints(669 Filters=[{"Name": "HostVPCId", "Values": [vpc_id]}]670 )671 assert len(response["ResolverEndpoints"]) == 4672 response = client.list_resolver_endpoints(673 Filters=[{"Name": "IpAddressCount", "Values": ["4"]}]674 )675 assert len(response["ResolverEndpoints"]) == 4676 response = client.list_resolver_endpoints(677 Filters=[{"Name": "IpAddressCount", "Values": ["0", "7"]}]678 )679 assert len(response["ResolverEndpoints"]) == 0680 response = client.list_resolver_endpoints(681 Filters=[{"Name": "Name", "Values": [f"F1-{random_num}"]}]682 )683 assert len(response["ResolverEndpoints"]) == 1684 assert response["ResolverEndpoints"][0]["Name"] == f"F1-{random_num}"685 response = client.list_resolver_endpoints(686 Filters=[687 {"Name": "HOST_VPC_ID", "Values": [vpc_id]},688 {"Name": "DIRECTION", "Values": ["INBOUND"]},689 {"Name": "NAME", "Values": [f"F3-{random_num}"]},690 ]691 )692 assert len(response["ResolverEndpoints"]) == 1693 assert response["ResolverEndpoints"][0]["Name"] == f"F3-{random_num}"694 response = client.list_resolver_endpoints(695 Filters=[{"Name": "SecurityGroupIds", "Values": [security_group_id]}]696 )697 assert len(response["ResolverEndpoints"]) == 4698 response = client.list_resolver_endpoints(699 Filters=[{"Name": "Status", "Values": ["OPERATIONAL"]}]700 )701 assert len(response["ResolverEndpoints"]) == 4702 response = client.list_resolver_endpoints(703 Filters=[{"Name": "Status", "Values": ["CREATING"]}]704 )705 assert len(response["ResolverEndpoints"]) == 0706@mock_route53resolver707def test_route53resolver_bad_list_resolver_endpoints_filters():708 """Test bad list_resolver_endpoints API calls that use filters."""709 client = boto3.client("route53resolver", region_name=TEST_REGION)710 # botocore barfs on an empty "Values":711 # TypeError: list_resolver_endpoints() only accepts keyword arguments.712 # client.list_resolver_endpoints([{"Name": "Direction", "Values": []}])713 # client.list_resolver_endpoints([{"Values": []}])714 with pytest.raises(ClientError) as exc:715 client.list_resolver_endpoints(Filters=[{"Name": "foo", "Values": ["bar"]}])716 err = exc.value.response["Error"]717 assert err["Code"] == "InvalidParameterException"718 assert "The filter 'foo' is invalid" in err["Message"]719 with pytest.raises(ClientError) as exc:720 client.list_resolver_endpoints(721 Filters=[{"Name": "HostVpcId", "Values": ["bar"]}]722 )723 err = exc.value.response["Error"]724 assert err["Code"] == "InvalidParameterException"725 assert "The filter 'HostVpcId' is invalid" in err["Message"]726@mock_ec2727@mock_route53resolver728def test_route53resolver_bad_list_resolver_endpoints():729 """Test bad list_resolver_endpoints API calls."""730 client = boto3.client("route53resolver", region_name=TEST_REGION)731 ec2_client = boto3.client("ec2", region_name=TEST_REGION)732 # Bad max_results.733 random_num = get_random_hex(10)734 create_test_endpoint(client, ec2_client, name=f"A-{random_num}")735 with pytest.raises(ClientError) as exc:736 client.list_resolver_endpoints(MaxResults=250)737 err = exc.value.response["Error"]738 assert err["Code"] == "ValidationException"739 assert "1 validation error detected" in err["Message"]740 assert (741 "Value '250' at 'maxResults' failed to satisfy constraint: Member "742 "must have length less than or equal to 100"743 ) in err["Message"]744@mock_ec2745@mock_route53resolver746def test_associate_resolver_endpoint_ip_address():747 client = boto3.client("route53resolver", region_name=TEST_REGION)748 ec2_client = boto3.client("ec2", region_name=TEST_REGION)749 # create subnet750 vpc_id = create_vpc(ec2_client)...
aws_route53resolver_info.py
Source:aws_route53resolver_info.py
...174 if client.can_paginate('list_resolver_endpoints'):175 paginator = client.get_paginator('list_resolver_endpoints')176 return paginator.paginate(), True177 else:178 return client.list_resolver_endpoints(), False179 else:180 return None, False181 except (BotoCoreError, ClientError) as e:182 module.fail_json_aws(e, msg='Failed to fetch Amazon Route 53 Resolver details')183def main():184 argument_spec = dict(185 id=dict(required=False, aliases=['firewall_rule_group_id', 'resolver_endpoint_id']),186 list_firewall_configs=dict(required=False, type=bool),187 list_firewall_domain_lists=dict(required=False, type=bool),188 list_firewall_rule_groups=dict(required=False, type=bool),189 list_firewall_rules=dict(required=False, type=bool),190 list_resolver_dnssec_configs=dict(required=False, type=bool),191 list_resolver_endpoint_ip_addresses=dict(required=False, type=bool),192 list_resolver_endpoints=dict(required=False, type=bool),...
route53resolver.py
Source:route53resolver.py
...6 service_code = 'route53resolver'7 quota_code = 'L-4A669CC0'8 @property9 def current(self):10 return len(self.boto_session.client('route53resolver').list_resolver_endpoints()['ResolverEndpoints'])11class RulesCountCheck(QuotaCheck):12 key = "route53resolver_rule_count"13 description = "Route53 Resolver rules per Region"14 scope = QuotaScope.REGION15 service_code = 'route53resolver'16 quota_code = 'L-51D8A1FB'17 @property18 def current(self):19 return len(self.boto_session.client('route53resolver').list_resolver_rules()['ResolverRules'])20class RuleAssociationsCountCheck(QuotaCheck):21 key = "route53resolver_rule_association_count"22 description = "Route53 Resolver rule associations per Region"23 scope = QuotaScope.REGION24 service_code = 'route53resolver'...
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!!