Exemple #1
0
    def test_from_progress_report(self):
        """
        Test that building an ProgressReport from the output of build_progress_report() makes an equivalent
        ProgressReport.
        """
        state = progress.ProgressReport.STATE_FAILED
        state_times = {
            progress.ProgressReport.STATE_FAILED:
            datetime(2013, 5, 3, 20, 11, 3)
        }
        error_message = 'This is an error message.'
        traceback = 'This is a traceback.'
        original_report = progress.ProgressReport(self.conduit,
                                                  state=state,
                                                  state_times=state_times,
                                                  error_message=error_message,
                                                  traceback=traceback)
        serial_report = original_report.build_progress_report()

        report = progress.ProgressReport.from_progress_report(serial_report)

        # All of the values that we had set in the initial report should be identical on this one, except that
        # the conduit should be None
        self.assertEqual(report.conduit, None)
        self.assertEqual(report._state, original_report.state)
        self.assertEqual(report.state_times, original_report.state_times)
        self.assertEqual(report.error_message, original_report.error_message)
        self.assertEqual(report.traceback, original_report.traceback)
Exemple #2
0
    def test__get_state(self):
        """
        Test our state property as a getter.
        """
        report = progress.ProgressReport(
            None, state=progress.ProgressReport.STATE_COMPLETE)

        self.assertEqual(report.state, progress.ProgressReport.STATE_COMPLETE)
Exemple #3
0
    def test__set_state_same_state(self):
        """
        Test setting a state to the same state. This is weird, but allowed.
        """
        report = progress.ProgressReport(None, state='state_1')

        # This should not raise an Exception
        report.state = 'state_1'

        self.assertEqual(report.state, 'state_1')
Exemple #4
0
    def test__set_state_disallowed_transition(self):
        """
        Test the state property as a setter for a disallowed state transition.
        """
        report = progress.ProgressReport(None, state='state_1')

        # We can't go from state_1 to anything other than state_2
        try:
            report.state = 'state_3'
            self.fail(
                'The line above this should have raised an Exception, but it did not.'
            )
        except ValueError, e:
            expected_error_substring = '%s --> %s' % (report.state, 'state_3')
            self.assertTrue(expected_error_substring in str(e))
Exemple #5
0
    def test__set_state_allowed_transition(self):
        """
        Test the state property as a setter for an allowed state transition.
        """
        report = progress.ProgressReport(self.conduit, state='state_1')

        # This is an allowed transition, so it should not raise an error
        report.state = 'state_2'

        self.assertEqual(report._state, 'state_2')
        self.assertTrue(report._state in report.state_times)
        self.assertTrue(isinstance(report.state_times[report._state],
                                   datetime))
        self.conduit.set_progress.assert_called_once_with(
            report.build_progress_report())
Exemple #6
0
    def test_update_progress(self):
        """
        The update_progress() method should send the progress report to the conduit.
        """
        state = progress.ProgressReport.STATE_FAILED
        state_times = {progress.ProgressReport.STATE_FAILED: datetime.utcnow()}
        error_message = 'This is an error message.'
        traceback = 'This is a traceback.'
        report = progress.ProgressReport(self.conduit,
                                         state=state,
                                         state_times=state_times,
                                         error_message=error_message,
                                         traceback=traceback)

        report.update_progress()

        # Make sure the conduit's set_progress() method was called
        self.conduit.set_progress.assert_called_once_with(
            report.build_progress_report())
Exemple #7
0
    def test_build_final_report_failure(self):
        """
        Test build_final_report() when there is a failure.
        """
        report = progress.ProgressReport(
            self.conduit, state=progress.ProgressReport.STATE_FAILED)

        conduit_report = report.build_final_report()

        # The success report call should not have been made
        self.assertEqual(self.conduit.build_success_report.call_count, 0)
        # We should have called the failure report once with the serialized progress report as the summary
        self.conduit.build_failure_report.assert_called_once_with(
            report.build_progress_report(), None)

        # Inspect the conduit report
        self.assertEqual(conduit_report.success_flag, False)
        self.assertEqual(conduit_report.canceled_flag, False)
        self.assertEqual(conduit_report.summary,
                         report.build_progress_report())
        self.assertEqual(conduit_report.details, None)
Exemple #8
0
    def test___init__with_non_defaults(self):
        """
        Test the __init__ method when passing in parameters.
        """
        state = progress.ProgressReport.STATE_FAILED
        state_times = {progress.ProgressReport.STATE_FAILED: datetime.utcnow()}
        error_message = 'This is an error message.'
        traceback = 'This is a traceback.'

        report = progress.ProgressReport(self.conduit,
                                         state=state,
                                         state_times=state_times,
                                         error_message=error_message,
                                         traceback=traceback)

        # Make sure all the appropriate attributes were set
        self.assertEqual(report.conduit, self.conduit)
        self.assertEqual(report._state, state)
        self.assertEqual(report.state_times, state_times)
        self.assertEqual(report.error_message, error_message)
        self.assertEqual(report.traceback, traceback)
Exemple #9
0
    def test___init___with_defaults(self):
        """
        Test the __init__ method with all default parameters.
        """
        report = progress.ProgressReport()

        # Make sure all the appropriate attributes were set
        self.assertEqual(report.conduit, None)
        self.assertEqual(report._state,
                         progress.ProgressReport.STATE_NOT_STARTED)

        # The state_times attribute should be a dictionary with only the time the not started state was
        # entered
        self.assertTrue(isinstance(report.state_times, dict))
        self.assertEqual(len(report.state_times), 1)
        self.assertTrue(
            isinstance(
                report.state_times[progress.ProgressReport.STATE_NOT_STARTED],
                datetime))

        self.assertEqual(report.error_message, None)
        self.assertEqual(report.traceback, None)
Exemple #10
0
    def test_build_final_report_cancelled(self):
        """
        Test build_final_report() when the state is cancelled. Since the user asked for it to be
        cancelled, we should report it as a success
        """
        report = progress.ProgressReport(
            self.conduit, state=progress.ProgressReport.STATE_CANCELED)

        conduit_report = report.build_final_report()

        # The failure report call should not have been made
        self.assertEqual(self.conduit.build_failure_report.call_count, 0)
        # We should have called the success report once with the serialized progress report as the
        # summary
        self.conduit.build_success_report.assert_called_once_with(
            report.build_progress_report(), None)

        # Inspect the conduit report
        self.assertEqual(conduit_report.success_flag, True)
        self.assertEqual(conduit_report.canceled_flag, False)
        self.assertEqual(conduit_report.summary,
                         report.build_progress_report())
        self.assertEqual(conduit_report.details, None)
Exemple #11
0
    def test_build_progress_report(self):
        """
        Test the build_progress_report() method.
        """
        state = progress.ProgressReport.STATE_FAILED
        state_times = {progress.ProgressReport.STATE_FAILED: datetime.utcnow()}
        error_message = 'This is an error message.'
        traceback = 'This is a traceback.'
        report = progress.ProgressReport(self.conduit,
                                         state=state,
                                         state_times=state_times,
                                         error_message=error_message,
                                         traceback=traceback)

        report = report.build_progress_report()

        # Make sure all the appropriate attributes were set
        self.assertEqual(report['state'], state)
        expected_state_times = {}
        for key, value in state_times.items():
            expected_state_times[key] = format_iso8601_datetime(value)
        self.assertTrue(report['state_times'], expected_state_times)
        self.assertEqual(report['error_message'], error_message)
        self.assertEqual(report['traceback'], traceback)