diff --git a/tests/test_rds/test_rds_clusters.py b/tests/test_rds/test_rds_clusters.py index a12fb38328f0..24c54991377c 100644 --- a/tests/test_rds/test_rds_clusters.py +++ b/tests/test_rds/test_rds_clusters.py @@ -10,18 +10,20 @@ RDS_REGION = "eu-north-1" +@pytest.fixture(name="client") @mock_aws -def test_describe_db_cluster_initial(): - client = boto3.client("rds", region_name=RDS_REGION) +def get_rds_client(): + return boto3.client("rds", region_name=RDS_REGION) + +@mock_aws +def test_describe_db_cluster_initial(client): resp = client.describe_db_clusters() assert len(resp["DBClusters"]) == 0 @mock_aws -def test_describe_db_cluster_fails_for_non_existent_cluster(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_describe_db_cluster_fails_for_non_existent_cluster(client): resp = client.describe_db_clusters() assert len(resp["DBClusters"]) == 0 with pytest.raises(ClientError) as ex: @@ -32,9 +34,7 @@ def test_describe_db_cluster_fails_for_non_existent_cluster(): @mock_aws -def test_create_db_cluster_invalid_engine(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_create_db_cluster_invalid_engine(client): with pytest.raises(ClientError) as ex: client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql" @@ -47,9 +47,7 @@ def test_create_db_cluster_invalid_engine(): @mock_aws -def test_create_db_cluster_needs_master_username(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_create_db_cluster_needs_master_username(client): with pytest.raises(ClientError) as ex: client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql" @@ -62,9 +60,7 @@ def test_create_db_cluster_needs_master_username(): @mock_aws -def test_create_db_cluster_needs_master_user_password(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_create_db_cluster_needs_master_user_password(client): with pytest.raises(ClientError) as ex: client.create_db_cluster( DBClusterIdentifier="cluster-id", @@ -79,9 +75,7 @@ def test_create_db_cluster_needs_master_user_password(): @mock_aws -def test_create_db_cluster_needs_long_master_user_password(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_create_db_cluster_needs_long_master_user_password(client): with pytest.raises(ClientError) as ex: client.create_db_cluster( DBClusterIdentifier="cluster-id", @@ -98,9 +92,7 @@ def test_create_db_cluster_needs_long_master_user_password(): @mock_aws -def test_modify_db_cluster_needs_long_master_user_password(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_modify_db_cluster_needs_long_master_user_password(client): client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql", @@ -122,8 +114,7 @@ def test_modify_db_cluster_needs_long_master_user_password(): @mock_aws -def test_modify_db_cluster_new_cluster_identifier(): - client = boto3.client("rds", region_name=RDS_REGION) +def test_modify_db_cluster_new_cluster_identifier(client): old_id = "cluster-id" new_id = "new-cluster-id" @@ -152,8 +143,7 @@ def test_modify_db_cluster_new_cluster_identifier(): @pytest.mark.parametrize("with_custom_kms_key", [True, False]) @mock_aws -def test_modify_db_cluster_manage_master_user_password(with_custom_kms_key): - client = boto3.client("rds", region_name=RDS_REGION) +def test_modify_db_cluster_manage_master_user_password(client, with_custom_kms_key): cluster_id = "cluster-id" custom_kms_key = f"arn:aws:kms:{RDS_REGION}:123456789012:key/abcd1234-56ef-78gh-90ij-klmnopqrstuv" custom_kms_key_args = ( @@ -207,8 +197,7 @@ def test_modify_db_cluster_manage_master_user_password(with_custom_kms_key): @pytest.mark.parametrize("with_apply_immediately", [True, False]) @mock_aws -def test_modify_db_cluster_rotate_master_user_password(with_apply_immediately): - client = boto3.client("rds", region_name=RDS_REGION) +def test_modify_db_cluster_rotate_master_user_password(client, with_apply_immediately): cluster_id = "cluster-id" client.create_db_cluster( @@ -248,9 +237,7 @@ def test_modify_db_cluster_rotate_master_user_password(with_apply_immediately): @mock_aws -def test_create_db_cluster__verify_default_properties(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_create_db_cluster__verify_default_properties(client): resp = client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-mysql", @@ -317,9 +304,7 @@ def test_create_db_cluster__verify_default_properties(): @mock_aws -def test_create_db_cluster_additional_parameters(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_create_db_cluster_additional_parameters(client): resp = client.create_db_cluster( AvailabilityZones=["eu-north-1b"], DatabaseName="users", @@ -378,9 +363,7 @@ def test_create_db_cluster_additional_parameters(): @mock_aws -def test_describe_db_cluster_after_creation(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_describe_db_cluster_after_creation(client): client.create_db_cluster( DBClusterIdentifier="cluster-id1", Engine="aurora-postgresql", @@ -411,9 +394,7 @@ def test_describe_db_cluster_after_creation(): @mock_aws -def test_delete_db_cluster(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_delete_db_cluster(client): client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql", @@ -427,9 +408,7 @@ def test_delete_db_cluster(): @mock_aws -def test_delete_db_cluster_do_snapshot(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_delete_db_cluster_do_snapshot(client): client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql", @@ -448,9 +427,7 @@ def test_delete_db_cluster_do_snapshot(): @mock_aws -def test_delete_db_cluster_that_is_protected(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_delete_db_cluster_that_is_protected(client): client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql", @@ -466,9 +443,7 @@ def test_delete_db_cluster_that_is_protected(): @mock_aws -def test_delete_db_cluster_unknown_cluster(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_delete_db_cluster_unknown_cluster(client): with pytest.raises(ClientError) as ex: client.delete_db_cluster(DBClusterIdentifier="cluster-unknown") err = ex.value.response["Error"] @@ -477,9 +452,7 @@ def test_delete_db_cluster_unknown_cluster(): @mock_aws -def test_start_db_cluster_unknown_cluster(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_start_db_cluster_unknown_cluster(client): with pytest.raises(ClientError) as ex: client.start_db_cluster(DBClusterIdentifier="cluster-unknown") err = ex.value.response["Error"] @@ -488,9 +461,7 @@ def test_start_db_cluster_unknown_cluster(): @mock_aws -def test_start_db_cluster_after_stopping(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_start_db_cluster_after_stopping(client): client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql", @@ -505,9 +476,7 @@ def test_start_db_cluster_after_stopping(): @mock_aws -def test_start_db_cluster_without_stopping(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_start_db_cluster_without_stopping(client): client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql", @@ -523,9 +492,7 @@ def test_start_db_cluster_without_stopping(): @mock_aws -def test_stop_db_cluster(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_stop_db_cluster(client): client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql", @@ -544,9 +511,7 @@ def test_stop_db_cluster(): @mock_aws -def test_stop_db_cluster_already_stopped(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_stop_db_cluster_already_stopped(client): client.create_db_cluster( DBClusterIdentifier="cluster-id", Engine="aurora-postgresql", @@ -564,9 +529,7 @@ def test_stop_db_cluster_already_stopped(): @mock_aws -def test_stop_db_cluster_unknown_cluster(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_stop_db_cluster_unknown_cluster(client): with pytest.raises(ClientError) as ex: client.stop_db_cluster(DBClusterIdentifier="cluster-unknown") err = ex.value.response["Error"] @@ -575,10 +538,9 @@ def test_stop_db_cluster_unknown_cluster(): @mock_aws -def test_create_db_cluster_snapshot_fails_for_unknown_cluster(): - conn = boto3.client("rds", region_name="us-west-2") +def test_create_db_cluster_snapshot_fails_for_unknown_cluster(client): with pytest.raises(ClientError) as exc: - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1" ) err = exc.value.response["Error"] @@ -586,9 +548,8 @@ def test_create_db_cluster_snapshot_fails_for_unknown_cluster(): @mock_aws -def test_create_db_cluster_snapshot(): - conn = boto3.client("rds", region_name="us-west-2") - conn.create_db_cluster( +def test_create_db_cluster_snapshot(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -599,7 +560,7 @@ def test_create_db_cluster_snapshot(): Port=1234, ) - snapshot = conn.create_db_cluster_snapshot( + snapshot = client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="g-1" ).get("DBClusterSnapshot") @@ -607,16 +568,16 @@ def test_create_db_cluster_snapshot(): assert snapshot["DBClusterIdentifier"] == "db-primary-1" assert snapshot["DBClusterSnapshotIdentifier"] == "g-1" assert snapshot["SnapshotType"] == "manual" - result = conn.list_tags_for_resource(ResourceName=snapshot["DBClusterSnapshotArn"]) + result = client.list_tags_for_resource( + ResourceName=snapshot["DBClusterSnapshotArn"] + ) assert result["TagList"] == [] @mock_aws -def test_create_db_cluster_snapshot_copy_tags(): - conn = boto3.client("rds", region_name="us-west-2") - +def test_create_db_cluster_snapshot_copy_tags(client): dbci = "db-primary-1" - conn.create_db_cluster( + client.create_db_cluster( DBClusterIdentifier=dbci, AllocatedStorage=10, Engine="postgres", @@ -629,7 +590,7 @@ def test_create_db_cluster_snapshot_copy_tags(): CopyTagsToSnapshot=True, ) - snapshot = conn.create_db_cluster_snapshot( + snapshot = client.create_db_cluster_snapshot( DBClusterIdentifier=dbci, DBClusterSnapshotIdentifier="g-1" ).get("DBClusterSnapshot") @@ -637,13 +598,15 @@ def test_create_db_cluster_snapshot_copy_tags(): assert snapshot.get("DBClusterIdentifier") == dbci assert snapshot.get("DBClusterSnapshotIdentifier") == "g-1" - result = conn.list_tags_for_resource(ResourceName=snapshot["DBClusterSnapshotArn"]) + result = client.list_tags_for_resource( + ResourceName=snapshot["DBClusterSnapshotArn"] + ) assert result["TagList"] == [ {"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}, ] - snapshot = conn.describe_db_cluster_snapshots(DBClusterIdentifier=dbci)[ + snapshot = client.describe_db_cluster_snapshots(DBClusterIdentifier=dbci)[ "DBClusterSnapshots" ][0] assert snapshot["TagList"] == [ @@ -653,11 +616,9 @@ def test_create_db_cluster_snapshot_copy_tags(): @mock_aws -def test_copy_db_cluster_snapshot_fails_for_unknown_snapshot(): - conn = boto3.client("rds", region_name="us-west-2") - +def test_copy_db_cluster_snapshot_fails_for_unknown_snapshot(client): with pytest.raises(ClientError) as exc: - conn.copy_db_cluster_snapshot( + client.copy_db_cluster_snapshot( SourceDBClusterSnapshotIdentifier="snapshot-1", TargetDBClusterSnapshotIdentifier="snapshot-2", ) @@ -667,10 +628,8 @@ def test_copy_db_cluster_snapshot_fails_for_unknown_snapshot(): @mock_aws -def test_copy_db_cluster_snapshot(): - conn = boto3.client("rds", region_name="us-west-2") - - conn.create_db_cluster( +def test_copy_db_cluster_snapshot(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -681,11 +640,11 @@ def test_copy_db_cluster_snapshot(): Port=1234, ) - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1" ).get("DBClusterSnapshot") - target_snapshot = conn.copy_db_cluster_snapshot( + target_snapshot = client.copy_db_cluster_snapshot( SourceDBClusterSnapshotIdentifier="snapshot-1", TargetDBClusterSnapshotIdentifier="snapshot-2", ).get("DBClusterSnapshot") @@ -693,17 +652,15 @@ def test_copy_db_cluster_snapshot(): assert target_snapshot.get("Engine") == "postgres" assert target_snapshot.get("DBClusterIdentifier") == "db-primary-1" assert target_snapshot.get("DBClusterSnapshotIdentifier") == "snapshot-2" - result = conn.list_tags_for_resource( + result = client.list_tags_for_resource( ResourceName=target_snapshot["DBClusterSnapshotArn"] ) assert result["TagList"] == [] @mock_aws -def test_copy_db_cluster_snapshot_fails_for_existed_target_snapshot(): - conn = boto3.client("rds", region_name="us-west-2") - - conn.create_db_cluster( +def test_copy_db_cluster_snapshot_fails_for_existed_target_snapshot(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -714,16 +671,16 @@ def test_copy_db_cluster_snapshot_fails_for_existed_target_snapshot(): Port=1234, ) - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1" ).get("DBClusterSnapshot") - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-2" ).get("DBClusterSnapshot") with pytest.raises(ClientError) as exc: - conn.copy_db_cluster_snapshot( + client.copy_db_cluster_snapshot( SourceDBClusterSnapshotIdentifier="snapshot-1", TargetDBClusterSnapshotIdentifier="snapshot-2", ) @@ -736,9 +693,8 @@ def test_copy_db_cluster_snapshot_fails_for_existed_target_snapshot(): @mock_aws -def test_describe_db_cluster_snapshots(): - conn = boto3.client("rds", region_name="us-west-2") - conn.create_db_cluster( +def test_describe_db_cluster_snapshots(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -749,16 +705,16 @@ def test_describe_db_cluster_snapshots(): Port=1234, ) - created = conn.create_db_cluster_snapshot( + created = client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1" ).get("DBClusterSnapshot") assert created.get("Engine") == "postgres" - by_database_id = conn.describe_db_cluster_snapshots( + by_database_id = client.describe_db_cluster_snapshots( DBClusterIdentifier="db-primary-1" ).get("DBClusterSnapshots") - by_snapshot_id = conn.describe_db_cluster_snapshots( + by_snapshot_id = client.describe_db_cluster_snapshots( DBClusterSnapshotIdentifier="snapshot-1" ).get("DBClusterSnapshots") assert by_snapshot_id == by_database_id @@ -767,19 +723,18 @@ def test_describe_db_cluster_snapshots(): assert snapshot == created assert snapshot.get("Engine") == "postgres" - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-2" ) - snapshots = conn.describe_db_cluster_snapshots( + snapshots = client.describe_db_cluster_snapshots( DBClusterIdentifier="db-primary-1" ).get("DBClusterSnapshots") assert len(snapshots) == 2 @mock_aws -def test_delete_db_cluster_snapshot(): - conn = boto3.client("rds", region_name="us-west-2") - conn.create_db_cluster( +def test_delete_db_cluster_snapshot(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -789,20 +744,19 @@ def test_delete_db_cluster_snapshot(): MasterUserPassword="hunter2000", Port=1234, ) - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1" ) - conn.describe_db_cluster_snapshots(DBClusterSnapshotIdentifier="snapshot-1") - conn.delete_db_cluster_snapshot(DBClusterSnapshotIdentifier="snapshot-1") + client.describe_db_cluster_snapshots(DBClusterSnapshotIdentifier="snapshot-1") + client.delete_db_cluster_snapshot(DBClusterSnapshotIdentifier="snapshot-1") with pytest.raises(ClientError): - conn.describe_db_cluster_snapshots(DBClusterSnapshotIdentifier="snapshot-1") + client.describe_db_cluster_snapshots(DBClusterSnapshotIdentifier="snapshot-1") @mock_aws -def test_restore_db_cluster_from_snapshot(): - conn = boto3.client("rds", region_name="us-west-2") - conn.create_db_cluster( +def test_restore_db_cluster_from_snapshot(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -812,14 +766,14 @@ def test_restore_db_cluster_from_snapshot(): MasterUserPassword="hunter2000", Port=1234, ) - assert len(conn.describe_db_clusters()["DBClusters"]) == 1 + assert len(client.describe_db_clusters()["DBClusters"]) == 1 - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1" ) # restore - new_cluster = conn.restore_db_cluster_from_snapshot( + new_cluster = client.restore_db_cluster_from_snapshot( DBClusterIdentifier="db-restore-1", SnapshotIdentifier="snapshot-1", Engine="postgres", @@ -831,17 +785,14 @@ def test_restore_db_cluster_from_snapshot(): assert new_cluster["Port"] == 1234 # Verify it exists - assert len(conn.describe_db_clusters()["DBClusters"]) == 2 - assert ( - len(conn.describe_db_clusters(DBClusterIdentifier="db-restore-1")["DBClusters"]) - == 1 - ) + assert len(client.describe_db_clusters()["DBClusters"]) == 2 + resp = client.describe_db_clusters(DBClusterIdentifier="db-restore-1") + assert len(resp["DBClusters"]) == 1 @mock_aws -def test_restore_db_cluster_from_snapshot_and_override_params(): - conn = boto3.client("rds", region_name="us-west-2") - conn.create_db_cluster( +def test_restore_db_cluster_from_snapshot_and_override_params(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -851,13 +802,13 @@ def test_restore_db_cluster_from_snapshot_and_override_params(): MasterUserPassword="hunter2000", Port=1234, ) - assert len(conn.describe_db_clusters()["DBClusters"]) == 1 - conn.create_db_cluster_snapshot( + assert len(client.describe_db_clusters()["DBClusters"]) == 1 + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1" ) # restore with some updated attributes - new_cluster = conn.restore_db_cluster_from_snapshot( + new_cluster = client.restore_db_cluster_from_snapshot( DBClusterIdentifier="db-restore-1", SnapshotIdentifier="snapshot-1", Engine="postgres", @@ -871,9 +822,8 @@ def test_restore_db_cluster_from_snapshot_and_override_params(): @mock_aws -def test_add_tags_to_cluster(): - conn = boto3.client("rds", region_name="us-west-2") - resp = conn.create_db_cluster( +def test_add_tags_to_cluster(client): + resp = client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -886,23 +836,22 @@ def test_add_tags_to_cluster(): ) cluster_arn = resp["DBCluster"]["DBClusterArn"] - conn.add_tags_to_resource( + client.add_tags_to_resource( ResourceName=cluster_arn, Tags=[{"Key": "k2", "Value": "v2"}] ) - tags = conn.list_tags_for_resource(ResourceName=cluster_arn)["TagList"] + tags = client.list_tags_for_resource(ResourceName=cluster_arn)["TagList"] assert tags == [{"Key": "k1", "Value": "v1"}, {"Key": "k2", "Value": "v2"}] - conn.remove_tags_from_resource(ResourceName=cluster_arn, TagKeys=["k1"]) + client.remove_tags_from_resource(ResourceName=cluster_arn, TagKeys=["k1"]) - tags = conn.list_tags_for_resource(ResourceName=cluster_arn)["TagList"] + tags = client.list_tags_for_resource(ResourceName=cluster_arn)["TagList"] assert tags == [{"Key": "k2", "Value": "v2"}] @mock_aws -def test_add_tags_to_cluster_snapshot(): - conn = boto3.client("rds", region_name="us-west-2") - conn.create_db_cluster( +def test_add_tags_to_cluster_snapshot(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -914,28 +863,26 @@ def test_add_tags_to_cluster_snapshot(): Tags=[{"Key": "k1", "Value": "v1"}], CopyTagsToSnapshot=True, ) - resp = conn.create_db_cluster_snapshot( + resp = client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1" ) snapshot_arn = resp["DBClusterSnapshot"]["DBClusterSnapshotArn"] - conn.add_tags_to_resource( + client.add_tags_to_resource( ResourceName=snapshot_arn, Tags=[{"Key": "k2", "Value": "v2"}] ) - tags = conn.list_tags_for_resource(ResourceName=snapshot_arn)["TagList"] + tags = client.list_tags_for_resource(ResourceName=snapshot_arn)["TagList"] assert tags == [{"Key": "k1", "Value": "v1"}, {"Key": "k2", "Value": "v2"}] - conn.remove_tags_from_resource(ResourceName=snapshot_arn, TagKeys=["k1"]) + client.remove_tags_from_resource(ResourceName=snapshot_arn, TagKeys=["k1"]) - tags = conn.list_tags_for_resource(ResourceName=snapshot_arn)["TagList"] + tags = client.list_tags_for_resource(ResourceName=snapshot_arn)["TagList"] assert tags == [{"Key": "k2", "Value": "v2"}] @mock_aws -def test_create_serverless_db_cluster(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_create_serverless_db_cluster(client): resp = client.create_db_cluster( DBClusterIdentifier="cluster-id", DatabaseName="users", @@ -957,9 +904,7 @@ def test_create_serverless_db_cluster(): @mock_aws -def test_create_db_cluster_with_enable_http_endpoint_invalid(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_create_db_cluster_with_enable_http_endpoint_invalid(client): resp = client.create_db_cluster( DBClusterIdentifier="cluster-id", DatabaseName="users", @@ -976,9 +921,7 @@ def test_create_db_cluster_with_enable_http_endpoint_invalid(): @mock_aws -def test_describe_db_clusters_filter_by_engine(): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_describe_db_clusters_filter_by_engine(client): client.create_db_cluster( DBClusterIdentifier="id1", Engine="aurora-mysql", @@ -1052,9 +995,8 @@ def test_replicate_cluster(): @mock_aws -def test_createdb_instance_engine_mismatch_fail(): +def test_createdb_instance_engine_mismatch_fail(client): # Setup - client = boto3.client("rds", "us-east-1") cluster_name = "test-cluster" client.create_db_cluster( DBClusterIdentifier=cluster_name, @@ -1065,7 +1007,6 @@ def test_createdb_instance_engine_mismatch_fail(): ) # Execute - with pytest.raises(ClientError) as exc: client.create_db_instance( DBClusterIdentifier=cluster_name, @@ -1086,9 +1027,8 @@ def test_createdb_instance_engine_mismatch_fail(): @mock_aws -def test_describe_db_cluster_snapshot_attributes_default(): - conn = boto3.client("rds", region_name="us-west-2") - conn.create_db_cluster( +def test_describe_db_cluster_snapshot_attributes_default(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -1099,11 +1039,11 @@ def test_describe_db_cluster_snapshot_attributes_default(): Port=1234, ) - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="g-1" ).get("DBClusterSnapshot") - resp = conn.describe_db_cluster_snapshot_attributes( + resp = client.describe_db_cluster_snapshot_attributes( DBClusterSnapshotIdentifier="g-1" ) @@ -1117,9 +1057,8 @@ def test_describe_db_cluster_snapshot_attributes_default(): @mock_aws -def test_describe_db_cluster_snapshot_attributes(): - conn = boto3.client("rds", region_name="us-west-2") - conn.create_db_cluster( +def test_describe_db_cluster_snapshot_attributes(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -1130,17 +1069,17 @@ def test_describe_db_cluster_snapshot_attributes(): Port=1234, ) - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="g-1" ).get("DBClusterSnapshot") - conn.modify_db_cluster_snapshot_attribute( + client.modify_db_cluster_snapshot_attribute( DBClusterSnapshotIdentifier="g-1", AttributeName="restore", ValuesToAdd=["test", "test2"], ) - resp = conn.describe_db_cluster_snapshot_attributes( + resp = client.describe_db_cluster_snapshot_attributes( DBClusterSnapshotIdentifier="g-1" ) @@ -1160,9 +1099,8 @@ def test_describe_db_cluster_snapshot_attributes(): @mock_aws -def test_modify_db_cluster_snapshot_attribute(): - conn = boto3.client("rds", region_name="us-west-2") - conn.create_db_cluster( +def test_modify_db_cluster_snapshot_attribute(client): + client.create_db_cluster( DBClusterIdentifier="db-primary-1", AllocatedStorage=10, Engine="postgres", @@ -1173,21 +1111,21 @@ def test_modify_db_cluster_snapshot_attribute(): Port=1234, ) - conn.create_db_cluster_snapshot( + client.create_db_cluster_snapshot( DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="g-1" ).get("DBClusterSnapshot") - resp = conn.modify_db_cluster_snapshot_attribute( + resp = client.modify_db_cluster_snapshot_attribute( DBClusterSnapshotIdentifier="g-1", AttributeName="restore", ValuesToAdd=["test", "test2"], ) - resp = conn.modify_db_cluster_snapshot_attribute( + resp = client.modify_db_cluster_snapshot_attribute( DBClusterSnapshotIdentifier="g-1", AttributeName="restore", ValuesToRemove=["test"], ) - resp = conn.modify_db_cluster_snapshot_attribute( + resp = client.modify_db_cluster_snapshot_attribute( DBClusterSnapshotIdentifier="g-1", AttributeName="restore", ValuesToAdd=["test3"], @@ -1208,8 +1146,7 @@ def test_modify_db_cluster_snapshot_attribute(): @mock_aws -def test_backtrack_window(): - client = boto3.client("rds", region_name=RDS_REGION) +def test_backtrack_window(client): window = 86400 resp = client.create_db_cluster( AvailabilityZones=["eu-north-1b"], @@ -1253,9 +1190,7 @@ def test_backtrack_window(): ), ], ) -def test_backtrack_errors(params): - client = boto3.client("rds", region_name=RDS_REGION) - +def test_backtrack_errors(client, params): with pytest.raises(ClientError) as ex: client.create_db_cluster( AvailabilityZones=["eu-north-1b"],