Пример #1
0
    def test_apply_notification_eventids(self, mock_statistics,
                                         mock_notification, mock_get_event_ids,
                                         mock_get_combinations,
                                         mock_add_notification,
                                         mock_storage_handler):
        """Tests if the correct before and after event ids are passed in the EventNotification

        :param mock_storage_handler:
        :return:
        """
        mock_statistics().applied = 1

        test_cases = [
            # (number_of_result_combinations, (n*2 calls to get_event_ids max), before, after)
            # Each iteration performs 2 calls to get_event_ids. The items in the list are the values that are returned
            # as the max_eventid for each call.
            (1, [None, 10404], 0, 10404),
            (1, [None, None], 0, 0),
            (3, [20, 100, 40, 120, 10, 150], 10, 150),
            (2, [20, None, None, 30, 22, 28], 0, 30),
        ]

        for combinations_cnt, max_eventids, before, after in test_cases:
            mock_get_combinations.return_value = [
                MagicMock() for _ in range(combinations_cnt)
            ]
            mock_get_event_ids.side_effect = [(i, 99999999)
                                              for i in max_eventids]
            apply({'header': {}})
            mock_notification.assert_called_with(1, [before, after])
            mock_add_notification.assert_called_once()
            mock_add_notification.reset_mock()

        # Test that add_notification is not called when suppress_notifications is set
        mock_get_combinations.return_value = [MagicMock()]
        mock_get_event_ids.side_effect = [
            (0, 100),
            (1, 99),
        ]
        apply({'header': {'suppress_notifications': True}})
        mock_add_notification.assert_not_called()
Пример #2
0
    def test_apply_up_to_date(self, mock_apply, mock):
        mock.return_value = self.mock_storage
        combination = MockCombination("any source", "any catalogue",
                                      "any entity")
        self.mock_storage.get_source_catalogue_entity_combinations.return_value = [
            combination
        ]

        result = apply({'header': {}})

        self.assertEqual(result, {'header': {}, 'summary': ANY})
        mock_apply.assert_not_called()
Пример #3
0
    def test_apply_trigger_analyze(self, mock_should_analyze, mock_statistics,
                                   mock_storage_handler):
        mock_storage_handler.return_value.get_source_catalogue_entity_combinations.return_value = [
            type(
                'Res', (), {
                    'source': 'the source',
                    'catalogue': 'the catalogue',
                    'entity': 'the entity',
                })
        ]

        # Should analyze is True and mode is full
        msg = {'header': {'mode': 'full'}}
        mock_should_analyze.return_value = True
        apply(msg)
        mock_storage_handler.return_value.analyze_table.assert_called_once()
        mock_storage_handler.reset_mock()

        # Should analyze is True and mode is not full
        msg = {'header': {'mode': 'notfull'}}
        apply(msg)
        mock_storage_handler.return_value.analyze_table.assert_not_called()

        # Should analyze is False and mode is full
        msg = {'header': {'mode': 'full'}}
        mock_should_analyze.return_value = False
        apply(msg)
        mock_storage_handler.return_value.analyze_table.assert_not_called()
Пример #4
0
    def test_apply_none(self, mock_apply, mock_event_notification,
                        mock_add_notification, mock):
        mock.return_value = self.mock_storage
        self.mock_storage.get_source_catalogue_entity_combinations.return_value = []

        result = apply({'header': {}})

        expected_result_msg = {'header': {}, 'summary': ANY}
        self.assertEqual(result, expected_result_msg)
        mock_apply.assert_not_called()

        # Even if none are applied, still trigger notification
        mock_add_notification.assert_called_with(expected_result_msg,
                                                 mock_event_notification())
Пример #5
0
    def test_apply(self, mock_apply, mock_event_notification,
                   mock_add_notification, mock):
        mock.return_value = self.mock_storage
        combination = MockCombination("any source", "any catalogue",
                                      "any entity")
        self.mock_storage.get_source_catalogue_entity_combinations.return_value = [
            combination
        ]

        result = apply({'header': {}})

        result_msg = {'header': {}, 'summary': ANY}

        self.assertEqual(result, result_msg)
        mock_apply.assert_called()

        mock_event_notification.assert_called_with({}, [1, 1])
        mock_add_notification.assert_called_with(result_msg,
                                                 mock_event_notification())