Exemplo n.º 1
0
 def form_valid(self, form):
     try:
         sync_events()
         messages.success(self.request, 'Events gesynct.')
     except EmarsysError as e:
         messages.error(self.request, 'Emarsys error: {}'.format(e))
     return super(EventsSyncView, self).form_valid(form)
    def test_sync_events_unknown_event_names(self, mock_api_get_events):
        EVENT_NAME = 'unknown event näme'
        mock_api_get_events.return_value = {
            EVENT_NAME: 1,
        }
        settings.EMARSYS_EVENTS = {
        }

        num_new_events, num_updated_ids, num_deleted_ids, \
            unsynced_event_names = sync_events()

        self.assertEqual(Event.objects.all().count(), 0)
    def test_sync_events_num_deleted_events(self, mock_api_get_events):
        mock_api_get_events.return_value = {
        }
        settings.EMARSYS_EVENTS = {
        }

        Event.objects.create(name='töst event 1', emarsys_id=1)

        num_new_events, num_updated_ids, num_deleted_ids, \
            unsynced_event_names = sync_events()

        self.assertEqual(num_deleted_ids, 1)
        self.assertEqual(Event.objects.all().count(), 0)
    def test_sync_events_unsynced_event_names(self, mock_api_get_events,
                                              mock_event_log):
        mock_api_get_events.return_value = {
        }
        settings.EMARSYS_EVENTS = {
            'unsynced event näme': {},
        }

        num_new_events, num_updated_ids, num_deleted_ids, \
            unsynced_event_names = sync_events()

        self.assertEqual(unsynced_event_names, ['unsynced event näme'])
        mock_event_log.warning.assert_called_with(
            'these event names in settings.EMARSYS_EVENTS '
            'are not known by Emarsys: "unsynced event näme"')
    def test_sync_events_num_new_events(self, mock_api_get_events):
        mock_api_get_events.return_value = {
            'töst event 1': 1,
            'töst event 2': 2,
        }
        settings.EMARSYS_EVENTS = {
            'töst event 1': {
            },
            'töst event 2': {
            },
        }
        num_new_events, num_updated_ids, num_deleted_ids, \
            unsynced_event_names = sync_events()

        self.assertEqual(num_new_events, 2)
        self.assertEqual(
            Event.objects.get(name='töst event 1').emarsys_id, 1)
        self.assertEqual(
            Event.objects.get(name='töst event 2').emarsys_id, 2)