From a476164e0f6713a96d1601217bdf437cc59dad16 Mon Sep 17 00:00:00 2001 From: Jerry Xu Date: Thu, 27 Feb 2025 14:11:23 -0500 Subject: [PATCH 1/5] feat: fix autominorversionupgrade and list_tables --- moto/rds/models.py | 2 ++ moto/timestreamwrite/responses.py | 7 +++- tests/test_rds/test_rds.py | 4 +++ tests/test_rds/test_rds_clusters.py | 3 ++ .../test_timestreamwrite_table.py | 32 +++++++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/moto/rds/models.py b/moto/rds/models.py index 7e9bfb7f1bb3..1772cc7a2935 100644 --- a/moto/rds/models.py +++ b/moto/rds/models.py @@ -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, @@ -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(): diff --git a/moto/timestreamwrite/responses.py b/moto/timestreamwrite/responses.py index 2c4ff9ed8017..fb92d14903cc 100644 --- a/moto/timestreamwrite/responses.py +++ b/moto/timestreamwrite/responses.py @@ -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: diff --git a/tests/test_rds/test_rds.py b/tests/test_rds/test_rds.py index 5763cc82208e..7bfb47ee5a8c 100644 --- a/tests/test_rds/test_rds.py +++ b/tests/test_rds/test_rds.py @@ -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 @@ -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 diff --git a/tests/test_rds/test_rds_clusters.py b/tests/test_rds/test_rds_clusters.py index 9f1885db89b3..ba94a8b30b71 100644 --- a/tests/test_rds/test_rds_clusters.py +++ b/tests/test_rds/test_rds_clusters.py @@ -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" diff --git a/tests/test_timestreamwrite/test_timestreamwrite_table.py b/tests/test_timestreamwrite/test_timestreamwrite_table.py index 38ddd40b852b..af8bfadd93a3 100644 --- a/tests/test_timestreamwrite/test_timestreamwrite_table.py +++ b/tests/test_timestreamwrite/test_timestreamwrite_table.py @@ -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(): From 2a57276ffcf1949d1abba7c9b0ca83b5ce70e116 Mon Sep 17 00:00:00 2001 From: Jerry Xu Date: Thu, 27 Feb 2025 15:04:01 -0500 Subject: [PATCH 2/5] fix lint error --- tests/test_rds/test_rds.py | 2 -- tests/test_timestreamwrite/test_timestreamwrite_table.py | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_rds/test_rds.py b/tests/test_rds/test_rds.py index 7bfb47ee5a8c..d993b055eabe 100644 --- a/tests/test_rds/test_rds.py +++ b/tests/test_rds/test_rds.py @@ -62,7 +62,6 @@ def test_create_database(client): VpcSecurityGroupIds=["sg-123456"], EnableCloudwatchLogsExports=["audit", "error"], AutoMinorVersionUpgrade=False, - PubliclyAccessible=True ) db_instance = database["DBInstance"] assert db_instance["AllocatedStorage"] == 10 @@ -86,7 +85,6 @@ def test_create_database(client): 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 diff --git a/tests/test_timestreamwrite/test_timestreamwrite_table.py b/tests/test_timestreamwrite/test_timestreamwrite_table.py index af8bfadd93a3..e5a077c23cf4 100644 --- a/tests/test_timestreamwrite/test_timestreamwrite_table.py +++ b/tests/test_timestreamwrite/test_timestreamwrite_table.py @@ -197,6 +197,7 @@ 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") From 311cdcc5ba028c6e63b68ccad52ef634bc20f138 Mon Sep 17 00:00:00 2001 From: Jerry Xu Date: Thu, 27 Feb 2025 15:35:55 -0500 Subject: [PATCH 3/5] feat: fix python typing issue --- moto/timestreamwrite/responses.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/moto/timestreamwrite/responses.py b/moto/timestreamwrite/responses.py index fb92d14903cc..492e1fc16cbd 100644 --- a/moto/timestreamwrite/responses.py +++ b/moto/timestreamwrite/responses.py @@ -1,9 +1,10 @@ import json +from typing import Iterable from moto.core.responses import BaseResponse from moto.timestreamquery.models import TimestreamQueryBackend, timestreamquery_backends -from .models import TimestreamWriteBackend, timestreamwrite_backends +from .models import TimestreamTable, TimestreamWriteBackend, timestreamwrite_backends class TimestreamWriteResponse(BaseResponse): @@ -86,9 +87,9 @@ def describe_table(self) -> str: def list_tables(self) -> str: database_name = self._get_param("DatabaseName") if database_name is None: - tables = [] + tables: Iterable[TimestreamTable] = [] for db in self.timestreamwrite_backend.list_databases(): - tables.extend(db.list_tables()) + tables = list(tables) + list(db.list_tables()) else: tables = self.timestreamwrite_backend.list_tables(database_name) return json.dumps(dict(Tables=[t.description() for t in tables])) From d8b6676b636e1e3157be9b48a40030b32876a726 Mon Sep 17 00:00:00 2001 From: Jerry Xu Date: Thu, 27 Feb 2025 16:23:34 -0500 Subject: [PATCH 4/5] feat: trigger build From 879aab7a7a5da6a249ca6bd109d2684d603f6507 Mon Sep 17 00:00:00 2001 From: Jerry Xu Date: Thu, 27 Feb 2025 18:21:11 -0500 Subject: [PATCH 5/5] feat: trigger build