-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/23.08.3' into develop
- Loading branch information
Showing
8 changed files
with
102 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ git+https://github.com/cos-forks/[email protected]+cos0 | |
kombu==4.2.0 | ||
itsdangerous==1.1.0 | ||
lxml==4.6.5 | ||
mailchimp==2.0.9 | ||
mailchimp3==3.0.18 | ||
nameparser==0.5.3 | ||
bcrypt==3.1.4 | ||
python-dateutil==2.8.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
# -*- coding: utf-8 -*- | ||
from hashlib import md5 | ||
import mock | ||
import pytest | ||
from website import mailchimp_utils | ||
from tests.base import OsfTestCase | ||
from mailchimp3.mailchimpclient import MailChimpError | ||
from nose.tools import * # noqa; PEP8 asserts | ||
from osf_tests.factories import UserFactory | ||
import mailchimp | ||
|
||
from framework.celery_tasks import handlers | ||
from osf_tests.factories import UserFactory | ||
from tests.base import OsfTestCase | ||
from website import mailchimp_utils | ||
from website.settings import MAILCHIMP_GENERAL_LIST, MAILCHIMP_LIST_MAP | ||
|
||
|
||
@pytest.mark.enable_enqueue_task | ||
|
@@ -18,69 +20,50 @@ def setUp(self, *args, **kwargs): | |
with self.context: | ||
handlers.celery_before_request() | ||
|
||
@mock.patch('website.mailchimp_utils.get_mailchimp_api') | ||
def test_get_list_id_from_name(self, mock_get_mailchimp_api): | ||
list_name = 'foo' | ||
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}]} | ||
list_id = mailchimp_utils.get_list_id_from_name(list_name) | ||
mock_client.lists.list.assert_called_with(filters={'list_name': list_name}) | ||
assert_equal(list_id, 1) | ||
|
||
@mock.patch('website.mailchimp_utils.get_mailchimp_api') | ||
def test_get_list_name_from_id(self, mock_get_mailchimp_api): | ||
list_id = '12345' | ||
mock_client = mock.MagicMock() | ||
mock_get_mailchimp_api.return_value = mock_client | ||
mock_client.lists.list.return_value = {'data': [{'id': list_id, 'name': 'foo'}]} | ||
mock_client.lists.get.return_value = {'id': list_id, 'name': 'foo'} | ||
list_name = mailchimp_utils.get_list_name_from_id(list_id) | ||
mock_client.lists.list.assert_called_with(filters={'list_id': list_id}) | ||
mock_client.lists.get.assert_called_with(list_id=list_id) | ||
assert_equal(list_name, 'foo') | ||
|
||
@mock.patch('website.mailchimp_utils.get_mailchimp_api') | ||
def test_subscribe_called_with_correct_arguments(self, mock_get_mailchimp_api): | ||
list_name = 'foo' | ||
def test_subscribe_called(self, mock_get_mailchimp_api): | ||
list_name = MAILCHIMP_GENERAL_LIST | ||
user = UserFactory() | ||
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.get.return_value = {'id': 1, 'list_name': list_name} | ||
list_id = mailchimp_utils.get_list_id_from_name(list_name) | ||
mailchimp_utils.subscribe_mailchimp(list_name, user._id) | ||
handlers.celery_teardown_request() | ||
mock_client.lists.subscribe.assert_called_with( | ||
id=list_id, | ||
email={'email': user.username}, | ||
merge_vars={ | ||
'fname': user.given_name, | ||
'lname': user.family_name, | ||
}, | ||
double_optin=False, | ||
update_existing=True, | ||
) | ||
mock_client.lists.members.create_or_update.assert_called() | ||
|
||
@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' | ||
list_name = MAILCHIMP_GENERAL_LIST | ||
user = UserFactory(username='[email protected]') | ||
assert list_name not in user.mailchimp_mailing_lists | ||
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 | ||
mock_client.lists.members.create_or_update.side_effect = MailChimpError | ||
mailchimp_utils.subscribe_mailchimp(list_name, user._id) | ||
handlers.celery_teardown_request() | ||
user.reload() | ||
assert_false(user.mailchimp_mailing_lists[list_name]) | ||
|
||
@mock.patch('website.mailchimp_utils.get_mailchimp_api') | ||
def test_unsubscribe_called_with_correct_arguments(self, mock_get_mailchimp_api): | ||
list_name = 'foo' | ||
list_name = MAILCHIMP_GENERAL_LIST | ||
list_id = MAILCHIMP_LIST_MAP[MAILCHIMP_GENERAL_LIST] | ||
user = UserFactory() | ||
user_hash = md5(user.username.lower().encode()).hexdigest() | ||
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) | ||
mock_client.lists.members.delete.assert_called_with(list_id=list_id, subscriber_hash=user_hash) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.