예제 #1
0
    def test_process_with_unexpected_exception(self, mock_load,
                                               mock_process_main):
        successful_report = Mock()
        successful_report.dict.return_value = {}
        successful_report.succeeded = True

        unsuccessful_report = Mock()
        unsuccessful_report.dict.return_value = {}
        unsuccessful_report.succeeded = False

        sources = {
            'A':
            Mock(id='A',
                 dict=Mock(return_value={'A': 1}),
                 descriptor={'name': 'A'},
                 refresh=Mock(return_value=[successful_report])),
            'B':
            Mock(id='B',
                 dict=Mock(return_value={'B': 2}),
                 descriptor={'name': 'B'},
                 refresh=Mock(return_value=[unsuccessful_report])),
            'C':
            Mock(id='C',
                 dict=Mock(return_value={'C': 3}),
                 descriptor={'name': 'C'},
                 refresh=Mock(return_value=[successful_report])),
        }

        mock_load.return_value = sources
        conduit = content_controller.ContentSourcesConduit('task_id')
        step = content_controller.ContentSourcesRefreshStep(conduit)
        self.assertRaises(Exception, step.process)
        self.assertEquals(step.progress_successes, 0)
        self.assertEqual(step.progress_failures, 1)
예제 #2
0
    def test_process_main_one(self, mock_load, mock_process_main):
        sources = {
            'A': Mock(id='A', dict=Mock(return_value={'A': 1})),
            'B': Mock(id='B', dict=Mock(return_value={'B': 2})),
            'C': Mock(id='C', dict=Mock(return_value={'C': 3})),
        }

        mock_load.return_value = sources
        conduit = content_controller.ContentSourcesConduit('task_id')
        step = content_controller.ContentSourcesRefreshStep(conduit, content_source_id='C')
        step.process()
        step.process_main.assert_called_with(item=sources['C'])
        self.assertEquals(step.progress_successes, 1)
예제 #3
0
    def test_process_main_all(self, mock_load, mock_process_main):
        sources = {
            'A': Mock(id='A', dict=Mock(return_value={'A': 1})),
            'B': Mock(id='B', dict=Mock(return_value={'B': 2})),
            'C': Mock(id='C', dict=Mock(return_value={'C': 3})),
        }

        mock_load.return_value = sources
        conduit = content_controller.ContentSourcesConduit('task_id')
        step = content_controller.ContentSourcesRefreshStep(conduit)
        step.process()
        expected_call_list = []
        for item in step.get_iterator():
            expected_call_list.append(call(item=item))
        self.assertEqual(expected_call_list, step.process_main.call_args_list)
        self.assertEquals(step.progress_successes, 3)
예제 #4
0
 def test_str(self):
     conduit = content_controller.ContentSourcesConduit('task-id-random')
     self.assertEqual(str(conduit), 'ContentSourcesConduit')