示例#1
0
 def test_get_progress_report_summary(self):
     parent_step = publish_step.PluginStep('parent_step')
     step = publish_step.PluginStep('foo_step')
     parent_step.add_child(step)
     step.state = reporting_constants.STATE_COMPLETE
     report = parent_step.get_progress_report_summary()
     target_report = {
         'foo_step': reporting_constants.STATE_COMPLETE
     }
     compare_dict(report, target_report)
示例#2
0
    def test_build_final_report_success(self):

        step_one = publish_step.PluginStep('step_one')
        step_one.state = reporting_constants.STATE_COMPLETE
        step_two = publish_step.PluginStep('step_two')
        step_two.state = reporting_constants.STATE_COMPLETE
        self.pluginstep.add_child(step_one)
        self.pluginstep.add_child(step_two)

        report = self.pluginstep._build_final_report()

        self.assertTrue(report.success_flag)
示例#3
0
 def test_cancel_before_processing(self):
     self.pluginstep.repo.content_unit_counts = {'FOO_TYPE': 2}
     step = publish_step.PluginStep('foo_step')
     step.is_skipped = Mock()
     step.cancel()
     step.process()
     self.assertEquals(0, step.is_skipped.call_count)
示例#4
0
 def test_process_lifecycle_no_working_dir(self, mock_wd):
     # we need to mock this to None instead of just setting
     # self.working_directory to None so that we don't go up the step repo
     # chain looking for working_dirs
     mock_wd.return_value = None
     step = publish_step.PluginStep("foo")
     self.assertRaises(RuntimeError, step.process_lifecycle)
示例#5
0
 def test_get_conduit_not_set(self):
     """
     Test that if the conduit has not been set in this step or it's parent, that we
     return None
     """
     step = publish_step.PluginStep('foo_step')
     self.assertEquals(None, step.get_conduit())
示例#6
0
 def test_build_final_report_reporting_disable(self):
     """
     Test that _build_final_report returnes None if reporting has been disabled
     """
     step = publish_step.PluginStep('step_one', disable_reporting=True)
     report = step._build_final_report()
     self.assertEquals(report, None)
示例#7
0
    def test_process_lifecycle(self):
        # set working_dir and conduit. This is required by process_lifecycle
        step = publish_step.PluginStep(
            'parent', working_dir=self.working_dir, conduit=self.conduit)
        step.process = Mock()
        child_step = publish_step.PluginStep(
            'child', working_dir=self.working_dir, conduit=self.conduit)
        child_step.process = Mock()
        step.add_child(child_step)
        step.report_progress = Mock()

        step.process_lifecycle()

        step.process.assert_called_once_with()
        child_step.process.assert_called_once_with()
        step.report_progress.assert_called_once_with(force=True)
示例#8
0
 def test_get_working_dir_from_parent(self):
     """
     Test getting the working dir from a parent step
     """
     step = publish_step.PluginStep('foo_step')
     step.parent = Mock(get_working_dir=Mock(return_value='foo'))
     self.assertEquals('foo', step.get_working_dir())
示例#9
0
 def test_get_working_dir_from_util(self, mock_get_working_dir):
     """
     Test getting the working dir from the utilities
     """
     step = publish_step.PluginStep('foo_step')
     mock_get_working_dir.return_value = 'foo'
     self.assertEquals('foo', step.get_working_dir())
示例#10
0
 def test_get_working_dir_from_step(self):
     """
     Test getting the working dir if it has already been calculated or set on this step
     """
     step = publish_step.PluginStep('foo_step')
     step.working_dir = 'foo'
     self.assertEquals('foo', step.get_working_dir())
示例#11
0
 def test_process_lifecycle_exception_still_removes_working_dir(self, super_pl, mock_rmtree):
     step = publish_step.PluginStep("foo", working_dir=self.working_dir, conduit=self.conduit)
     step._build_final_report = Mock()
     self.assertRaises(Exception, step.process_lifecycle)
     super_pl.assert_called_once_with()
     self.assertFalse(step._build_final_report.called)
     mock_rmtree.assert_called_once_with(self.working_dir, ignore_errors=True)
示例#12
0
    def test_process_child_on_error_notifies_parent(self):
        # set working_dir and conduit. This is required by process_lifecycle
        step = publish_step.PluginStep('parent', working_dir=self.working_dir, conduit=self.conduit)
        child_step = publish_step.PluginStep(
            'child', working_dir=self.working_dir, conduit=self.conduit)
        child_step.initialize = Mock(side_effect=Exception('boo'))
        child_step.on_error = Mock(side_effect=Exception('flux'))
        step.on_error = Mock()

        step.add_child(child_step)

        self.assertRaises(Exception, step.process_lifecycle)

        self.assertEquals(reporting_constants.STATE_FAILED, step.state)
        self.assertEquals(reporting_constants.STATE_FAILED, child_step.state)
        self.assertTrue(step.on_error.called)
        self.assertTrue(child_step.on_error.called)
示例#13
0
 def test_process_lifecycle_non_existent_working_dir(self, mock_wd, mock_rmtree, mock_progress,
                                                     mock_build_report):
     new_dir = os.path.join(self.working_dir, 'test', 'bar')
     mock_wd.return_value = new_dir
     step = publish_step.PluginStep("foo")
     step.process_lifecycle()
     self.assertTrue(os.path.exists(new_dir))
     mock_rmtree.assert_called_once_with(new_dir, ignore_errors=True)
示例#14
0
    def test_process_lifecycle_reports_on_error(self):
        # set working_dir and conduit. This is required by process_lifecycle
        step = publish_step.PluginStep('parent', working_dir=self.working_dir, conduit=self.conduit)
        step.process = Mock(side_effect=Exception('Foo'))
        step.report_progress = Mock()

        self.assertRaises(Exception, step.process_lifecycle)

        step.report_progress.assert_called_once_with(force=True)
示例#15
0
 def test_process_step_failure_reported_on_metadata_finalized(self, mock_get_units):
     self.pluginstep.repo.content_unit_counts = {'FOO_TYPE': 1}
     mock_get_units.return_value = ['mock_unit']
     step = publish_step.PluginStep('foo_step')
     step.parent = self.pluginstep
     step.finalize = Mock(side_effect=Exception())
     self.assertRaises(Exception, step.process)
     self.assertEquals(step.state, reporting_constants.STATE_FAILED)
     self.assertEquals(step.progress_successes, 1)
     self.assertEquals(step.progress_failures, 1)
     self.assertEquals(step.total_units, 1)
示例#16
0
    def test_record_failure(self):
        plugin_step = publish_step.PluginStep('foo_step')
        plugin_step.parent = self.pluginstep

        error_msg = 'Too bad, so sad'

        try:
            raise Exception(error_msg)

        except Exception, e:
            tb = sys.exc_info()[2]
            plugin_step._record_failure(e, tb)
示例#17
0
    def setUp(self):
        self.working_dir = tempfile.mkdtemp(prefix='working_')

        self.repo_id = 'publish-test-repo'
        self.repo = Repository(self.repo_id, working_dir=self.working_dir)
        self.conduit = RepoPublishConduit(self.repo_id, 'test_plugin_id')
        self.conduit.get_repo_scratchpad = Mock(return_value={})

        self.config = PluginCallConfiguration(None, None)
        self.pluginstep = publish_step.PluginStep(
            "base-step", repo=self.repo, conduit=self.conduit,
            config=self.config, plugin_type='test_plugin_type')
示例#18
0
    def test_get_progress_report(self):
        step = publish_step.PluginStep('foo_step')
        step.error_details = "foo"
        step.state = reporting_constants.STATE_COMPLETE
        step.total_units = 2
        step.progress_successes = 1
        step.progress_failures = 1
        report = step.get_progress_report()

        target_report = {
            reporting_constants.PROGRESS_STEP_TYPE_KEY: 'foo_step',
            reporting_constants.PROGRESS_NUM_SUCCESSES_KEY: 1,
            reporting_constants.PROGRESS_STATE_KEY: step.state,
            reporting_constants.PROGRESS_ERROR_DETAILS_KEY: step.error_details,
            reporting_constants.PROGRESS_NUM_PROCESSED_KEY: 2,
            reporting_constants.PROGRESS_NUM_FAILURES_KEY: 1,
            reporting_constants.PROGRESS_ITEMS_TOTAL_KEY: 2,
            reporting_constants.PROGRESS_DESCRIPTION_KEY: '',
            reporting_constants.PROGRESS_DETAILS_KEY: '',
            reporting_constants.PROGRESS_STEP_UUID: step.uuid
        }

        compare_dict(report[0], target_report)
示例#19
0
 def test_get_repo(self):
     step = publish_step.PluginStep('foo_step')
     step.repo = 'foo'
     self.assertEquals('foo', step.get_repo())
示例#20
0
 def test_get_plugin_type(self):
     step = publish_step.PluginStep('foo_step')
     step.plugin_type = 'foo'
     self.assertEquals('foo', step.get_plugin_type())
示例#21
0
 def test_get_plugin_type_none(self):
     step = publish_step.PluginStep('foo_step')
     self.assertEquals(None, step.get_plugin_type())
示例#22
0
 def test_get_conduit(self):
     step = publish_step.PluginStep('foo_step')
     step.conduit = 'foo'
     self.assertEquals('foo', step.get_conduit())
示例#23
0
 def test_get_conduit_from_parent(self):
     step = publish_step.PluginStep('foo_step')
     step.conduit = 'foo'
     step.parent = Mock()
     step.parent.get_conduit.return_value = 'foo'
     self.assertEquals('foo', step.get_conduit())
示例#24
0
 def test_report_progress(self):
     plugin_step = publish_step.PluginStep('foo_step')
     plugin_step.parent = Mock()
     plugin_step.report_progress()
     plugin_step.parent.report_progress.assert_called_once_with(False)