

@mock.patch('website.mailchimp_utils.get_mailchimp_api')
def test_unsubscribe_called_with_correct_arguments(self, mock_get_mailchimp_api):
    list_name = 'foo'
    user = UserFactory()
    mock_client = mock.MagicMock()
    mock_get_mailchimp_api.return_value = mock_client
    mock_client.lists.list.return_value = {
        'data': [{
            'id': 2,
            'list_name': list_name,
        }],
    }
    list_id = mailchimp_utils.get_list_id_from_name(list_name)
    mailchimp_utils.unsubscribe_mailchimp_async(list_name, user._id)
    handlers.celery_teardown_request()
    mock_client.lists.unsubscribe.assert_called_with(id=list_id, email={
        'email': user.username,
    }, send_goodbye=True)

dataset/ETHPy150Open CenterForOpenScience/osf.io/tests/test_mailchimp.py TestMailChimpHelpers.test_unsubscribe_called_with_correct_arguments/original