我想知道如何用会话模拟 boto3 客户端?我尝试了以下方式,但测试失败。我想我没有正确地模拟会话和客户端。
AssertionError: 'arn:aws:quicksight:us-east-1:09876543210[32 chars]ount' !=
Method:
def method():
sts = boto3.client("sts")
session = sts.assume_role(role_arn=role_arn)
quicksight_client = session.client("quicksight", region)
user_arn = quicksight_client.get_quicksight_user_arn(user_name)
单元测试:
@patch("boto3.quicksight")
@patch("boto3.Session")
@patch("boto3.sts")
def test(self, mock_sts_client, mock_session, mock_quicksight_client):
mock_sts_client.return_value.assume_role.return_value = mock_session(aws_access_key_id, aws_secret_access_key, aws_session_token)
mock_quicksight_client.return_value.get_quicksight_user_arn.return_value = valid_user_arn
response = self.method()
valid_response = valid_user_arn
self.assertEqual(valid_response, response)