So I have a class S3 in file/s3.py with the following init:
class S3:
def __init__(self):
self.s3_client = boto3.client("s3")
def get_object(self):
s3_object = self.s3_client.get_object()
return s3_object
As you can see, the boto3.client class has a method named get_object() as well. I'm testing my custom get_object() method from another file but don't want to actaully make a boto3.client call to AWS services.
test.py
class TestS3Class(unittest.TestCase):
"""TestCase for file/s3.py"""
def setUp(self):
"""Creates an instance of the live S3 class for testing"""
self.s3_test_client = S3()
@patch('boto3.client')
def test_get_object(self, mock_client):
""""""
mock_client.get_object.return_value = {'key': 'value'}
self.assertIsInstance(self.s3_test_client.get_object(), dict)
At the moment I'm getting AssertionError: None is not an instance of <class 'dict'> as a response, so I'm not sure if I'm patching something or not, but it's definitely not setting boto3.client.get_object()'s return value to the dictionary object.
Any hints on how to mock that self.s3_client = boto3.client()?