Techdebt: Replace sure with regular assertions in RDS (#6683)
This commit is contained in:
parent
28743bdbe7
commit
1fe69d55a5
@ -1,7 +1,7 @@
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_rds
|
||||
from moto.core import DEFAULT_ACCOUNT_ID
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import boto3
|
||||
import pytest
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from moto import mock_rds
|
||||
|
||||
@ -37,8 +36,8 @@ class TestDBInstanceFilters:
|
||||
self.client.describe_db_instances(
|
||||
Filters=[{"Name": "invalid-filter-name", "Values": []}]
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("InvalidParameterValue")
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
assert ex.value.response["Error"]["Code"] == "InvalidParameterValue"
|
||||
assert ex.value.response["Error"]["Message"] == (
|
||||
"Unrecognized filter name: invalid-filter-name"
|
||||
)
|
||||
|
||||
@ -47,8 +46,8 @@ class TestDBInstanceFilters:
|
||||
self.client.describe_db_instances(
|
||||
Filters=[{"Name": "db-instance-id", "Values": []}]
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("InvalidParameterCombination")
|
||||
ex.value.response["Error"]["Message"].should.contain("must not be empty")
|
||||
assert ex.value.response["Error"]["Code"] == "InvalidParameterCombination"
|
||||
assert "must not be empty" in ex.value.response["Error"]["Message"]
|
||||
|
||||
def test_db_cluster_id_filter(self):
|
||||
resp = self.client.describe_db_instances()
|
||||
@ -57,8 +56,8 @@ class TestDBInstanceFilters:
|
||||
db_instances = self.client.describe_db_instances(
|
||||
Filters=[{"Name": "db-cluster-id", "Values": [db_cluster_identifier]}]
|
||||
).get("DBInstances")
|
||||
db_instances.should.have.length_of(1)
|
||||
db_instances[0]["DBClusterIdentifier"].should.equal(db_cluster_identifier)
|
||||
assert len(db_instances) == 1
|
||||
assert db_instances[0]["DBClusterIdentifier"] == db_cluster_identifier
|
||||
|
||||
def test_db_instance_id_filter(self):
|
||||
resp = self.client.describe_db_instances()
|
||||
@ -67,8 +66,8 @@ class TestDBInstanceFilters:
|
||||
db_instances = self.client.describe_db_instances(
|
||||
Filters=[{"Name": "db-instance-id", "Values": [db_instance_identifier]}]
|
||||
).get("DBInstances")
|
||||
db_instances.should.have.length_of(1)
|
||||
db_instances[0]["DBInstanceIdentifier"].should.equal(db_instance_identifier)
|
||||
assert len(db_instances) == 1
|
||||
assert db_instances[0]["DBInstanceIdentifier"] == db_instance_identifier
|
||||
|
||||
def test_db_instance_id_filter_works_with_arns(self):
|
||||
resp = self.client.describe_db_instances()
|
||||
@ -77,8 +76,8 @@ class TestDBInstanceFilters:
|
||||
db_instances = self.client.describe_db_instances(
|
||||
Filters=[{"Name": "db-instance-id", "Values": [db_instance_arn]}]
|
||||
).get("DBInstances")
|
||||
db_instances.should.have.length_of(1)
|
||||
db_instances[0]["DBInstanceArn"].should.equal(db_instance_arn)
|
||||
assert len(db_instances) == 1
|
||||
assert db_instances[0]["DBInstanceArn"] == db_instance_arn
|
||||
|
||||
def test_dbi_resource_id_filter(self):
|
||||
resp = self.client.describe_db_instances()
|
||||
@ -88,19 +87,19 @@ class TestDBInstanceFilters:
|
||||
Filters=[{"Name": "dbi-resource-id", "Values": [dbi_resource_identifier]}]
|
||||
).get("DBInstances")
|
||||
for db_instance in db_instances:
|
||||
db_instance["DbiResourceId"].should.equal(dbi_resource_identifier)
|
||||
assert db_instance["DbiResourceId"] == dbi_resource_identifier
|
||||
|
||||
def test_engine_filter(self):
|
||||
db_instances = self.client.describe_db_instances(
|
||||
Filters=[{"Name": "engine", "Values": ["postgres"]}]
|
||||
).get("DBInstances")
|
||||
for db_instance in db_instances:
|
||||
db_instance["Engine"].should.equal("postgres")
|
||||
assert db_instance["Engine"] == "postgres"
|
||||
|
||||
db_instances = self.client.describe_db_instances(
|
||||
Filters=[{"Name": "engine", "Values": ["oracle"]}]
|
||||
).get("DBInstances")
|
||||
db_instances.should.have.length_of(0)
|
||||
assert len(db_instances) == 0
|
||||
|
||||
def test_multiple_filters(self):
|
||||
resp = self.client.describe_db_instances(
|
||||
@ -115,9 +114,9 @@ class TestDBInstanceFilters:
|
||||
returned_identifiers = [
|
||||
db["DBInstanceIdentifier"] for db in resp["DBInstances"]
|
||||
]
|
||||
returned_identifiers.should.have.length_of(2)
|
||||
"db-instance-0".should.be.within(returned_identifiers)
|
||||
"db-instance-3".should.be.within(returned_identifiers)
|
||||
assert len(returned_identifiers) == 2
|
||||
assert "db-instance-0" in returned_identifiers
|
||||
assert "db-instance-3" in returned_identifiers
|
||||
|
||||
def test_invalid_db_instance_identifier_with_exclusive_filter(self):
|
||||
# Passing a non-existent DBInstanceIdentifier will not raise an error
|
||||
@ -126,8 +125,8 @@ class TestDBInstanceFilters:
|
||||
DBInstanceIdentifier="non-existent",
|
||||
Filters=[{"Name": "db-instance-id", "Values": ["db-instance-1"]}],
|
||||
)
|
||||
resp["DBInstances"].should.have.length_of(1)
|
||||
resp["DBInstances"][0]["DBInstanceIdentifier"].should.equal("db-instance-1")
|
||||
assert len(resp["DBInstances"]) == 1
|
||||
assert resp["DBInstances"][0]["DBInstanceIdentifier"] == "db-instance-1"
|
||||
|
||||
def test_invalid_db_instance_identifier_with_non_matching_filter(self):
|
||||
# Passing a non-existent DBInstanceIdentifier will raise an error if
|
||||
@ -137,8 +136,8 @@ class TestDBInstanceFilters:
|
||||
DBInstanceIdentifier="non-existent",
|
||||
Filters=[{"Name": "engine", "Values": ["mysql"]}],
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("DBInstanceNotFound")
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
assert ex.value.response["Error"]["Code"] == "DBInstanceNotFound"
|
||||
assert ex.value.response["Error"]["Message"] == (
|
||||
"DBInstance non-existent not found."
|
||||
)
|
||||
|
||||
@ -155,8 +154,8 @@ class TestDBInstanceFilters:
|
||||
returned_identifiers = [
|
||||
db["DBInstanceIdentifier"] for db in resp["DBInstances"]
|
||||
]
|
||||
"db-instance-0".should_not.be.within(returned_identifiers)
|
||||
"db-instance-1".should.be.within(returned_identifiers)
|
||||
assert "db-instance-0" not in returned_identifiers
|
||||
assert "db-instance-1" in returned_identifiers
|
||||
|
||||
def test_valid_db_instance_identifier_with_inclusive_filter(self):
|
||||
# Passing a valid DBInstanceIdentifier with a filter it matches but also
|
||||
@ -171,8 +170,8 @@ class TestDBInstanceFilters:
|
||||
returned_identifiers = [
|
||||
db["DBInstanceIdentifier"] for db in resp["DBInstances"]
|
||||
]
|
||||
"db-instance-0".should.be.within(returned_identifiers)
|
||||
"db-instance-1".should.be.within(returned_identifiers)
|
||||
assert "db-instance-0" in returned_identifiers
|
||||
assert "db-instance-1" in returned_identifiers
|
||||
|
||||
def test_valid_db_instance_identifier_with_non_matching_filter(self):
|
||||
# Passing a valid DBInstanceIdentifier will raise an error if the
|
||||
@ -182,8 +181,8 @@ class TestDBInstanceFilters:
|
||||
DBInstanceIdentifier="db-instance-0",
|
||||
Filters=[{"Name": "engine", "Values": ["postgres"]}],
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("DBInstanceNotFound")
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
assert ex.value.response["Error"]["Code"] == "DBInstanceNotFound"
|
||||
assert ex.value.response["Error"]["Message"] == (
|
||||
"DBInstance db-instance-0 not found."
|
||||
)
|
||||
|
||||
@ -224,8 +223,8 @@ class TestDBSnapshotFilters:
|
||||
self.client.describe_db_snapshots(
|
||||
Filters=[{"Name": "invalid-filter-name", "Values": []}]
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("InvalidParameterValue")
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
assert ex.value.response["Error"]["Code"] == "InvalidParameterValue"
|
||||
assert ex.value.response["Error"]["Message"] == (
|
||||
"Unrecognized filter name: invalid-filter-name"
|
||||
)
|
||||
|
||||
@ -234,15 +233,15 @@ class TestDBSnapshotFilters:
|
||||
self.client.describe_db_snapshots(
|
||||
Filters=[{"Name": "db-snapshot-id", "Values": []}]
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("InvalidParameterCombination")
|
||||
ex.value.response["Error"]["Message"].should.contain("must not be empty")
|
||||
assert ex.value.response["Error"]["Code"] == "InvalidParameterCombination"
|
||||
assert "must not be empty" in ex.value.response["Error"]["Message"]
|
||||
|
||||
def test_db_snapshot_id_filter(self):
|
||||
snapshots = self.client.describe_db_snapshots(
|
||||
Filters=[{"Name": "db-snapshot-id", "Values": ["db-instance-1-snapshot-0"]}]
|
||||
).get("DBSnapshots")
|
||||
snapshots.should.have.length_of(1)
|
||||
snapshots[0]["DBSnapshotIdentifier"].should.equal("db-instance-1-snapshot-0")
|
||||
assert len(snapshots) == 1
|
||||
assert snapshots[0]["DBSnapshotIdentifier"] == "db-instance-1-snapshot-0"
|
||||
|
||||
def test_db_instance_id_filter(self):
|
||||
resp = self.client.describe_db_instances()
|
||||
@ -252,7 +251,7 @@ class TestDBSnapshotFilters:
|
||||
Filters=[{"Name": "db-instance-id", "Values": [db_instance_identifier]}]
|
||||
).get("DBSnapshots")
|
||||
for snapshot in snapshots:
|
||||
snapshot["DBInstanceIdentifier"].should.equal(db_instance_identifier)
|
||||
assert snapshot["DBInstanceIdentifier"] == db_instance_identifier
|
||||
|
||||
def test_db_instance_id_filter_works_with_arns(self):
|
||||
resp = self.client.describe_db_instances()
|
||||
@ -263,7 +262,7 @@ class TestDBSnapshotFilters:
|
||||
Filters=[{"Name": "db-instance-id", "Values": [db_instance_arn]}]
|
||||
).get("DBSnapshots")
|
||||
for snapshot in snapshots:
|
||||
snapshot["DBInstanceIdentifier"].should.equal(db_instance_identifier)
|
||||
assert snapshot["DBInstanceIdentifier"] == db_instance_identifier
|
||||
|
||||
def test_dbi_resource_id_filter(self):
|
||||
resp = self.client.describe_db_instances()
|
||||
@ -273,19 +272,19 @@ class TestDBSnapshotFilters:
|
||||
Filters=[{"Name": "dbi-resource-id", "Values": [dbi_resource_identifier]}]
|
||||
).get("DBSnapshots")
|
||||
for snapshot in snapshots:
|
||||
snapshot["DbiResourceId"].should.equal(dbi_resource_identifier)
|
||||
assert snapshot["DbiResourceId"] == dbi_resource_identifier
|
||||
|
||||
def test_engine_filter(self):
|
||||
snapshots = self.client.describe_db_snapshots(
|
||||
Filters=[{"Name": "engine", "Values": ["postgres"]}]
|
||||
).get("DBSnapshots")
|
||||
for snapshot in snapshots:
|
||||
snapshot["Engine"].should.equal("postgres")
|
||||
assert snapshot["Engine"] == "postgres"
|
||||
|
||||
snapshots = self.client.describe_db_snapshots(
|
||||
Filters=[{"Name": "engine", "Values": ["oracle"]}]
|
||||
).get("DBSnapshots")
|
||||
snapshots.should.have.length_of(0)
|
||||
assert len(snapshots) == 0
|
||||
|
||||
def test_snapshot_type_filter(self):
|
||||
snapshots = self.client.describe_db_snapshots(
|
||||
@ -310,8 +309,8 @@ class TestDBSnapshotFilters:
|
||||
{"Name": "engine", "Values": ["mysql"]},
|
||||
]
|
||||
).get("DBSnapshots")
|
||||
snapshots.should.have.length_of(1)
|
||||
snapshots[0]["DBSnapshotIdentifier"].should.equal("db-instance-0-snapshot-1")
|
||||
assert len(snapshots) == 1
|
||||
assert snapshots[0]["DBSnapshotIdentifier"] == "db-instance-0-snapshot-1"
|
||||
|
||||
def test_invalid_snapshot_id_with_db_instance_id_and_filter(self):
|
||||
# Passing a non-existent DBSnapshotIdentifier will return an empty list
|
||||
@ -321,7 +320,7 @@ class TestDBSnapshotFilters:
|
||||
DBInstanceIdentifier="a-db-instance-identifier",
|
||||
Filters=[{"Name": "db-instance-id", "Values": ["db-instance-1"]}],
|
||||
)
|
||||
resp["DBSnapshots"].should.have.length_of(0)
|
||||
assert len(resp["DBSnapshots"]) == 0
|
||||
|
||||
def test_invalid_snapshot_id_with_non_matching_filter(self):
|
||||
# Passing a non-existent DBSnapshotIdentifier will raise an error if
|
||||
@ -331,8 +330,8 @@ class TestDBSnapshotFilters:
|
||||
DBSnapshotIdentifier="non-existent",
|
||||
Filters=[{"Name": "engine", "Values": ["oracle"]}],
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("DBSnapshotNotFound")
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
assert ex.value.response["Error"]["Code"] == "DBSnapshotNotFound"
|
||||
assert ex.value.response["Error"]["Message"] == (
|
||||
"DBSnapshot non-existent not found."
|
||||
)
|
||||
|
||||
@ -347,8 +346,8 @@ class TestDBSnapshotFilters:
|
||||
{"Name": "engine", "Values": ["postgres"]},
|
||||
],
|
||||
)
|
||||
resp["DBSnapshots"].should.have.length_of(1)
|
||||
resp["DBSnapshots"][0]["DBSnapshotIdentifier"].should.equal(
|
||||
assert len(resp["DBSnapshots"]) == 1
|
||||
assert resp["DBSnapshots"][0]["DBSnapshotIdentifier"] == (
|
||||
"db-instance-1-snapshot-1"
|
||||
)
|
||||
|
||||
@ -367,9 +366,9 @@ class TestDBSnapshotFilters:
|
||||
],
|
||||
).get("DBSnapshots")
|
||||
returned_identifiers = [ss["DBSnapshotIdentifier"] for ss in snapshots]
|
||||
returned_identifiers.should.have.length_of(2)
|
||||
"db-instance-0-snapshot-0".should.be.within(returned_identifiers)
|
||||
"db-instance-1-snapshot-1".should.be.within(returned_identifiers)
|
||||
assert len(returned_identifiers) == 2
|
||||
assert "db-instance-0-snapshot-0" in returned_identifiers
|
||||
assert "db-instance-1-snapshot-1" in returned_identifiers
|
||||
|
||||
def test_valid_snapshot_id_with_non_matching_filter(self):
|
||||
# Passing a valid DBSnapshotIdentifier will raise an error if the
|
||||
@ -379,8 +378,8 @@ class TestDBSnapshotFilters:
|
||||
DBSnapshotIdentifier="db-instance-0-snapshot-0",
|
||||
Filters=[{"Name": "engine", "Values": ["postgres"]}],
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("DBSnapshotNotFound")
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
assert ex.value.response["Error"]["Code"] == "DBSnapshotNotFound"
|
||||
assert ex.value.response["Error"]["Message"] == (
|
||||
"DBSnapshot db-instance-0-snapshot-0 not found."
|
||||
)
|
||||
|
||||
@ -422,8 +421,8 @@ class TestDBClusterSnapshotFilters:
|
||||
self.client.describe_db_cluster_snapshots(
|
||||
Filters=[{"Name": "invalid-filter-name", "Values": []}]
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("InvalidParameterValue")
|
||||
ex.value.response["Error"]["Message"].should.equal(
|
||||
assert ex.value.response["Error"]["Code"] == "InvalidParameterValue"
|
||||
assert ex.value.response["Error"]["Message"] == (
|
||||
"Unrecognized filter name: invalid-filter-name"
|
||||
)
|
||||
|
||||
@ -432,8 +431,8 @@ class TestDBClusterSnapshotFilters:
|
||||
self.client.describe_db_cluster_snapshots(
|
||||
Filters=[{"Name": "snapshot-type", "Values": []}]
|
||||
)
|
||||
ex.value.response["Error"]["Code"].should.equal("InvalidParameterCombination")
|
||||
ex.value.response["Error"]["Message"].should.contain("must not be empty")
|
||||
assert ex.value.response["Error"]["Code"] == "InvalidParameterCombination"
|
||||
assert "must not be empty" in ex.value.response["Error"]["Message"]
|
||||
|
||||
def test_snapshot_type_filter(self):
|
||||
snapshots = self.client.describe_db_cluster_snapshots(
|
||||
|
@ -1,7 +1,7 @@
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_rds
|
||||
from moto.core import DEFAULT_ACCOUNT_ID
|
||||
|
||||
@ -65,7 +65,8 @@ def test_global_cluster_members():
|
||||
@mock_rds
|
||||
def test_create_global_cluster_from_regular_cluster():
|
||||
# WHEN create_db_cluster is called
|
||||
# AND create_global_cluster is called with SourceDBClusterIdentifier set as the earlier created db cluster
|
||||
# AND create_global_cluster is called with SourceDBClusterIdentifier
|
||||
# set as the earlier created db cluster
|
||||
# THEN that db cluster is elevated to a global cluster
|
||||
# AND it still shows up when calling describe_db_clusters
|
||||
client = boto3.client("rds", "us-east-1")
|
||||
@ -184,9 +185,10 @@ def test_create_global_cluster_from_regular_cluster__and_specify_engine():
|
||||
)
|
||||
err = exc.value.response["Error"]
|
||||
assert err["Code"] == "InvalidParameterCombination"
|
||||
assert (
|
||||
err["Message"]
|
||||
== "When creating global cluster from existing db cluster, value for engineName should not be specified since it will be inherited from source cluster"
|
||||
assert err["Message"] == (
|
||||
"When creating global cluster from existing db cluster, value for "
|
||||
"engineName should not be specified since it will be inherited "
|
||||
"from source cluster"
|
||||
)
|
||||
|
||||
|
||||
@ -195,11 +197,13 @@ def test_delete_non_global_cluster():
|
||||
# WHEN a global cluster contains a regular cluster
|
||||
# AND we attempt to delete the global cluster
|
||||
# THEN we get an error message
|
||||
# An error occurs (InvalidGlobalClusterStateFault) when calling the DeleteGlobalCluster operation: Global Cluster arn:aws:rds::486285699788:global-cluster:g1 is not empty
|
||||
# An error occurs (InvalidGlobalClusterStateFault) when calling the
|
||||
# DeleteGlobalCluster operation: Global Cluster
|
||||
# arn:aws:rds::486285699788:global-cluster:g1 is not empty
|
||||
client = boto3.client("rds", "us-east-1")
|
||||
|
||||
client.create_global_cluster(GlobalClusterIdentifier="gc1", Engine="aurora-mysql")
|
||||
client.create_db_cluster(
|
||||
_ = client.create_db_cluster(
|
||||
DBClusterIdentifier="dbci",
|
||||
GlobalClusterIdentifier="gc1",
|
||||
Engine="mysql",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
||||
import boto3
|
||||
import json
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
import boto3
|
||||
|
||||
from moto import mock_cloudformation, mock_ec2, mock_rds
|
||||
from tests.test_cloudformation.fixtures import rds_mysql_with_db_parameter_group
|
||||
from tests.test_cloudformation.fixtures import rds_mysql_with_read_replica
|
||||
@ -36,12 +37,12 @@ def test_create_subnetgroup_via_cf():
|
||||
cf.create_stack(StackName="test_stack", TemplateBody=template_json)
|
||||
|
||||
response = rds.describe_db_subnet_groups()["DBSubnetGroups"]
|
||||
response.should.have.length_of(1)
|
||||
assert len(response) == 1
|
||||
|
||||
created_subnet = response[0]
|
||||
created_subnet.should.have.key("DBSubnetGroupName").equal("subnetgroupname")
|
||||
created_subnet.should.have.key("DBSubnetGroupDescription").equal("subnetgroupdesc")
|
||||
created_subnet.should.have.key("VpcId").equal(vpc["VpcId"])
|
||||
assert created_subnet["DBSubnetGroupName"] == "subnetgroupname"
|
||||
assert created_subnet["DBSubnetGroupDescription"] == "subnetgroupdesc"
|
||||
assert created_subnet["VpcId"] == vpc["VpcId"]
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@ -82,19 +83,19 @@ def test_create_dbinstance_via_cf():
|
||||
|
||||
db_instance_identifier = summaries[0]["PhysicalResourceId"]
|
||||
resp = rds.describe_db_instances()["DBInstances"]
|
||||
resp.should.have.length_of(1)
|
||||
assert len(resp) == 1
|
||||
|
||||
created = resp[0]
|
||||
created["DBInstanceIdentifier"].should.equal(db_instance_identifier)
|
||||
created["Engine"].should.equal("mysql")
|
||||
created["DBInstanceStatus"].should.equal("available")
|
||||
assert created["DBInstanceIdentifier"] == db_instance_identifier
|
||||
assert created["Engine"] == "mysql"
|
||||
assert created["DBInstanceStatus"] == "available"
|
||||
|
||||
# Verify the stack outputs are correct
|
||||
o = _get_stack_outputs(cf, stack_name="test_stack")
|
||||
o.should.have.key("db_address").equals(
|
||||
assert o["db_address"] == (
|
||||
f"{db_instance_identifier}.aaaaaaaaaa.us-west-2.rds.amazonaws.com"
|
||||
)
|
||||
o.should.have.key("db_port").equals("3307")
|
||||
assert o["db_port"] == "3307"
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@ -121,10 +122,10 @@ def test_create_dbsecuritygroup_via_cf():
|
||||
cf.create_stack(StackName="test_stack", TemplateBody=template_json)
|
||||
|
||||
result = rds.describe_db_security_groups()["DBSecurityGroups"]
|
||||
result.should.have.length_of(1)
|
||||
assert len(result) == 1
|
||||
|
||||
created = result[0]
|
||||
created["DBSecurityGroupDescription"].should.equal("my sec group")
|
||||
assert created["DBSecurityGroupDescription"] == "my sec group"
|
||||
|
||||
|
||||
@mock_cloudformation
|
||||
@ -159,7 +160,7 @@ def test_rds_db_parameter_groups():
|
||||
rds_conn = boto3.client("rds", region_name="us-west-1")
|
||||
|
||||
db_parameter_groups = rds_conn.describe_db_parameter_groups()
|
||||
db_parameter_groups["DBParameterGroups"].should.have.length_of(1)
|
||||
assert len(db_parameter_groups["DBParameterGroups"]) == 1
|
||||
db_parameter_group_name = db_parameter_groups["DBParameterGroups"][0][
|
||||
"DBParameterGroupName"
|
||||
]
|
||||
@ -174,7 +175,7 @@ def test_rds_db_parameter_groups():
|
||||
):
|
||||
found_cloudformation_set_parameter = True
|
||||
|
||||
found_cloudformation_set_parameter.should.equal(True)
|
||||
assert found_cloudformation_set_parameter is True
|
||||
|
||||
|
||||
@mock_cloudformation
|
||||
@ -260,7 +261,7 @@ def test_rds_mysql_with_read_replica_in_vpc():
|
||||
subnet_group = rds.describe_db_subnet_groups(DBSubnetGroupName=subnet_group_name)[
|
||||
"DBSubnetGroups"
|
||||
][0]
|
||||
subnet_group.should.have.key("DBSubnetGroupDescription").equal("my db subnet group")
|
||||
assert subnet_group["DBSubnetGroupDescription"] == "my db subnet group"
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@ -292,12 +293,12 @@ def test_delete_dbinstance_via_cf():
|
||||
cf.create_stack(StackName="test_stack", TemplateBody=template_json)
|
||||
|
||||
resp = rds.describe_db_instances()["DBInstances"]
|
||||
resp.should.have.length_of(1)
|
||||
assert len(resp) == 1
|
||||
|
||||
cf.delete_stack(StackName="test_stack")
|
||||
|
||||
resp = rds.describe_db_instances()["DBInstances"]
|
||||
resp.should.have.length_of(0)
|
||||
assert len(resp) == 0
|
||||
|
||||
|
||||
def _get_stack_outputs(cf_client, stack_name):
|
||||
|
@ -1,8 +1,9 @@
|
||||
import boto3
|
||||
import pytest
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
import re
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from moto import mock_rds
|
||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||
|
||||
@ -12,7 +13,7 @@ def test_describe_db_cluster_initial():
|
||||
client = boto3.client("rds", region_name="eu-north-1")
|
||||
|
||||
resp = client.describe_db_clusters()
|
||||
resp.should.have.key("DBClusters").should.have.length_of(0)
|
||||
assert len(resp["DBClusters"]) == 0
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -20,12 +21,12 @@ def test_describe_db_cluster_fails_for_non_existent_cluster():
|
||||
client = boto3.client("rds", region_name="eu-north-1")
|
||||
|
||||
resp = client.describe_db_clusters()
|
||||
resp.should.have.key("DBClusters").should.have.length_of(0)
|
||||
assert len(resp["DBClusters"]) == 0
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.describe_db_clusters(DBClusterIdentifier="cluster-id")
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("DBClusterNotFoundFault")
|
||||
err["Message"].should.equal("DBCluster cluster-id not found.")
|
||||
assert err["Code"] == "DBClusterNotFoundFault"
|
||||
assert err["Message"] == "DBCluster cluster-id not found."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -35,8 +36,8 @@ def test_create_db_cluster_needs_master_username():
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_db_cluster(DBClusterIdentifier="cluster-id", Engine="aurora")
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("InvalidParameterValue")
|
||||
err["Message"].should.equal(
|
||||
assert err["Code"] == "InvalidParameterValue"
|
||||
assert err["Message"] == (
|
||||
"The parameter MasterUsername must be provided and must not be blank."
|
||||
)
|
||||
|
||||
@ -50,8 +51,8 @@ def test_create_db_cluster_needs_master_user_password():
|
||||
DBClusterIdentifier="cluster-id", Engine="aurora", MasterUsername="root"
|
||||
)
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("InvalidParameterValue")
|
||||
err["Message"].should.equal(
|
||||
assert err["Code"] == "InvalidParameterValue"
|
||||
assert err["Message"] == (
|
||||
"The parameter MasterUserPassword must be provided and must not be blank."
|
||||
)
|
||||
|
||||
@ -68,9 +69,10 @@ def test_create_db_cluster_needs_long_master_user_password():
|
||||
MasterUserPassword="hunter2",
|
||||
)
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("InvalidParameterValue")
|
||||
err["Message"].should.equal(
|
||||
"The parameter MasterUserPassword is not a valid password because it is shorter than 8 characters."
|
||||
assert err["Code"] == "InvalidParameterValue"
|
||||
assert err["Message"] == (
|
||||
"The parameter MasterUserPassword is not a valid password because "
|
||||
"it is shorter than 8 characters."
|
||||
)
|
||||
|
||||
|
||||
@ -91,9 +93,10 @@ def test_modify_db_cluster_needs_long_master_user_password():
|
||||
MasterUserPassword="hunter2",
|
||||
)
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("InvalidParameterValue")
|
||||
err["Message"].should.equal(
|
||||
"The parameter MasterUserPassword is not a valid password because it is shorter than 8 characters."
|
||||
assert err["Code"] == "InvalidParameterValue"
|
||||
assert err["Message"] == (
|
||||
"The parameter MasterUserPassword is not a valid password because "
|
||||
"it is shorter than 8 characters."
|
||||
)
|
||||
|
||||
|
||||
@ -116,7 +119,7 @@ def test_modify_db_cluster_new_cluster_identifier():
|
||||
MasterUserPassword="hunter21",
|
||||
)
|
||||
|
||||
resp["DBCluster"].should.have.key("DBClusterIdentifier").equal(new_id)
|
||||
assert resp["DBCluster"]["DBClusterIdentifier"] == new_id
|
||||
|
||||
clusters = [
|
||||
cluster["DBClusterIdentifier"]
|
||||
@ -136,61 +139,61 @@ def test_create_db_cluster__verify_default_properties():
|
||||
MasterUsername="root",
|
||||
MasterUserPassword="hunter2_",
|
||||
)
|
||||
resp.should.have.key("DBCluster")
|
||||
assert "DBCluster" in resp
|
||||
|
||||
cluster = resp["DBCluster"]
|
||||
|
||||
cluster.shouldnt.have.key(
|
||||
"DatabaseName"
|
||||
) # This was not supplied, so should not be returned
|
||||
# This was not supplied, so should not be returned
|
||||
assert "DatabaseName" not in cluster
|
||||
|
||||
cluster.should.have.key("AvailabilityZones")
|
||||
set(cluster["AvailabilityZones"]).should.equal(
|
||||
{"eu-north-1a", "eu-north-1b", "eu-north-1c"}
|
||||
)
|
||||
cluster.should.have.key("BackupRetentionPeriod").equal(1)
|
||||
cluster.should.have.key("DBClusterIdentifier").equal("cluster-id")
|
||||
cluster.should.have.key("DBClusterParameterGroup").equal("default.aurora8.0")
|
||||
cluster.should.have.key("DBSubnetGroup").equal("default")
|
||||
cluster.should.have.key("Status").equal("creating")
|
||||
cluster.should.have.key("Endpoint").match(
|
||||
"cluster-id.cluster-[a-z0-9]{12}.eu-north-1.rds.amazonaws.com"
|
||||
assert "AvailabilityZones" in cluster
|
||||
assert set(cluster["AvailabilityZones"]) == {
|
||||
"eu-north-1a",
|
||||
"eu-north-1b",
|
||||
"eu-north-1c",
|
||||
}
|
||||
assert cluster["BackupRetentionPeriod"] == 1
|
||||
assert cluster["DBClusterIdentifier"] == "cluster-id"
|
||||
assert cluster["DBClusterParameterGroup"] == "default.aurora8.0"
|
||||
assert cluster["DBSubnetGroup"] == "default"
|
||||
assert cluster["Status"] == "creating"
|
||||
assert re.match(
|
||||
"cluster-id.cluster-[a-z0-9]{12}.eu-north-1.rds.amazonaws.com",
|
||||
cluster["Endpoint"],
|
||||
)
|
||||
endpoint = cluster["Endpoint"]
|
||||
expected_readonly = endpoint.replace(
|
||||
"cluster-id.cluster-", "cluster-id.cluster-ro-"
|
||||
)
|
||||
cluster.should.have.key("ReaderEndpoint").equal(expected_readonly)
|
||||
cluster.should.have.key("MultiAZ").equal(False)
|
||||
cluster.should.have.key("Engine").equal("aurora")
|
||||
cluster.should.have.key("EngineVersion").equal("5.6.mysql_aurora.1.22.5")
|
||||
cluster.should.have.key("Port").equal(3306)
|
||||
cluster.should.have.key("MasterUsername").equal("root")
|
||||
cluster.should.have.key("PreferredBackupWindow").equal("01:37-02:07")
|
||||
cluster.should.have.key("PreferredMaintenanceWindow").equal("wed:02:40-wed:03:10")
|
||||
cluster.should.have.key("ReadReplicaIdentifiers").equal([])
|
||||
cluster.should.have.key("DBClusterMembers").equal([])
|
||||
cluster.should.have.key("VpcSecurityGroups")
|
||||
cluster.should.have.key("HostedZoneId")
|
||||
cluster.should.have.key("StorageEncrypted").equal(False)
|
||||
cluster.should.have.key("DbClusterResourceId").match(r"cluster-[A-Z0-9]{26}")
|
||||
cluster.should.have.key("DBClusterArn").equal(
|
||||
assert cluster["ReaderEndpoint"] == expected_readonly
|
||||
assert cluster["MultiAZ"] is False
|
||||
assert cluster["Engine"] == "aurora"
|
||||
assert cluster["EngineVersion"] == "5.6.mysql_aurora.1.22.5"
|
||||
assert cluster["Port"] == 3306
|
||||
assert cluster["MasterUsername"] == "root"
|
||||
assert cluster["PreferredBackupWindow"] == "01:37-02:07"
|
||||
assert cluster["PreferredMaintenanceWindow"] == "wed:02:40-wed:03:10"
|
||||
assert cluster["ReadReplicaIdentifiers"] == []
|
||||
assert cluster["DBClusterMembers"] == []
|
||||
assert "VpcSecurityGroups" in cluster
|
||||
assert "HostedZoneId" in cluster
|
||||
assert cluster["StorageEncrypted"] is False
|
||||
assert re.match(r"cluster-[A-Z0-9]{26}", cluster["DbClusterResourceId"])
|
||||
assert cluster["DBClusterArn"] == (
|
||||
f"arn:aws:rds:eu-north-1:{ACCOUNT_ID}:cluster:cluster-id"
|
||||
)
|
||||
cluster.should.have.key("AssociatedRoles").equal([])
|
||||
cluster.should.have.key("IAMDatabaseAuthenticationEnabled").equal(False)
|
||||
cluster.should.have.key("EngineMode").equal("provisioned")
|
||||
cluster.should.have.key("DeletionProtection").equal(False)
|
||||
cluster.should.have.key("HttpEndpointEnabled").equal(False)
|
||||
cluster.should.have.key("CopyTagsToSnapshot").equal(False)
|
||||
cluster.should.have.key("CrossAccountClone").equal(False)
|
||||
cluster.should.have.key("DeletionProtection").equal(False)
|
||||
cluster.should.have.key("DomainMemberships").equal([])
|
||||
cluster.should.have.key("TagList").equal([])
|
||||
cluster.should.have.key("ClusterCreateTime")
|
||||
cluster.should.have.key(
|
||||
"EarliestRestorableTime"
|
||||
).should.be.greater_than_or_equal_to(cluster["ClusterCreateTime"])
|
||||
assert cluster["AssociatedRoles"] == []
|
||||
assert cluster["IAMDatabaseAuthenticationEnabled"] is False
|
||||
assert cluster["EngineMode"] == "provisioned"
|
||||
assert cluster["DeletionProtection"] is False
|
||||
assert cluster["HttpEndpointEnabled"] is False
|
||||
assert cluster["CopyTagsToSnapshot"] is False
|
||||
assert cluster["CrossAccountClone"] is False
|
||||
assert cluster["DeletionProtection"] is False
|
||||
assert cluster["DomainMemberships"] == []
|
||||
assert cluster["TagList"] == []
|
||||
assert "ClusterCreateTime" in cluster
|
||||
assert cluster["EarliestRestorableTime"] >= cluster["ClusterCreateTime"]
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -221,14 +224,14 @@ def test_create_db_cluster_additional_parameters():
|
||||
|
||||
cluster = resp["DBCluster"]
|
||||
|
||||
cluster.should.have.key("AvailabilityZones").equal(["eu-north-1b"])
|
||||
cluster.should.have.key("DatabaseName").equal("users")
|
||||
cluster.should.have.key("Engine").equal("aurora")
|
||||
cluster.should.have.key("EngineVersion").equal("8.0.mysql_aurora.3.01.0")
|
||||
cluster.should.have.key("EngineMode").equal("serverless")
|
||||
cluster.should.have.key("Port").equal(1234)
|
||||
cluster.should.have.key("DeletionProtection").equal(True)
|
||||
cluster.should.have.key("EnabledCloudwatchLogsExports").equals(["audit"])
|
||||
assert cluster["AvailabilityZones"] == ["eu-north-1b"]
|
||||
assert cluster["DatabaseName"] == "users"
|
||||
assert cluster["Engine"] == "aurora"
|
||||
assert cluster["EngineVersion"] == "8.0.mysql_aurora.3.01.0"
|
||||
assert cluster["EngineMode"] == "serverless"
|
||||
assert cluster["Port"] == 1234
|
||||
assert cluster["DeletionProtection"] is True
|
||||
assert cluster["EnabledCloudwatchLogsExports"] == ["audit"]
|
||||
assert cluster["KmsKeyId"] == "some:kms:arn"
|
||||
assert cluster["NetworkType"] == "IPV4"
|
||||
assert cluster["DBSubnetGroup"] == "subnetgroupname"
|
||||
@ -258,15 +261,19 @@ def test_describe_db_cluster_after_creation():
|
||||
MasterUserPassword="hunter2_",
|
||||
)["DBCluster"]["DBClusterArn"]
|
||||
|
||||
client.describe_db_clusters()["DBClusters"].should.have.length_of(2)
|
||||
assert len(client.describe_db_clusters()["DBClusters"]) == 2
|
||||
|
||||
client.describe_db_clusters(DBClusterIdentifier="cluster-id2")[
|
||||
"DBClusters"
|
||||
].should.have.length_of(1)
|
||||
assert (
|
||||
len(
|
||||
client.describe_db_clusters(DBClusterIdentifier="cluster-id2")["DBClusters"]
|
||||
)
|
||||
== 1
|
||||
)
|
||||
|
||||
client.describe_db_clusters(DBClusterIdentifier=cluster_arn)[
|
||||
"DBClusters"
|
||||
].should.have.length_of(1)
|
||||
assert (
|
||||
len(client.describe_db_clusters(DBClusterIdentifier=cluster_arn)["DBClusters"])
|
||||
== 1
|
||||
)
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -282,7 +289,7 @@ def test_delete_db_cluster():
|
||||
|
||||
client.delete_db_cluster(DBClusterIdentifier="cluster-id")
|
||||
|
||||
client.describe_db_clusters()["DBClusters"].should.have.length_of(0)
|
||||
assert len(client.describe_db_clusters()["DBClusters"]) == 0
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -299,7 +306,7 @@ def test_delete_db_cluster_do_snapshot():
|
||||
client.delete_db_cluster(
|
||||
DBClusterIdentifier="cluster-id", FinalDBSnapshotIdentifier="final-snapshot"
|
||||
)
|
||||
client.describe_db_clusters()["DBClusters"].should.have.length_of(0)
|
||||
assert len(client.describe_db_clusters()["DBClusters"]) == 0
|
||||
snapshot = client.describe_db_cluster_snapshots()["DBClusterSnapshots"][0]
|
||||
assert snapshot["DBClusterIdentifier"] == "cluster-id"
|
||||
assert snapshot["DBClusterSnapshotIdentifier"] == "final-snapshot"
|
||||
@ -321,7 +328,7 @@ def test_delete_db_cluster_that_is_protected():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.delete_db_cluster(DBClusterIdentifier="cluster-id")
|
||||
err = exc.value.response["Error"]
|
||||
err["Message"].should.equal("Can't delete Cluster with protection enabled")
|
||||
assert err["Message"] == "Can't delete Cluster with protection enabled"
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -331,8 +338,8 @@ def test_delete_db_cluster_unknown_cluster():
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.delete_db_cluster(DBClusterIdentifier="cluster-unknown")
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("DBClusterNotFoundFault")
|
||||
err["Message"].should.equal("DBCluster cluster-unknown not found.")
|
||||
assert err["Code"] == "DBClusterNotFoundFault"
|
||||
assert err["Message"] == "DBCluster cluster-unknown not found."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -342,8 +349,8 @@ def test_start_db_cluster_unknown_cluster():
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.start_db_cluster(DBClusterIdentifier="cluster-unknown")
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("DBClusterNotFoundFault")
|
||||
err["Message"].should.equal("DBCluster cluster-unknown not found.")
|
||||
assert err["Code"] == "DBClusterNotFoundFault"
|
||||
assert err["Message"] == "DBCluster cluster-unknown not found."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -360,7 +367,7 @@ def test_start_db_cluster_after_stopping():
|
||||
|
||||
client.start_db_cluster(DBClusterIdentifier="cluster-id")
|
||||
cluster = client.describe_db_clusters()["DBClusters"][0]
|
||||
cluster["Status"].should.equal("available")
|
||||
assert cluster["Status"] == "available"
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -377,8 +384,8 @@ def test_start_db_cluster_without_stopping():
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.start_db_cluster(DBClusterIdentifier="cluster-id")
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("InvalidDBClusterStateFault")
|
||||
err["Message"].should.equal("DbCluster cluster-id is not in stopped state.")
|
||||
assert err["Code"] == "InvalidDBClusterStateFault"
|
||||
assert err["Message"] == "DbCluster cluster-id is not in stopped state."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -395,11 +402,11 @@ def test_stop_db_cluster():
|
||||
resp = client.stop_db_cluster(DBClusterIdentifier="cluster-id")
|
||||
# Quirk of the AWS implementation - the immediate response show it's still available
|
||||
cluster = resp["DBCluster"]
|
||||
cluster["Status"].should.equal("available")
|
||||
assert cluster["Status"] == "available"
|
||||
# For some time the status will be 'stopping'
|
||||
# And finally it will be 'stopped'
|
||||
cluster = client.describe_db_clusters()["DBClusters"][0]
|
||||
cluster["Status"].should.equal("stopped")
|
||||
assert cluster["Status"] == "stopped"
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -418,8 +425,8 @@ def test_stop_db_cluster_already_stopped():
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.stop_db_cluster(DBClusterIdentifier="cluster-id")
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("InvalidDBClusterStateFault")
|
||||
err["Message"].should.equal("DbCluster cluster-id is not in available state.")
|
||||
assert err["Code"] == "InvalidDBClusterStateFault"
|
||||
assert err["Message"] == "DbCluster cluster-id is not in available state."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -429,8 +436,8 @@ def test_stop_db_cluster_unknown_cluster():
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.stop_db_cluster(DBClusterIdentifier="cluster-unknown")
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("DBClusterNotFoundFault")
|
||||
err["Message"].should.equal("DBCluster cluster-unknown not found.")
|
||||
assert err["Code"] == "DBClusterNotFoundFault"
|
||||
assert err["Message"] == "DBCluster cluster-unknown not found."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -441,7 +448,7 @@ def test_create_db_cluster_snapshot_fails_for_unknown_cluster():
|
||||
DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1"
|
||||
)
|
||||
err = exc.value.response["Error"]
|
||||
err["Message"].should.equal("DBCluster db-primary-1 not found.")
|
||||
assert err["Message"] == "DBCluster db-primary-1 not found."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -467,7 +474,7 @@ def test_create_db_cluster_snapshot():
|
||||
assert snapshot["DBClusterSnapshotIdentifier"] == "g-1"
|
||||
assert snapshot["SnapshotType"] == "manual"
|
||||
result = conn.list_tags_for_resource(ResourceName=snapshot["DBClusterSnapshotArn"])
|
||||
result["TagList"].should.equal([])
|
||||
assert result["TagList"] == []
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -491,14 +498,15 @@ def test_create_db_cluster_snapshot_copy_tags():
|
||||
DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="g-1"
|
||||
).get("DBClusterSnapshot")
|
||||
|
||||
snapshot.get("Engine").should.equal("postgres")
|
||||
snapshot.get("DBClusterIdentifier").should.equal("db-primary-1")
|
||||
snapshot.get("DBClusterSnapshotIdentifier").should.equal("g-1")
|
||||
assert snapshot.get("Engine") == "postgres"
|
||||
assert snapshot.get("DBClusterIdentifier") == "db-primary-1"
|
||||
assert snapshot.get("DBClusterSnapshotIdentifier") == "g-1"
|
||||
|
||||
result = conn.list_tags_for_resource(ResourceName=snapshot["DBClusterSnapshotArn"])
|
||||
result["TagList"].should.equal(
|
||||
[{"Value": "bar", "Key": "foo"}, {"Value": "bar1", "Key": "foo1"}]
|
||||
)
|
||||
assert result["TagList"] == [
|
||||
{"Value": "bar", "Key": "foo"},
|
||||
{"Value": "bar1", "Key": "foo1"},
|
||||
]
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -512,7 +520,7 @@ def test_copy_db_cluster_snapshot_fails_for_unknown_snapshot():
|
||||
)
|
||||
|
||||
err = exc.value.response["Error"]
|
||||
err["Message"].should.equal("DBClusterSnapshot snapshot-1 not found.")
|
||||
assert err["Message"] == "DBClusterSnapshot snapshot-1 not found."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -539,13 +547,13 @@ def test_copy_db_cluster_snapshot():
|
||||
TargetDBClusterSnapshotIdentifier="snapshot-2",
|
||||
).get("DBClusterSnapshot")
|
||||
|
||||
target_snapshot.get("Engine").should.equal("postgres")
|
||||
target_snapshot.get("DBClusterIdentifier").should.equal("db-primary-1")
|
||||
target_snapshot.get("DBClusterSnapshotIdentifier").should.equal("snapshot-2")
|
||||
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(
|
||||
ResourceName=target_snapshot["DBClusterSnapshotArn"]
|
||||
)
|
||||
result["TagList"].should.equal([])
|
||||
assert result["TagList"] == []
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -578,8 +586,9 @@ def test_copy_db_cluster_snapshot_fails_for_existed_target_snapshot():
|
||||
)
|
||||
|
||||
err = exc.value.response["Error"]
|
||||
err["Message"].should.equal(
|
||||
"Cannot create the snapshot because a snapshot with the identifier snapshot-2 already exists."
|
||||
assert err["Message"] == (
|
||||
"Cannot create the snapshot because a snapshot with the identifier "
|
||||
"snapshot-2 already exists."
|
||||
)
|
||||
|
||||
|
||||
@ -601,7 +610,7 @@ def test_describe_db_cluster_snapshots():
|
||||
DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1"
|
||||
).get("DBClusterSnapshot")
|
||||
|
||||
created.get("Engine").should.equal("postgres")
|
||||
assert created.get("Engine") == "postgres"
|
||||
|
||||
by_database_id = conn.describe_db_cluster_snapshots(
|
||||
DBClusterIdentifier="db-primary-1"
|
||||
@ -609,11 +618,11 @@ def test_describe_db_cluster_snapshots():
|
||||
by_snapshot_id = conn.describe_db_cluster_snapshots(
|
||||
DBClusterSnapshotIdentifier="snapshot-1"
|
||||
).get("DBClusterSnapshots")
|
||||
by_snapshot_id.should.equal(by_database_id)
|
||||
assert by_snapshot_id == by_database_id
|
||||
|
||||
snapshot = by_snapshot_id[0]
|
||||
snapshot.should.equal(created)
|
||||
snapshot.get("Engine").should.equal("postgres")
|
||||
assert snapshot == created
|
||||
assert snapshot.get("Engine") == "postgres"
|
||||
|
||||
conn.create_db_cluster_snapshot(
|
||||
DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-2"
|
||||
@ -621,7 +630,7 @@ def test_describe_db_cluster_snapshots():
|
||||
snapshots = conn.describe_db_cluster_snapshots(
|
||||
DBClusterIdentifier="db-primary-1"
|
||||
).get("DBClusterSnapshots")
|
||||
snapshots.should.have.length_of(2)
|
||||
assert len(snapshots) == 2
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -643,9 +652,8 @@ def test_delete_db_cluster_snapshot():
|
||||
|
||||
conn.describe_db_cluster_snapshots(DBClusterSnapshotIdentifier="snapshot-1")
|
||||
conn.delete_db_cluster_snapshot(DBClusterSnapshotIdentifier="snapshot-1")
|
||||
conn.describe_db_cluster_snapshots.when.called_with(
|
||||
DBClusterSnapshotIdentifier="snapshot-1"
|
||||
).should.throw(ClientError)
|
||||
with pytest.raises(ClientError):
|
||||
conn.describe_db_cluster_snapshots(DBClusterSnapshotIdentifier="snapshot-1")
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -661,7 +669,7 @@ def test_restore_db_cluster_from_snapshot():
|
||||
MasterUserPassword="hunter2000",
|
||||
Port=1234,
|
||||
)
|
||||
conn.describe_db_clusters()["DBClusters"].should.have.length_of(1)
|
||||
assert len(conn.describe_db_clusters()["DBClusters"]) == 1
|
||||
|
||||
conn.create_db_cluster_snapshot(
|
||||
DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1"
|
||||
@ -673,17 +681,18 @@ def test_restore_db_cluster_from_snapshot():
|
||||
SnapshotIdentifier="snapshot-1",
|
||||
Engine="postgres",
|
||||
)["DBCluster"]
|
||||
new_cluster["DBClusterIdentifier"].should.equal("db-restore-1")
|
||||
new_cluster["DBClusterInstanceClass"].should.equal("db.m1.small")
|
||||
new_cluster["Engine"].should.equal("postgres")
|
||||
new_cluster["DatabaseName"].should.equal("staging-postgres")
|
||||
new_cluster["Port"].should.equal(1234)
|
||||
assert new_cluster["DBClusterIdentifier"] == "db-restore-1"
|
||||
assert new_cluster["DBClusterInstanceClass"] == "db.m1.small"
|
||||
assert new_cluster["Engine"] == "postgres"
|
||||
assert new_cluster["DatabaseName"] == "staging-postgres"
|
||||
assert new_cluster["Port"] == 1234
|
||||
|
||||
# Verify it exists
|
||||
conn.describe_db_clusters()["DBClusters"].should.have.length_of(2)
|
||||
conn.describe_db_clusters(DBClusterIdentifier="db-restore-1")[
|
||||
"DBClusters"
|
||||
].should.have.length_of(1)
|
||||
assert len(conn.describe_db_clusters()["DBClusters"]) == 2
|
||||
assert (
|
||||
len(conn.describe_db_clusters(DBClusterIdentifier="db-restore-1")["DBClusters"])
|
||||
== 1
|
||||
)
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -699,7 +708,7 @@ def test_restore_db_cluster_from_snapshot_and_override_params():
|
||||
MasterUserPassword="hunter2000",
|
||||
Port=1234,
|
||||
)
|
||||
conn.describe_db_clusters()["DBClusters"].should.have.length_of(1)
|
||||
assert len(conn.describe_db_clusters()["DBClusters"]) == 1
|
||||
conn.create_db_cluster_snapshot(
|
||||
DBClusterIdentifier="db-primary-1", DBClusterSnapshotIdentifier="snapshot-1"
|
||||
)
|
||||
@ -712,10 +721,10 @@ def test_restore_db_cluster_from_snapshot_and_override_params():
|
||||
Port=10000,
|
||||
DBClusterInstanceClass="db.r6g.xlarge",
|
||||
)["DBCluster"]
|
||||
new_cluster["DBClusterIdentifier"].should.equal("db-restore-1")
|
||||
new_cluster["DBClusterParameterGroup"].should.equal("default.aurora8.0")
|
||||
new_cluster["DBClusterInstanceClass"].should.equal("db.r6g.xlarge")
|
||||
new_cluster["Port"].should.equal(10000)
|
||||
assert new_cluster["DBClusterIdentifier"] == "db-restore-1"
|
||||
assert new_cluster["DBClusterParameterGroup"] == "default.aurora8.0"
|
||||
assert new_cluster["DBClusterInstanceClass"] == "db.r6g.xlarge"
|
||||
assert new_cluster["Port"] == 10000
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -739,12 +748,12 @@ def test_add_tags_to_cluster():
|
||||
)
|
||||
|
||||
tags = conn.list_tags_for_resource(ResourceName=cluster_arn)["TagList"]
|
||||
tags.should.equal([{"Key": "k1", "Value": "v1"}, {"Key": "k2", "Value": "v2"}])
|
||||
assert tags == [{"Key": "k1", "Value": "v1"}, {"Key": "k2", "Value": "v2"}]
|
||||
|
||||
conn.remove_tags_from_resource(ResourceName=cluster_arn, TagKeys=["k1"])
|
||||
|
||||
tags = conn.list_tags_for_resource(ResourceName=cluster_arn)["TagList"]
|
||||
tags.should.equal([{"Key": "k2", "Value": "v2"}])
|
||||
assert tags == [{"Key": "k2", "Value": "v2"}]
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -771,12 +780,12 @@ def test_add_tags_to_cluster_snapshot():
|
||||
)
|
||||
|
||||
tags = conn.list_tags_for_resource(ResourceName=snapshot_arn)["TagList"]
|
||||
tags.should.equal([{"Key": "k1", "Value": "v1"}, {"Key": "k2", "Value": "v2"}])
|
||||
assert tags == [{"Key": "k1", "Value": "v1"}, {"Key": "k2", "Value": "v2"}]
|
||||
|
||||
conn.remove_tags_from_resource(ResourceName=snapshot_arn, TagKeys=["k1"])
|
||||
|
||||
tags = conn.list_tags_for_resource(ResourceName=snapshot_arn)["TagList"]
|
||||
tags.should.equal([{"Key": "k2", "Value": "v2"}])
|
||||
assert tags == [{"Key": "k2", "Value": "v2"}]
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -795,7 +804,7 @@ def test_create_serverless_db_cluster():
|
||||
)
|
||||
cluster = resp["DBCluster"]
|
||||
# This is only true for specific engine versions
|
||||
cluster.should.have.key("HttpEndpointEnabled").equal(True)
|
||||
assert cluster["HttpEndpointEnabled"] is True
|
||||
|
||||
# Verify that a default serverless_configuration is added
|
||||
assert "ScalingConfigurationInfo" in cluster
|
||||
@ -819,7 +828,7 @@ def test_create_db_cluster_with_enable_http_endpoint_invalid():
|
||||
)
|
||||
cluster = resp["DBCluster"]
|
||||
# This attribute is ignored if an invalid engine version is supplied
|
||||
cluster.should.have.key("HttpEndpointEnabled").equal(False)
|
||||
assert cluster["HttpEndpointEnabled"] is False
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -859,8 +868,10 @@ def test_describe_db_clusters_filter_by_engine():
|
||||
@mock_rds
|
||||
def test_replicate_cluster():
|
||||
# WHEN create_db_cluster is called
|
||||
# AND create_db_cluster is called again with ReplicationSourceIdentifier set to the first cluster
|
||||
# THEN promote_read_replica_db_cluster can be called on the second cluster, elevating it to a read/write cluster
|
||||
# AND create_db_cluster is called again with ReplicationSourceIdentifier
|
||||
# set to the first cluster
|
||||
# THEN promote_read_replica_db_cluster can be called on the second
|
||||
# cluster, elevating it to a read/write cluster
|
||||
us_east = boto3.client("rds", "us-east-1")
|
||||
us_west = boto3.client("rds", "us-west-1")
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_rds
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ def test_add_instance_as_cluster_member():
|
||||
# the instance is included as a ClusterMember in the describe_db_clusters call
|
||||
client = boto3.client("rds", "us-east-1")
|
||||
|
||||
client.create_db_cluster(
|
||||
_ = client.create_db_cluster(
|
||||
DBClusterIdentifier="dbci",
|
||||
Engine="mysql",
|
||||
MasterUsername="masterusername",
|
||||
@ -43,7 +43,7 @@ def test_remove_instance_from_cluster():
|
||||
# the instance is included as a ClusterMember in the describe_db_clusters call
|
||||
client = boto3.client("rds", "us-east-1")
|
||||
|
||||
client.create_db_cluster(
|
||||
_ = client.create_db_cluster(
|
||||
DBClusterIdentifier="dbci",
|
||||
Engine="mysql",
|
||||
MasterUsername="masterusername",
|
||||
@ -72,7 +72,7 @@ def test_remove_instance_from_cluster():
|
||||
def test_add_instance_to_serverless_cluster():
|
||||
client = boto3.client("rds", "us-east-1")
|
||||
|
||||
client.create_db_cluster(
|
||||
_ = client.create_db_cluster(
|
||||
DBClusterIdentifier="dbci",
|
||||
Engine="aurora",
|
||||
EngineMode="serverless",
|
||||
|
@ -1,8 +1,7 @@
|
||||
import boto3
|
||||
import pytest
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from moto import mock_rds
|
||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||
|
||||
@ -44,16 +43,16 @@ def test_create_event_subscription():
|
||||
SourceIds=[db_identifier],
|
||||
).get("EventSubscription")
|
||||
|
||||
es["CustSubscriptionId"].should.equal(f"{db_identifier}-events")
|
||||
es["SnsTopicArn"].should.equal(
|
||||
assert es["CustSubscriptionId"] == f"{db_identifier}-events"
|
||||
assert es["SnsTopicArn"] == (
|
||||
f"arn:aws:sns::{ACCOUNT_ID}:{db_identifier}-events-topic"
|
||||
)
|
||||
es["SourceType"].should.equal("db-instance")
|
||||
es["EventCategoriesList"].should.equal(
|
||||
assert es["SourceType"] == "db-instance"
|
||||
assert es["EventCategoriesList"] == (
|
||||
["Backup", "Creation", "Deletion", "Failure", "Recovery", "Restoration"]
|
||||
)
|
||||
es["SourceIdsList"].should.equal([db_identifier])
|
||||
es["Enabled"].should.equal(False)
|
||||
assert es["SourceIdsList"] == [db_identifier]
|
||||
assert es["Enabled"] is False
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -75,8 +74,8 @@ def test_create_event_fail_already_exists():
|
||||
|
||||
err = ex.value.response["Error"]
|
||||
|
||||
err["Code"].should.equal("SubscriptionAlreadyExistFault")
|
||||
err["Message"].should.equal("Subscription db-primary-1-events already exists.")
|
||||
assert err["Code"] == "SubscriptionAlreadyExistFault"
|
||||
assert err["Message"] == "Subscription db-primary-1-events already exists."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -86,8 +85,8 @@ def test_delete_event_subscription_fails_unknown_subscription():
|
||||
client.delete_event_subscription(SubscriptionName="my-db-events")
|
||||
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("SubscriptionNotFoundFault")
|
||||
err["Message"].should.equal("Subscription my-db-events not found.")
|
||||
assert err["Code"] == "SubscriptionNotFoundFault"
|
||||
assert err["Message"] == "Subscription my-db-events not found."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -104,8 +103,8 @@ def test_delete_event_subscription():
|
||||
SubscriptionName=f"{db_identifier}-events"
|
||||
).get("EventSubscription")
|
||||
|
||||
es["CustSubscriptionId"].should.equal(f"{db_identifier}-events")
|
||||
es["SnsTopicArn"].should.equal(
|
||||
assert es["CustSubscriptionId"] == f"{db_identifier}-events"
|
||||
assert es["SnsTopicArn"] == (
|
||||
f"arn:aws:sns::{ACCOUNT_ID}:{db_identifier}-events-topic"
|
||||
)
|
||||
|
||||
@ -122,8 +121,8 @@ def test_describe_event_subscriptions():
|
||||
|
||||
subscriptions = client.describe_event_subscriptions().get("EventSubscriptionsList")
|
||||
|
||||
subscriptions.should.have.length_of(1)
|
||||
subscriptions[0]["CustSubscriptionId"].should.equal(f"{db_identifier}-events")
|
||||
assert len(subscriptions) == 1
|
||||
assert subscriptions[0]["CustSubscriptionId"] == f"{db_identifier}-events"
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -134,5 +133,5 @@ def test_describe_event_subscriptions_fails_unknown_subscription():
|
||||
|
||||
err = ex.value.response["Error"]
|
||||
|
||||
err["Code"].should.equal("SubscriptionNotFoundFault")
|
||||
err["Message"].should.equal("Subscription my-db-events not found.")
|
||||
assert err["Code"] == "SubscriptionNotFoundFault"
|
||||
assert err["Message"] == "Subscription my-db-events not found."
|
||||
|
@ -1,8 +1,7 @@
|
||||
import boto3
|
||||
import pytest
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from moto import mock_rds
|
||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||
|
||||
@ -63,8 +62,8 @@ def test_start_export_task_fails_unknown_snapshot():
|
||||
)
|
||||
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("DBSnapshotNotFound")
|
||||
err["Message"].should.equal("DBSnapshot snapshot-1 not found.")
|
||||
assert err["Code"] == "DBSnapshotNotFound"
|
||||
assert err["Message"] == "DBSnapshot snapshot-1 not found."
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -82,16 +81,16 @@ def test_start_export_task_db():
|
||||
ExportOnly=["schema.table"],
|
||||
)
|
||||
|
||||
export["ExportTaskIdentifier"].should.equal("export-snapshot-1")
|
||||
export["SourceArn"].should.equal(source_arn)
|
||||
export["S3Bucket"].should.equal("export-bucket")
|
||||
export["S3Prefix"].should.equal("snaps/")
|
||||
export["IamRoleArn"].should.equal("arn:aws:iam:::role/export-role")
|
||||
export["KmsKeyId"].should.equal(
|
||||
assert export["ExportTaskIdentifier"] == "export-snapshot-1"
|
||||
assert export["SourceArn"] == source_arn
|
||||
assert export["S3Bucket"] == "export-bucket"
|
||||
assert export["S3Prefix"] == "snaps/"
|
||||
assert export["IamRoleArn"] == "arn:aws:iam:::role/export-role"
|
||||
assert export["KmsKeyId"] == (
|
||||
"arn:aws:kms:::key/0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE"
|
||||
)
|
||||
export["ExportOnly"].should.equal(["schema.table"])
|
||||
export["SourceType"].should.equal("SNAPSHOT")
|
||||
assert export["ExportOnly"] == ["schema.table"]
|
||||
assert export["SourceType"] == "SNAPSHOT"
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -109,16 +108,16 @@ def test_start_export_task_db_cluster():
|
||||
ExportOnly=["schema.table"],
|
||||
)
|
||||
|
||||
export["ExportTaskIdentifier"].should.equal("export-snapshot-1")
|
||||
export["SourceArn"].should.equal(source_arn)
|
||||
export["S3Bucket"].should.equal("export-bucket")
|
||||
export["S3Prefix"].should.equal("snaps/")
|
||||
export["IamRoleArn"].should.equal("arn:aws:iam:::role/export-role")
|
||||
export["KmsKeyId"].should.equal(
|
||||
assert export["ExportTaskIdentifier"] == "export-snapshot-1"
|
||||
assert export["SourceArn"] == source_arn
|
||||
assert export["S3Bucket"] == "export-bucket"
|
||||
assert export["S3Prefix"] == "snaps/"
|
||||
assert export["IamRoleArn"] == "arn:aws:iam:::role/export-role"
|
||||
assert export["KmsKeyId"] == (
|
||||
"arn:aws:kms:::key/0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE"
|
||||
)
|
||||
export["ExportOnly"].should.equal(["schema.table"])
|
||||
export["SourceType"].should.equal("CLUSTER")
|
||||
assert export["ExportOnly"] == ["schema.table"]
|
||||
assert export["SourceType"] == "CLUSTER"
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -143,9 +142,10 @@ def test_start_export_task_fail_already_exists():
|
||||
)
|
||||
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("ExportTaskAlreadyExistsFault")
|
||||
err["Message"].should.equal(
|
||||
"Cannot start export task because a task with the identifier export-snapshot-1 already exists."
|
||||
assert err["Code"] == "ExportTaskAlreadyExistsFault"
|
||||
assert err["Message"] == (
|
||||
"Cannot start export task because a task with the identifier "
|
||||
"export-snapshot-1 already exists."
|
||||
)
|
||||
|
||||
|
||||
@ -156,9 +156,10 @@ def test_cancel_export_task_fails_unknown_task():
|
||||
client.cancel_export_task(ExportTaskIdentifier="export-snapshot-1")
|
||||
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("ExportTaskNotFoundFault")
|
||||
err["Message"].should.equal(
|
||||
"Cannot cancel export task because a task with the identifier export-snapshot-1 is not exist."
|
||||
assert err["Code"] == "ExportTaskNotFoundFault"
|
||||
assert err["Message"] == (
|
||||
"Cannot cancel export task because a task with the identifier "
|
||||
"export-snapshot-1 is not exist."
|
||||
)
|
||||
|
||||
|
||||
@ -177,8 +178,8 @@ def test_cancel_export_task():
|
||||
|
||||
export = client.cancel_export_task(ExportTaskIdentifier="export-snapshot-1")
|
||||
|
||||
export["ExportTaskIdentifier"].should.equal("export-snapshot-1")
|
||||
export["Status"].should.equal("canceled")
|
||||
assert export["ExportTaskIdentifier"] == "export-snapshot-1"
|
||||
assert export["Status"] == "canceled"
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -195,8 +196,8 @@ def test_describe_export_tasks():
|
||||
|
||||
exports = client.describe_export_tasks().get("ExportTasks")
|
||||
|
||||
exports.should.have.length_of(1)
|
||||
exports[0]["ExportTaskIdentifier"].should.equal("export-snapshot-1")
|
||||
assert len(exports) == 1
|
||||
assert exports[0]["ExportTaskIdentifier"] == "export-snapshot-1"
|
||||
|
||||
|
||||
@mock_rds
|
||||
@ -206,7 +207,8 @@ def test_describe_export_tasks_fails_unknown_task():
|
||||
client.describe_export_tasks(ExportTaskIdentifier="export-snapshot-1")
|
||||
|
||||
err = ex.value.response["Error"]
|
||||
err["Code"].should.equal("ExportTaskNotFoundFault")
|
||||
err["Message"].should.equal(
|
||||
"Cannot cancel export task because a task with the identifier export-snapshot-1 is not exist."
|
||||
assert err["Code"] == "ExportTaskNotFoundFault"
|
||||
assert err["Message"] == (
|
||||
"Cannot cancel export task because a task with the identifier "
|
||||
"export-snapshot-1 is not exist."
|
||||
)
|
||||
|
@ -1,6 +1,5 @@
|
||||
from urllib.parse import urlencode
|
||||
import moto.server as server
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
|
||||
def test_list_databases():
|
||||
@ -9,7 +8,7 @@ def test_list_databases():
|
||||
|
||||
res = test_client.get("/?Action=DescribeDBInstances")
|
||||
|
||||
res.data.decode("utf-8").should.contain("<DescribeDBInstancesResult>")
|
||||
assert "<DescribeDBInstancesResult>" in res.data.decode("utf-8")
|
||||
|
||||
|
||||
def test_create_db_instance():
|
||||
@ -28,10 +27,10 @@ def test_create_db_instance():
|
||||
resp = test_client.post(f"/?{qs}")
|
||||
|
||||
response = resp.data.decode("utf-8")
|
||||
response.shouldnt.contain("<DBClusterIdentifier>")
|
||||
response.should.contain("<DBInstanceIdentifier>hi</DBInstanceIdentifier")
|
||||
assert "<DBClusterIdentifier>" not in response
|
||||
assert "<DBInstanceIdentifier>hi</DBInstanceIdentifier" in response
|
||||
# We do not pass these values - they should default to false
|
||||
response.should.contain("<MultiAZ>false</MultiAZ>")
|
||||
response.should.contain(
|
||||
assert "<MultiAZ>false</MultiAZ>" in response
|
||||
assert (
|
||||
"<IAMDatabaseAuthenticationEnabled>false</IAMDatabaseAuthenticationEnabled>"
|
||||
)
|
||||
) in response
|
||||
|
@ -11,7 +11,7 @@ from moto.rds.utils import (
|
||||
)
|
||||
|
||||
|
||||
class TestFilterValidation(object):
|
||||
class TestFilterValidation:
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
cls.filter_defs = {
|
||||
@ -37,13 +37,13 @@ class TestFilterValidation(object):
|
||||
validate_filters(filters, self.filter_defs)
|
||||
|
||||
|
||||
class Resource(object):
|
||||
class Resource:
|
||||
def __init__(self, identifier, **kwargs):
|
||||
self.identifier = identifier
|
||||
self.__dict__.update(kwargs)
|
||||
|
||||
|
||||
class TestResourceFiltering(object):
|
||||
class TestResourceFiltering:
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
cls.filter_defs = {
|
||||
@ -64,31 +64,31 @@ class TestResourceFiltering(object):
|
||||
def test_filtering_on_nested_attribute(self):
|
||||
filters = {"nested-resource": ["nested-id-1"]}
|
||||
filtered_resources = apply_filter(self.resources, filters, self.filter_defs)
|
||||
filtered_resources.should.have.length_of(1)
|
||||
filtered_resources.should.have.key("identifier-3")
|
||||
assert len(filtered_resources) == 1
|
||||
assert "identifier-3" in filtered_resources
|
||||
|
||||
def test_filtering_on_common_attribute(self):
|
||||
filters = {"common-attr": ["common"]}
|
||||
filtered_resources = apply_filter(self.resources, filters, self.filter_defs)
|
||||
filtered_resources.should.have.length_of(2)
|
||||
filtered_resources.should.have.key("identifier-1")
|
||||
filtered_resources.should.have.key("identifier-4")
|
||||
assert len(filtered_resources) == 2
|
||||
assert "identifier-1" in filtered_resources
|
||||
assert "identifier-4" in filtered_resources
|
||||
|
||||
def test_filtering_on_multiple_attributes(self):
|
||||
filters = {"multiple-attrs": ["common"]}
|
||||
filtered_resources = apply_filter(self.resources, filters, self.filter_defs)
|
||||
filtered_resources.should.have.length_of(3)
|
||||
filtered_resources.should.have.key("identifier-1")
|
||||
filtered_resources.should.have.key("identifier-4")
|
||||
filtered_resources.should.have.key("identifier-5")
|
||||
assert len(filtered_resources) == 3
|
||||
assert "identifier-1" in filtered_resources
|
||||
assert "identifier-4" in filtered_resources
|
||||
assert "identifier-5" in filtered_resources
|
||||
|
||||
def test_filters_with_multiple_values(self):
|
||||
filters = {"identifier": ["identifier-0", "identifier-3", "identifier-5"]}
|
||||
filtered_resources = apply_filter(self.resources, filters, self.filter_defs)
|
||||
filtered_resources.should.have.length_of(3)
|
||||
filtered_resources.should.have.key("identifier-0")
|
||||
filtered_resources.should.have.key("identifier-3")
|
||||
filtered_resources.should.have.key("identifier-5")
|
||||
assert len(filtered_resources) == 3
|
||||
assert "identifier-0" in filtered_resources
|
||||
assert "identifier-3" in filtered_resources
|
||||
assert "identifier-5" in filtered_resources
|
||||
|
||||
def test_multiple_filters(self):
|
||||
filters = {
|
||||
@ -97,11 +97,11 @@ class TestResourceFiltering(object):
|
||||
"multiple-attrs": ["common"],
|
||||
}
|
||||
filtered_resources = apply_filter(self.resources, filters, self.filter_defs)
|
||||
filtered_resources.should.have.length_of(1)
|
||||
filtered_resources.should.have.key("identifier-1")
|
||||
assert len(filtered_resources) == 1
|
||||
assert "identifier-1" in filtered_resources
|
||||
|
||||
|
||||
class TestMergingFilters(object):
|
||||
class TestMergingFilters:
|
||||
def test_when_filters_to_update_is_none(self):
|
||||
filters_to_update = {"filter-name": ["value1"]}
|
||||
merged = merge_filters(filters_to_update, None)
|
||||
@ -135,12 +135,15 @@ class TestMergingFilters(object):
|
||||
}
|
||||
merged = merge_filters(filters_to_update, filters_to_merge)
|
||||
assert len(merged.keys()) == 4
|
||||
for key in merged.keys():
|
||||
assert merged[key] == ["value1", "value2"]
|
||||
for value in merged.values():
|
||||
assert value == ["value1", "value2"]
|
||||
|
||||
|
||||
def test_encode_orderable_db_instance():
|
||||
# Data from AWS comes in a specific format. Verify we can encode/decode it to something more compact
|
||||
"""Verify the data can be encoded/decoded to something more compact.
|
||||
|
||||
Data from AWS comes in a specific format.
|
||||
"""
|
||||
original = {
|
||||
"Engine": "neptune",
|
||||
"EngineVersion": "1.0.3.0",
|
||||
@ -173,11 +176,15 @@ def test_encode_orderable_db_instance():
|
||||
"Support edNetworkTypes": ["IPV4"],
|
||||
}
|
||||
short = encode_orderable_db_instance(original)
|
||||
decode_orderable_db_instance(short).should.equal(original)
|
||||
assert decode_orderable_db_instance(short) == original
|
||||
|
||||
|
||||
def test_encode_orderable_db_instance__short_format():
|
||||
# Verify this works in a random format. We don't know for sure what AWS returns, so it should always work regardless of the input
|
||||
"""Verify this works in a random format.
|
||||
|
||||
We don't know for sure what AWS returns, so it should always work
|
||||
regardless of the input.
|
||||
"""
|
||||
short = {
|
||||
"Engine": "neptune",
|
||||
"EngineVersion": "1.0.3.0",
|
||||
@ -190,12 +197,10 @@ def test_encode_orderable_db_instance__short_format():
|
||||
"SupportsClusters": True,
|
||||
"SupportedNetworkTypes": ["IPV4"],
|
||||
}
|
||||
decode_orderable_db_instance(encode_orderable_db_instance(short)).should.equal(
|
||||
short
|
||||
)
|
||||
assert decode_orderable_db_instance(encode_orderable_db_instance(short)) == short
|
||||
|
||||
|
||||
def test_verify_encoding_is_unique():
|
||||
len(set(ORDERABLE_DB_INSTANCE_ENCODING.values())).should.equal(
|
||||
len(ORDERABLE_DB_INSTANCE_ENCODING.keys())
|
||||
assert len(set(ORDERABLE_DB_INSTANCE_ENCODING.values())) == len(
|
||||
ORDERABLE_DB_INSTANCE_ENCODING.keys()
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user