How to use create_query_logging_config method in localstack

Best Python code snippet using localstack_python

test_route53_query_logging_config.py

Source:test_route53_query_logging_config.py Github

copy

Full Screen

...31 return log_group_arn32@mock_logs33@mock_route5334def test_create_query_logging_config_bad_args():35 """Test bad arguments to create_query_logging_config()."""36 client = boto3.client("route53", region_name=TEST_REGION)37 logs_client = boto3.client("logs", region_name=TEST_REGION)38 hosted_zone_test_name = f"route53_query_log_{get_random_hex(6)}.test"39 hosted_zone_id = create_hosted_zone_id(client, hosted_zone_test_name)40 log_group_arn = create_log_group_arn(logs_client, hosted_zone_test_name)41 # Check exception: NoSuchHostedZone42 with pytest.raises(ClientError) as exc:43 client.create_query_logging_config(44 HostedZoneId="foo", CloudWatchLogsLogGroupArn=log_group_arn45 )46 err = exc.value.response["Error"]47 assert err["Code"] == "NoSuchHostedZone"48 assert "No hosted zone found with ID: foo" in err["Message"]49 # Check exception: InvalidInput (bad CloudWatch Logs log ARN)50 with pytest.raises(ClientError) as exc:51 client.create_query_logging_config(52 HostedZoneId=hosted_zone_id,53 CloudWatchLogsLogGroupArn=f"arn:aws:logs:{TEST_REGION}:{ACCOUNT_ID}:foo-bar:foo",54 )55 err = exc.value.response["Error"]56 assert err["Code"] == "InvalidInput"57 assert "The ARN for the CloudWatch Logs log group is invalid" in err["Message"]58 # Check exception: InvalidInput (CloudWatch Logs log not in us-east-1)59 with pytest.raises(ClientError) as exc:60 client.create_query_logging_config(61 HostedZoneId=hosted_zone_id,62 CloudWatchLogsLogGroupArn=log_group_arn.replace(TEST_REGION, "us-west-1"),63 )64 err = exc.value.response["Error"]65 assert err["Code"] == "InvalidInput"66 assert "The ARN for the CloudWatch Logs log group is invalid" in err["Message"]67 # Check exception: NoSuchCloudWatchLogsLogGroup68 with pytest.raises(ClientError) as exc:69 client.create_query_logging_config(70 HostedZoneId=hosted_zone_id,71 CloudWatchLogsLogGroupArn=log_group_arn.replace(72 hosted_zone_test_name, "foo"73 ),74 )75 err = exc.value.response["Error"]76 assert err["Code"] == "NoSuchCloudWatchLogsLogGroup"77 assert "The specified CloudWatch Logs log group doesn't exist" in err["Message"]78 # Check exception: QueryLoggingConfigAlreadyExists79 client.create_query_logging_config(80 HostedZoneId=hosted_zone_id, CloudWatchLogsLogGroupArn=log_group_arn81 )82 with pytest.raises(ClientError) as exc:83 client.create_query_logging_config(84 HostedZoneId=hosted_zone_id, CloudWatchLogsLogGroupArn=log_group_arn85 )86 err = exc.value.response["Error"]87 assert err["Code"] == "QueryLoggingConfigAlreadyExists"88 assert (89 "A query logging configuration already exists for this hosted zone"90 in err["Message"]91 )92@mock_logs93@mock_route5394def test_create_query_logging_config_good_args():95 """Test a valid create_logging_config() request."""96 client = boto3.client("route53", region_name=TEST_REGION)97 logs_client = boto3.client("logs", region_name=TEST_REGION)98 hosted_zone_test_name = f"route53_query_log_{get_random_hex(6)}.test"99 hosted_zone_id = create_hosted_zone_id(client, hosted_zone_test_name)100 log_group_arn = create_log_group_arn(logs_client, hosted_zone_test_name)101 response = client.create_query_logging_config(102 HostedZoneId=hosted_zone_id, CloudWatchLogsLogGroupArn=log_group_arn103 )104 config = response["QueryLoggingConfig"]105 assert config["HostedZoneId"] == hosted_zone_id.split("/")[-1]106 assert config["CloudWatchLogsLogGroupArn"] == log_group_arn107 assert config["Id"]108 location = response["Location"]109 assert (110 location111 == f"https://route53.amazonaws.com/2013-04-01/queryloggingconfig/{config['Id']}"112 )113@mock_logs114@mock_route53115def test_delete_query_logging_config():116 """Test valid and invalid delete_query_logging_config requests."""117 client = boto3.client("route53", region_name=TEST_REGION)118 logs_client = boto3.client("logs", region_name=TEST_REGION)119 # Create a query logging config that can then be deleted.120 hosted_zone_test_name = f"route53_query_log_{get_random_hex(6)}.test"121 hosted_zone_id = create_hosted_zone_id(client, hosted_zone_test_name)122 log_group_arn = create_log_group_arn(logs_client, hosted_zone_test_name)123 query_response = client.create_query_logging_config(124 HostedZoneId=hosted_zone_id, CloudWatchLogsLogGroupArn=log_group_arn125 )126 # Test the deletion.127 query_id = query_response["QueryLoggingConfig"]["Id"]128 response = client.delete_query_logging_config(Id=query_id)129 # There is no response other than the usual ResponseMetadata.130 assert list(response.keys()) == ["ResponseMetadata"]131 # Test the deletion of a non-existent query logging config, i.e., the132 # one that was just deleted.133 with pytest.raises(ClientError) as exc:134 client.delete_query_logging_config(Id=query_id)135 err = exc.value.response["Error"]136 assert err["Code"] == "NoSuchQueryLoggingConfig"137 assert "The query logging configuration does not exist" in err["Message"]138@mock_logs139@mock_route53140def test_get_query_logging_config():141 """Test valid and invalid get_query_logging_config requests."""142 client = boto3.client("route53", region_name=TEST_REGION)143 logs_client = boto3.client("logs", region_name=TEST_REGION)144 # Create a query logging config that can then be retrieved.145 hosted_zone_test_name = f"route53_query_log_{get_random_hex(6)}.test"146 hosted_zone_id = create_hosted_zone_id(client, hosted_zone_test_name)147 log_group_arn = create_log_group_arn(logs_client, hosted_zone_test_name)148 query_response = client.create_query_logging_config(149 HostedZoneId=hosted_zone_id, CloudWatchLogsLogGroupArn=log_group_arn150 )151 # Test the retrieval.152 query_id = query_response["QueryLoggingConfig"]["Id"]153 response = client.get_query_logging_config(Id=query_id)154 config = response["QueryLoggingConfig"]155 assert config["HostedZoneId"] == hosted_zone_id.split("/")[-1]156 assert config["CloudWatchLogsLogGroupArn"] == log_group_arn157 assert config["Id"]158 # Test the retrieval of a non-existent query logging config.159 with pytest.raises(ClientError) as exc:160 client.get_query_logging_config(Id="1234567890")161 err = exc.value.response["Error"]162 assert err["Code"] == "NoSuchQueryLoggingConfig"163 assert "The query logging configuration does not exist" in err["Message"]164@mock_logs165@mock_route53166def test_list_query_logging_configs_bad_args():167 """Test bad arguments to list_query_logging_configs()."""168 client = boto3.client("route53", region_name=TEST_REGION)169 logs_client = boto3.client("logs", region_name=TEST_REGION)170 # Check exception: NoSuchHostedZone171 with pytest.raises(ClientError) as exc:172 client.list_query_logging_configs(HostedZoneId="foo", MaxResults="10")173 err = exc.value.response["Error"]174 assert err["Code"] == "NoSuchHostedZone"175 assert "No hosted zone found with ID: foo" in err["Message"]176 # Create a couple of query logging configs to work with.177 for _ in range(3):178 hosted_zone_test_name = f"route53_query_log_{get_random_hex(6)}.test"179 hosted_zone_id = create_hosted_zone_id(client, hosted_zone_test_name)180 log_group_arn = create_log_group_arn(logs_client, hosted_zone_test_name)181 client.create_query_logging_config(182 HostedZoneId=hosted_zone_id, CloudWatchLogsLogGroupArn=log_group_arn183 )184 # Retrieve a query logging config, then request more with an invalid token.185 client.list_query_logging_configs(MaxResults="1")186 with pytest.raises(ClientError) as exc:187 client.list_query_logging_configs(NextToken="foo")188 err = exc.value.response["Error"]189 assert err["Code"] == "InvalidPaginationToken"190 assert (191 "Route 53 can't get the next page of query logging configurations "192 "because the specified value for NextToken is invalid." in err["Message"]193 )194@mock_logs195@mock_route53196def test_list_query_logging_configs_good_args():197 """Test valid arguments to list_query_logging_configs()."""198 client = boto3.client("route53", region_name=TEST_REGION)199 logs_client = boto3.client("logs", region_name=TEST_REGION)200 # Test when there are no query logging configs.201 response = client.list_query_logging_configs()202 query_logging_configs = response["QueryLoggingConfigs"]203 assert len(query_logging_configs) == 0204 # Create a couple of query logging configs to work with.205 zone_ids = []206 for _ in range(10):207 hosted_zone_test_name = f"route53_query_log_{get_random_hex(6)}.test"208 hosted_zone_id = create_hosted_zone_id(client, hosted_zone_test_name)209 zone_ids.append(hosted_zone_id)210 log_group_arn = create_log_group_arn(logs_client, hosted_zone_test_name)211 client.create_query_logging_config(212 HostedZoneId=hosted_zone_id, CloudWatchLogsLogGroupArn=log_group_arn213 )214 # Verify all 10 of the query logging configs can be retrieved in one go.215 response = client.list_query_logging_configs()216 query_logging_configs = response["QueryLoggingConfigs"]217 assert len(query_logging_configs) == 10218 for idx, query_logging_config in enumerate(query_logging_configs):219 assert query_logging_config["HostedZoneId"] == zone_ids[idx].split("/")[-1]220 # Request only two of the query logging configs and verify there's a221 # next_token.222 response = client.list_query_logging_configs(MaxResults="2")223 assert len(response["QueryLoggingConfigs"]) == 2224 assert response["NextToken"]225 # Request the remaining 8 query logging configs and verify there is...

Full Screen

Full Screen

test_aws_hostedzones_client.py

Source:test_aws_hostedzones_client.py Github

copy

Full Screen

...102 }103 route53_client.list_query_logging_configs = Mock(104 side_effect=lambda HostedZoneId: expected_list_query_logging_config105 )106 AwsHostedZonesClient(route53_client).create_query_logging_config(107 "AAAABBBBCCCCDD", "arn:aws:logs:us-east-1:123456789012:log-group:/aws/route53/public.aws.scanner.gov.uk."108 )109 assert route53_client.list_query_logging_configs.call_count == 1110 assert route53_client.create_query_logging_config.call_count == 1111 route53_client.create_query_logging_config.assert_has_calls(112 [113 call(114 HostedZoneId="AAAABBBBCCCCDD",115 CloudWatchLogsLogGroupArn="arn:aws:logs:us-east-1:123456789012:log-group:\116/aws/route53/public.aws.scanner.gov.uk.",117 )118 ]119 )120 def test_delete_query_logging_config(self) -> None:...

Full Screen

Full Screen

aws_hosted_zones_client.py

Source:aws_hosted_zones_client.py Github

copy

Full Screen

...27 try:28 return self._route53.list_query_logging_configs(HostedZoneId=id)29 except (BotoCoreError, ClientError) as err:30 raise QueryLogException(f"unable to get the query log config: {err}")31 def create_query_logging_config(self, hosted_zone_id: str, cloudwatch_logs_loggrouparn: str) -> Any:32 hosted_zone_query_log = self._route53.list_query_logging_configs(HostedZoneId=hosted_zone_id)33 if (34 len(hosted_zone_query_log["QueryLoggingConfigs"]) == 035 or hosted_zone_query_log["QueryLoggingConfigs"][0]["CloudWatchLogsLogGroupArn"] == ""36 ):37 return self._route53.create_query_logging_config(38 HostedZoneId=hosted_zone_id, CloudWatchLogsLogGroupArn=cloudwatch_logs_loggrouparn39 )40 def delete_query_logging_config(self, hosted_zone_id: str) -> Any:41 queryLoggingConfig = self._route53.list_query_logging_configs(HostedZoneId=hosted_zone_id)42 if len(queryLoggingConfig["QueryLoggingConfigs"]) > 0:43 queryLoggingConfigId = queryLoggingConfig["QueryLoggingConfigs"][0]["Id"]44 self._route53.delete_query_logging_config(Id=queryLoggingConfigId)...

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