Skip to content

Commit

Permalink
boto3.setup_default_session(region_name='eu-west-2')
Browse files Browse the repository at this point in the history
  • Loading branch information
WillGibson committed Nov 12, 2024
1 parent af42595 commit 30937be
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions postgres/tests/test_manage_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class TestManageUsers(unittest.TestCase):
def setUp(self):
self.cursor = MagicMock()
boto3.setup_default_session(region_name='eu-west-2')


@classmethod
Expand Down Expand Up @@ -59,7 +60,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 +75,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,7 +109,7 @@ 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")
Expand All @@ -118,9 +119,9 @@ def test_handler(self, mock_connect, mock_create_or_update_db_user):
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 +130,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 30937be

Please sign in to comment.