How can I mock a boto3 sns call in unit tests?
<p>I am trying to unit test a function:</p>

<pre><code>@shared_task()
def push_notification(message=None, message_type=None, user_id=None, data={}):

    #  Get the aws arn from token table
    aws_token_data = AwsDeviceToken.objects.filter(user_id=user_id).latest("id")
    client = boto3.client('sns', **aws.AWS_CREDENTIAL)

    message = {
        'default': message,
         more stuff here 
         'data': data})
    }
    message = json.dumps(message, ensure_ascii=False)
    response = client.publish(
        TargetArn=str(aws_token_data.aws_PLATFORM_endpoint_arn),
        Message=message,
        MessageStructure='json',
        MessageAttributes={}
    )
    return response
</code></pre>

<p>When users register for our service they get a topic arn based on their device type.</p>

<p>I have tried: </p>

<pre><code>def test_push_notification(self):
    with mock.patch('boto3.client') as mock_client:
        data = {'Some data': "to be sent"}
        push_notification(
            message="your invitation has been accepted",
            message_type='b2g_accepted',
            user=self.user,
            data=data
        )
        self.assertEqual(mock_client.call_count, 1)
</code></pre>

<p>Where self.user is a user registered in the setUp method of TestCase. This fails, the call_count is 0</p>

<p>I am scratching my head trying to figure out a way to test this function but mostly coming up with third party modules or examples for S3.</p>

<p>Any help is appreciated </p>