def test_set_campaign_content(self): dm_mailchimp_client = DMMailChimpClient('username', DUMMY_MAILCHIMP_API_KEY, 'logger') with mock.patch.object(dm_mailchimp_client._client.campaigns.content, 'update', autospec=True) as update: campaign_id = '1' html_content = {'html': '<p>One or two words</p>'} update.return_value = html_content with assert_external_service_log_entry(): res = dm_mailchimp_client.set_campaign_content(campaign_id, html_content) assert res == html_content dm_mailchimp_client._client.campaigns.content.update.assert_called_once_with(campaign_id, html_content)
def test_log_error_message_if_error_setting_campaign_content(self, exception, expected_error): dm_mailchimp_client = DMMailChimpClient('username', DUMMY_MAILCHIMP_API_KEY, logging.getLogger('mailchimp')) with mock.patch.object(dm_mailchimp_client._client.campaigns.content, 'update', autospec=True) as update: update.side_effect = exception with assert_external_service_log_entry(successful_call=False, extra_modules=['mailchimp']) as log_catcher: res = dm_mailchimp_client.set_campaign_content('1', {"html": "some html"}) assert res is False assert log_catcher.records[1].msg == "Mailchimp failed to set content for campaign id '1'" assert log_catcher.records[1].error == expected_error
def test_log_error_message_if_error_setting_campaign_content(logger): dm_mailchimp_client = DMMailChimpClient('username', 'api key', logger) with mock.patch.object(dm_mailchimp_client._client.campaigns.content, 'update', autospec=True) as update: update.side_effect = RequestException("error message") res = dm_mailchimp_client.set_campaign_content('1', {"html": "some html"}) assert res is False logger.error.assert_called_once_with( "Mailchimp failed to set content for campaign id '1'", extra={"error": "error message"})
def test_set_campaign_content(): dm_mailchimp_client = DMMailChimpClient('username', 'api key', 'logger') with mock.patch.object(dm_mailchimp_client._client.campaigns.content, 'update', autospec=True) as update: campaign_id = '1' html_content = {'html': '<p>One or two words</p>'} update.return_value = html_content res = dm_mailchimp_client.set_campaign_content(campaign_id, html_content) assert res == html_content dm_mailchimp_client._client.campaigns.content.update.assert_called_once_with( campaign_id, html_content)