Example #1
0
    def test__raise_path_error_not_found(self):
        """
        For a standard error like 404, the report's error message should be used.
        """
        report = DownloadReport('http://foo/bar', '/a/b/c')
        report.error_report = {'response_code': httplib.NOT_FOUND}
        report.error_msg = 'oops'

        with self.assertRaises(IOError) as assertion:
            registry.V2Repository._raise_path_error(report)

        self.assertEqual(assertion.exception.message, report.error_msg)
Example #2
0
    def test__raise_path_error_not_found(self):
        """
        For a standard error like 404, the report's error message should be used.
        """
        report = DownloadReport('http://foo/bar', '/a/b/c')
        report.error_report = {'response_code': httplib.NOT_FOUND}
        report.error_msg = 'oops'

        with self.assertRaises(IOError) as assertion:
            registry.V2Repository._raise_path_error(report)

        self.assertEqual(assertion.exception.message, report.error_msg)
    def test_download_failed_during_manifest(self):
        self.iso_sync_run.progress_report._state = SyncProgressReport.STATE_MANIFEST_IN_PROGRESS
        url = 'http://www.theonion.com/articles/' +\
            'american-airlines-us-airways-merge-to-form-worlds,31302/'
        report = DownloadReport(url, '/fake/destination')
        report.error_report = {'why': 'because'}

        self.iso_sync_run.download_failed(report)

        # The manifest_state should be failed
        self.assertEqual(self.iso_sync_run.progress_report._state,
                         SyncProgressReport.STATE_MANIFEST_FAILED)
        self.assertEqual(self.iso_sync_run.progress_report.error_message, report.error_report)
Example #4
0
    def test__raise_path_error_unathorized(self):
        """
        Specifically for a 401, a custom error message should be used explaining that the cause
        could be either that the client is unauthorized, or that the resource was not found.
        Docker hub responds 401 for the not found case, which is why this function exists.
        """
        report = DownloadReport('http://foo/bar', '/a/b/c')
        report.error_report = {'response_code': httplib.UNAUTHORIZED}
        report.error_msg = 'oops'

        with self.assertRaises(IOError) as assertion:
            registry.V2Repository._raise_path_error(report)

        # not worrying about what the exact contents are; just that the function added its
        # own message
        self.assertNotEqual(assertion.exception.message, report.error_msg)
        self.assertTrue(len(assertion.exception.message) > 0)
Example #5
0
    def test_download_failed_during_manifest(self, _logger):
        self.iso_sync_run.progress_report._state = SyncProgressReport.STATE_MANIFEST_IN_PROGRESS
        url = 'http://www.theonion.com/articles/' + \
              'american-airlines-us-airways-merge-to-form-worlds,31302/'
        report = DownloadReport(url, '/fake/destination')
        report.error_report = {'why': 'because'}
        report.error_msg = 'uh oh'

        self.iso_sync_run.download_failed(report)

        # The manifest_state should be failed
        self.assertEqual(self.iso_sync_run.progress_report._state,
                         SyncProgressReport.STATE_MANIFEST_FAILED)
        self.assertEqual(self.iso_sync_run.progress_report.error_message, report.error_report)
        self.assertEqual(_logger.error.call_count, 1)
        log_msg = _logger.error.mock_calls[0][1][0]
        self.assertTrue('uh oh' in log_msg)
Example #6
0
    def test__raise_path_error_unathorized(self):
        """
        Specifically for a 401, a custom error message should be used explaining that the cause
        could be either that the client is unauthorized, or that the resource was not found.
        Docker hub responds 401 for the not found case, which is why this function exists.
        """
        report = DownloadReport('http://foo/bar', '/a/b/c')
        report.error_report = {'response_code': httplib.UNAUTHORIZED}
        report.error_msg = 'oops'

        with self.assertRaises(IOError) as assertion:
            registry.V2Repository._raise_path_error(report)

        # not worrying about what the exact contents are; just that the function added its
        # own message
        self.assertNotEqual(assertion.exception.message, report.error_msg)
        self.assertTrue(len(assertion.exception.message) > 0)