Skip to content

Commit

Permalink
feat: fix autominorversionupgrade and list_tables
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryhxu committed Feb 27, 2025
1 parent 81f5fd1 commit a476164
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def __init__(
db_cluster_identifier: str,
engine: str,
allocated_storage: Optional[int] = None,
auto_minor_version_upgrade: bool = True,
engine_version: Optional[str] = None,
master_username: Optional[str] = None,
master_user_password: Optional[str] = None,
Expand All @@ -413,6 +414,7 @@ def __init__(
self.database_name = database_name
self.db_cluster_identifier = db_cluster_identifier
self.db_cluster_instance_class = kwargs.get("db_cluster_instance_class")
self.auto_minor_version_upgrade = auto_minor_version_upgrade
self.deletion_protection = deletion_protection
self.engine = engine
if self.engine not in ClusterEngine.list_cluster_engines():
Expand Down
7 changes: 6 additions & 1 deletion moto/timestreamwrite/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ def describe_table(self) -> str:

def list_tables(self) -> str:
database_name = self._get_param("DatabaseName")
tables = self.timestreamwrite_backend.list_tables(database_name)
if database_name is None:
tables = []
for db in self.timestreamwrite_backend.list_databases():
tables.extend(db.list_tables())
else:
tables = self.timestreamwrite_backend.list_tables(database_name)
return json.dumps(dict(Tables=[t.description() for t in tables]))

def update_table(self) -> str:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_rds/test_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def test_create_database(client):
DBSecurityGroups=["my_sg"],
VpcSecurityGroupIds=["sg-123456"],
EnableCloudwatchLogsExports=["audit", "error"],
AutoMinorVersionUpgrade=False,
PubliclyAccessible=True
)
db_instance = database["DBInstance"]
assert db_instance["AllocatedStorage"] == 10
Expand All @@ -83,6 +85,8 @@ def test_create_database(client):
assert db_instance["EnabledCloudwatchLogsExports"] == ["audit", "error"]
assert db_instance["Endpoint"]["Port"] == 1234
assert db_instance["DbInstancePort"] == 1234
assert db_instance["AutoMinorVersionUpgrade"] is False
assert db_instance["PubliclyAccessible"] is True


@mock_aws
Expand Down
3 changes: 3 additions & 0 deletions tests/test_rds/test_rds_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,13 @@ def test_create_db_cluster_additional_parameters(client):
},
VpcSecurityGroupIds=["sg1", "sg2"],
EnableIAMDatabaseAuthentication=True,
AutoMinorVersionUpgrade=False,
)

cluster = resp["DBCluster"]

assert cluster["AutoMinorVersionUpgrade"] is False
assert cluster["DBClusterIdentifier"] == "cluster-id"
assert cluster["AvailabilityZones"] == ["eu-north-1b"]
assert cluster["DatabaseName"] == "users"
assert cluster["Engine"] == "aurora-postgresql"
Expand Down
32 changes: 32 additions & 0 deletions tests/test_timestreamwrite/test_timestreamwrite_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,38 @@ def test_create_multiple_tables():
}
assert {t["TableStatus"] for t in tables} == {"ACTIVE"}

@mock_aws
def test_list_tables_without_database():
ts = boto3.client("timestream-write", region_name="us-east-1")
ts.create_database(DatabaseName="mydatabase")

for idx in range(0, 5):
ts.create_table(
DatabaseName="mydatabase",
TableName=f"mytable_{idx}",
RetentionProperties={
"MemoryStoreRetentionPeriodInHours": 7,
"MagneticStoreRetentionPeriodInDays": 42,
},
)

database = ts.describe_database(DatabaseName="mydatabase")["Database"]

assert database["TableCount"] == 5

# database_name is optional in api call
tables = ts.list_tables()["Tables"]
assert len(tables) == 5
assert {t["DatabaseName"] for t in tables} == {"mydatabase"}
assert {t["TableName"] for t in tables} == {
"mytable_0",
"mytable_1",
"mytable_2",
"mytable_3",
"mytable_4",
}
assert {t["TableStatus"] for t in tables} == {"ACTIVE"}


@mock_aws
def test_delete_table():
Expand Down

0 comments on commit a476164

Please sign in to comment.