Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @pytest.mark.django_db
- @testutils.override_settings_dict('MAILCHIMP', 'LISTID_AGENCIES', '123456')
- @testutils.override_settings_dict('MAILCHIMP', 'LISTID_FREELANCERS', '12345')
- @testutils.override_settings_dict('MAILCHIMP', 'SECRET_KEY', MAILCHIMP_SECRET_KEY)
- def test_webhook__unsubscribe_freelancer__wrong_list():
- freelancer = FreelancerProfileFactory()
- freelancer.settings.receive_marketing_emails = True
- freelancer.settings.save()
- url = _get_correct_webhook_url()
- wrong_list_id = '123456789'
- payload = {
- 'type': ['unsubscribe'],
- 'data[list_id]': [wrong_list_id],
- 'data[email]': [freelancer.user.email]
- }
- request = RequestFactory().post(url, payload)
- request.user_agent = 'MailChimp.com'
- with mock.patch('yunojuno.apps.core.views.mailchimp.logger') as _logger:
- mailchimp_views.webhook(request)
- _logger.error.assert_called_once_with(
- "MailChimp webhook called with unknown list_id ({0})".format(wrong_list_id)
- )
- freelancer = FreelancerProfile.objects.last()
- assert freelancer.settings.receive_marketing_emails
- @pytest.mark.django_db
- @testutils.override_settings_dict('MAILCHIMP', 'LISTID_AGENCIES', '123456')
- @testutils.override_settings_dict('MAILCHIMP', 'LISTID_FREELANCERS', '12345')
- @testutils.override_settings_dict('MAILCHIMP', 'SECRET_KEY', MAILCHIMP_SECRET_KEY)
- def test_webhook__unsubscribe__wrong_user_agent():
- wrong_user_agent = 'dummy_user_agent'
- url = _get_correct_webhook_url()
- payload = {
- 'type': ['unsubscribe'],
- 'data[list_id]': ['12345'],
- 'data[email]': '[email protected]'
- }
- request = RequestFactory().post(url, payload)
- request.user_agent = wrong_user_agent
- with mock.patch('yunojuno.apps.core.views.mailchimp.logger') as _logger:
- mailchimp_views.webhook(request)
- _logger.error.assert_called_once_with(
- "MailChimp webhook called non POST request with user_agent ({0})"
- .format(wrong_user_agent)
- )
Advertisement
Add Comment
Please, Sign In to add comment