I have a module which makes object of dynamoDB client. The module is external and does not belong to my code. I am trying to unit test enclosingClass
class enclosingClass:
def enclosing_function():
ddb_client = get_ddb_client(role)
ddb_client.query()
# Module in my code which returns dynamoDB client object
from x.y.common import get_aws_client
def get_ddb_client(role):
return get_aws_client('dynamodb', assume_role_arn=role)
In my code I am getting the aws client object and calling query on it. I want to mock both the things
- return value of get_aws_client should be a mocked object
- Call to query dynamoDB should happen on mocked object.
But when I run unit test, I am getting the actual dynamoDB object and calling query on the dynamoDB object returns 'expected bytes or bytearray, but got 'MagicMock'
I am not understanding what to do in this. very new to python and not sure how do I return a mocked dynamoDb client object
@mock.patch("x.y.common.get_aws_client")
@mock.patch("boto3.client")
def test_hello_world_task(get_aws_client_mock, mock_client):
get_aws_client_mock.return_value= mock_client
mock_client.query.return_value = None
enclosing_class.enclosing_function() # the method call to enclosing function