

@mock.patch('website.mailchimp_utils.get_mailchimp_api')
def test_subscribe_fake_email_does_not_throw_validation_error(self, mock_get_mailchimp_api):
    list_name = 'foo'
    user = UserFactory(username='fake@fake.com')
    mock_client = mock.MagicMock()
    mock_get_mailchimp_api.return_value = mock_client
    mock_client.lists.list.return_value = {
        'data': [{
            'id': 1,
            'list_name': list_name,
        }],
    }
    mock_client.lists.subscribe.side_effect = mailchimp.ValidationError
    mailchimp_utils.subscribe_mailchimp(list_name, user._id)
    handlers.celery_teardown_request()
    assert_false(user.mailchimp_mailing_lists[list_name])

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