Skip to content

Commit

Permalink
Try passing in the region
Browse files Browse the repository at this point in the history
  • Loading branch information
WillGibson committed Nov 12, 2024
1 parent ad556df commit bb3634f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions postgres/tests/test_manage_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_create_or_update_db_user(self):

conn.commit.assert_called_once()


def test_create_or_update_db_user_when_user_exists(self):
self.cursor.fetchone.return_value = ["test_user"]
conn = MagicMock()
Expand All @@ -74,14 +74,14 @@ def test_create_or_update_db_user_when_user_exists(self):
)

conn.commit.assert_called_once()


@mock_aws
def test_create_or_update_user_secret(self):
ssm = boto3.client("ssm")
user_secret_name = "/test/secret"
user_secret_string = {"username": "test_user", "password": "test_password"}

response = create_or_update_user_secret(
ssm, user_secret_name, user_secret_string, self.event
)
Expand All @@ -108,19 +108,19 @@ def test_create_or_update_user_secret_overwrites(self):

assert parameter["Version"] == 2
assert parameter["Value"] == json.dumps(user_secret_string)


@patch("postgres.manage_users.create_or_update_db_user")
@patch("postgres.manage_users.psycopg2.connect")
@mock_aws
def test_handler(self, mock_connect, mock_create_or_update_db_user):
secretsmanager = boto3.client("secretsmanager")
secretsmanager = boto3.client("secretsmanager", region_name="eu-west-2")
secret_id = secretsmanager.create_secret(
Name=self.secret_name, SecretString=self.secret_string
)["ARN"]

self.event["MasterUserSecretArn"] = secret_id

mock_connect.return_value = self.conn
self.conn.cursor = self.cursor

Expand All @@ -129,7 +129,7 @@ def test_handler(self, mock_connect, mock_create_or_update_db_user):
user_password = json.loads(boto3.client("ssm").get_parameter(Name=self.secret_name, WithDecryption=True)["Parameter"]["Value"])[
"password"
]

mock_create_or_update_db_user.assert_called_once_with(
self.conn, self.cursor(), "test-user", user_password, ["SELECT"]
)

0 comments on commit bb3634f

Please sign in to comment.