def test_notification_api_fail(self, now_mock, requests_post_mock):
""" Notifications: Test API failure for notify() """
now_mock.return_value = timezone.make_aware(
timezone.datetime(2016, 11, 17, hour=0, minute=5))
requests_post_mock.return_value = mock.MagicMock(
status_code=403, text='Forbidden')
settings = NotificationSetting.get_solo()
settings.send_notification = True
settings.notification_service = NotificationSetting.NOTIFICATION_NMA
settings.api_key = 'es7sh2d-DSMR-Reader-Rulez-iweu732'
settings.next_notification = timezone.localtime(timezone.now())
settings.save()
if self.fixtures:
with self.assertRaises(AssertionError):
dsmr_notification.services.notify()
else:
# When having no data, this should NOT raise an exception.
return dsmr_notification.services.notify()
with self.assertRaisesMessage(
AssertionError, 'Notify API call failed: Forbidden (HTTP403)'):
dsmr_notification.services.notify()
评论列表
文章目录