Run black on moto & test directories.

This commit is contained in:
Asher Foa 2019-10-31 08:44:26 -07:00
commit 96e5b1993d
507 changed files with 52541 additions and 47814 deletions

View file

@ -14,17 +14,19 @@ from tests.helpers import disable_on_py3
def test_create_database():
conn = boto.rds.connect_to_region("us-west-2")
database = conn.create_dbinstance("db-master-1", 10, 'db.m1.small', 'root', 'hunter2',
security_groups=["my_sg"])
database = conn.create_dbinstance(
"db-master-1", 10, "db.m1.small", "root", "hunter2", security_groups=["my_sg"]
)
database.status.should.equal('available')
database.status.should.equal("available")
database.id.should.equal("db-master-1")
database.allocated_storage.should.equal(10)
database.instance_class.should.equal("db.m1.small")
database.master_username.should.equal("root")
database.endpoint.should.equal(
('db-master-1.aaaaaaaaaa.us-west-2.rds.amazonaws.com', 3306))
database.security_groups[0].name.should.equal('my_sg')
("db-master-1.aaaaaaaaaa.us-west-2.rds.amazonaws.com", 3306)
)
database.security_groups[0].name.should.equal("my_sg")
@mock_rds_deprecated
@ -33,8 +35,8 @@ def test_get_databases():
list(conn.get_all_dbinstances()).should.have.length_of(0)
conn.create_dbinstance("db-master-1", 10, 'db.m1.small', 'root', 'hunter2')
conn.create_dbinstance("db-master-2", 10, 'db.m1.small', 'root', 'hunter2')
conn.create_dbinstance("db-master-1", 10, "db.m1.small", "root", "hunter2")
conn.create_dbinstance("db-master-2", 10, "db.m1.small", "root", "hunter2")
list(conn.get_all_dbinstances()).should.have.length_of(2)
@ -46,18 +48,20 @@ def test_get_databases():
@mock_rds
def test_get_databases_paginated():
conn = boto3.client('rds', region_name="us-west-2")
conn = boto3.client("rds", region_name="us-west-2")
for i in range(51):
conn.create_db_instance(AllocatedStorage=5,
Port=5432,
DBInstanceIdentifier='rds%d' % i,
DBInstanceClass='db.t1.micro',
Engine='postgres')
conn.create_db_instance(
AllocatedStorage=5,
Port=5432,
DBInstanceIdentifier="rds%d" % i,
DBInstanceClass="db.t1.micro",
Engine="postgres",
)
resp = conn.describe_db_instances()
resp["DBInstances"].should.have.length_of(50)
resp["Marker"].should.equal(resp["DBInstances"][-1]['DBInstanceIdentifier'])
resp["Marker"].should.equal(resp["DBInstances"][-1]["DBInstanceIdentifier"])
resp2 = conn.describe_db_instances(Marker=resp["Marker"])
resp2["DBInstances"].should.have.length_of(1)
@ -66,8 +70,7 @@ def test_get_databases_paginated():
@mock_rds_deprecated
def test_describe_non_existant_database():
conn = boto.rds.connect_to_region("us-west-2")
conn.get_all_dbinstances.when.called_with(
"not-a-db").should.throw(BotoServerError)
conn.get_all_dbinstances.when.called_with("not-a-db").should.throw(BotoServerError)
@mock_rds_deprecated
@ -75,7 +78,7 @@ def test_delete_database():
conn = boto.rds.connect_to_region("us-west-2")
list(conn.get_all_dbinstances()).should.have.length_of(0)
conn.create_dbinstance("db-master-1", 10, 'db.m1.small', 'root', 'hunter2')
conn.create_dbinstance("db-master-1", 10, "db.m1.small", "root", "hunter2")
list(conn.get_all_dbinstances()).should.have.length_of(1)
conn.delete_dbinstance("db-master-1")
@ -85,16 +88,15 @@ def test_delete_database():
@mock_rds_deprecated
def test_delete_non_existant_database():
conn = boto.rds.connect_to_region("us-west-2")
conn.delete_dbinstance.when.called_with(
"not-a-db").should.throw(BotoServerError)
conn.delete_dbinstance.when.called_with("not-a-db").should.throw(BotoServerError)
@mock_rds_deprecated
def test_create_database_security_group():
conn = boto.rds.connect_to_region("us-west-2")
security_group = conn.create_dbsecurity_group('db_sg', 'DB Security Group')
security_group.name.should.equal('db_sg')
security_group = conn.create_dbsecurity_group("db_sg", "DB Security Group")
security_group.name.should.equal("db_sg")
security_group.description.should.equal("DB Security Group")
list(security_group.ip_ranges).should.equal([])
@ -105,8 +107,8 @@ def test_get_security_groups():
list(conn.get_all_dbsecurity_groups()).should.have.length_of(0)
conn.create_dbsecurity_group('db_sg1', 'DB Security Group')
conn.create_dbsecurity_group('db_sg2', 'DB Security Group')
conn.create_dbsecurity_group("db_sg1", "DB Security Group")
conn.create_dbsecurity_group("db_sg2", "DB Security Group")
list(conn.get_all_dbsecurity_groups()).should.have.length_of(2)
@ -119,14 +121,15 @@ def test_get_security_groups():
@mock_rds_deprecated
def test_get_non_existant_security_group():
conn = boto.rds.connect_to_region("us-west-2")
conn.get_all_dbsecurity_groups.when.called_with(
"not-a-sg").should.throw(BotoServerError)
conn.get_all_dbsecurity_groups.when.called_with("not-a-sg").should.throw(
BotoServerError
)
@mock_rds_deprecated
def test_delete_database_security_group():
conn = boto.rds.connect_to_region("us-west-2")
conn.create_dbsecurity_group('db_sg', 'DB Security Group')
conn.create_dbsecurity_group("db_sg", "DB Security Group")
list(conn.get_all_dbsecurity_groups()).should.have.length_of(1)
@ -137,21 +140,22 @@ def test_delete_database_security_group():
@mock_rds_deprecated
def test_delete_non_existant_security_group():
conn = boto.rds.connect_to_region("us-west-2")
conn.delete_dbsecurity_group.when.called_with(
"not-a-db").should.throw(BotoServerError)
conn.delete_dbsecurity_group.when.called_with("not-a-db").should.throw(
BotoServerError
)
@disable_on_py3()
@mock_rds_deprecated
def test_security_group_authorize():
conn = boto.rds.connect_to_region("us-west-2")
security_group = conn.create_dbsecurity_group('db_sg', 'DB Security Group')
security_group = conn.create_dbsecurity_group("db_sg", "DB Security Group")
list(security_group.ip_ranges).should.equal([])
security_group.authorize(cidr_ip='10.3.2.45/32')
security_group.authorize(cidr_ip="10.3.2.45/32")
security_group = conn.get_all_dbsecurity_groups()[0]
list(security_group.ip_ranges).should.have.length_of(1)
security_group.ip_ranges[0].cidr_ip.should.equal('10.3.2.45/32')
security_group.ip_ranges[0].cidr_ip.should.equal("10.3.2.45/32")
@mock_rds_deprecated
@ -159,8 +163,9 @@ def test_add_security_group_to_database():
conn = boto.rds.connect_to_region("us-west-2")
database = conn.create_dbinstance(
"db-master-1", 10, 'db.m1.small', 'root', 'hunter2')
security_group = conn.create_dbsecurity_group('db_sg', 'DB Security Group')
"db-master-1", 10, "db.m1.small", "root", "hunter2"
)
security_group = conn.create_dbsecurity_group("db_sg", "DB Security Group")
database.modify(security_groups=[security_group])
database = conn.get_all_dbinstances()[0]
@ -179,9 +184,8 @@ def test_add_database_subnet_group():
subnet_ids = [subnet1.id, subnet2.id]
conn = boto.rds.connect_to_region("us-west-2")
subnet_group = conn.create_db_subnet_group(
"db_subnet", "my db subnet", subnet_ids)
subnet_group.name.should.equal('db_subnet')
subnet_group = conn.create_db_subnet_group("db_subnet", "my db subnet", subnet_ids)
subnet_group.name.should.equal("db_subnet")
subnet_group.description.should.equal("my db subnet")
list(subnet_group.subnet_ids).should.equal(subnet_ids)
@ -200,8 +204,9 @@ def test_describe_database_subnet_group():
list(conn.get_all_db_subnet_groups()).should.have.length_of(2)
list(conn.get_all_db_subnet_groups("db_subnet1")).should.have.length_of(1)
conn.get_all_db_subnet_groups.when.called_with(
"not-a-subnet").should.throw(BotoServerError)
conn.get_all_db_subnet_groups.when.called_with("not-a-subnet").should.throw(
BotoServerError
)
@mock_ec2_deprecated
@ -218,8 +223,9 @@ def test_delete_database_subnet_group():
conn.delete_db_subnet_group("db_subnet1")
list(conn.get_all_db_subnet_groups()).should.have.length_of(0)
conn.delete_db_subnet_group.when.called_with(
"db_subnet1").should.throw(BotoServerError)
conn.delete_db_subnet_group.when.called_with("db_subnet1").should.throw(
BotoServerError
)
@mock_ec2_deprecated
@ -232,8 +238,14 @@ def test_create_database_in_subnet_group():
conn = boto.rds.connect_to_region("us-west-2")
conn.create_db_subnet_group("db_subnet1", "my db subnet", [subnet.id])
database = conn.create_dbinstance("db-master-1", 10, 'db.m1.small',
'root', 'hunter2', db_subnet_group_name="db_subnet1")
database = conn.create_dbinstance(
"db-master-1",
10,
"db.m1.small",
"root",
"hunter2",
db_subnet_group_name="db_subnet1",
)
database = conn.get_all_dbinstances("db-master-1")[0]
database.subnet_group.name.should.equal("db_subnet1")
@ -244,16 +256,18 @@ def test_create_database_replica():
conn = boto.rds.connect_to_region("us-west-2")
primary = conn.create_dbinstance(
"db-master-1", 10, 'db.m1.small', 'root', 'hunter2')
"db-master-1", 10, "db.m1.small", "root", "hunter2"
)
replica = conn.create_dbinstance_read_replica(
"replica", "db-master-1", "db.m1.small")
"replica", "db-master-1", "db.m1.small"
)
replica.id.should.equal("replica")
replica.instance_class.should.equal("db.m1.small")
status_info = replica.status_infos[0]
status_info.normal.should.equal(True)
status_info.status_type.should.equal('read replication')
status_info.status.should.equal('replicating')
status_info.status_type.should.equal("read replication")
status_info.status.should.equal("replicating")
primary = conn.get_all_dbinstances("db-master-1")[0]
primary.read_replica_dbinstance_identifiers[0].should.equal("replica")
@ -270,13 +284,12 @@ def test_create_cross_region_database_replica():
west_2_conn = boto.rds.connect_to_region("us-west-2")
primary = west_1_conn.create_dbinstance(
"db-master-1", 10, 'db.m1.small', 'root', 'hunter2')
"db-master-1", 10, "db.m1.small", "root", "hunter2"
)
primary_arn = "arn:aws:rds:us-west-1:1234567890:db:db-master-1"
replica = west_2_conn.create_dbinstance_read_replica(
"replica",
primary_arn,
"db.m1.small",
"replica", primary_arn, "db.m1.small"
)
primary = west_1_conn.get_all_dbinstances("db-master-1")[0]
@ -298,17 +311,19 @@ def test_connecting_to_us_east_1():
# https://github.com/boto/boto/blob/e271ff09364ea18d9d8b6f4d63d6b0ac6cbc9b75/boto/endpoints.json#L285
conn = boto.rds.connect_to_region("us-east-1")
database = conn.create_dbinstance("db-master-1", 10, 'db.m1.small', 'root', 'hunter2',
security_groups=["my_sg"])
database = conn.create_dbinstance(
"db-master-1", 10, "db.m1.small", "root", "hunter2", security_groups=["my_sg"]
)
database.status.should.equal('available')
database.status.should.equal("available")
database.id.should.equal("db-master-1")
database.allocated_storage.should.equal(10)
database.instance_class.should.equal("db.m1.small")
database.master_username.should.equal("root")
database.endpoint.should.equal(
('db-master-1.aaaaaaaaaa.us-east-1.rds.amazonaws.com', 3306))
database.security_groups[0].name.should.equal('my_sg')
("db-master-1.aaaaaaaaaa.us-east-1.rds.amazonaws.com", 3306)
)
database.security_groups[0].name.should.equal("my_sg")
@mock_rds_deprecated
@ -316,9 +331,10 @@ def test_create_database_with_iops():
conn = boto.rds.connect_to_region("us-west-2")
database = conn.create_dbinstance(
"db-master-1", 10, 'db.m1.small', 'root', 'hunter2', iops=6000)
"db-master-1", 10, "db.m1.small", "root", "hunter2", iops=6000
)
database.status.should.equal('available')
database.status.should.equal("available")
database.iops.should.equal(6000)
# boto>2.36.0 may change the following property name to `storage_type`
database.StorageType.should.equal('io1')
database.StorageType.should.equal("io1")

View file

@ -5,9 +5,9 @@ import sure # noqa
import moto.server as server
from moto import mock_rds
'''
"""
Test the different server responses
'''
"""
@mock_rds
@ -15,6 +15,6 @@ def test_list_databases():
backend = server.create_backend_app("rds")
test_client = backend.test_client()
res = test_client.get('/?Action=DescribeDBInstances')
res = test_client.get("/?Action=DescribeDBInstances")
res.data.decode("utf-8").should.contain("<DescribeDBInstancesResult>")