Пример #1
0
    def test_failure_timeout(self):
        """
        If a file fails to be sent to harstorage because of a timeout,
        then it is left in the folder to retry.
        """
        @urlmatch(method='post')
        def harstorage_mock_timeout(*args, **kwargs):
            raise requests.exceptions.Timeout('TimeoutError')

        with HTTMock(harstorage_mock_timeout):
            uploader = haruploader.Uploader(self.test_dir, self.url)
            uploader.upload_hars()

        self.assertTrue(os.path.isfile(self.test_file))
Пример #2
0
    def test_failure_bad_status(self):
        """
        If a file fails to be sent to harstorage because of a 500 error,
        then it is left in the folder to retry.
        """
        @urlmatch(method='post')
        def harstorage_mock_server_error(*args, **kwargs):
            return {
                'status_code': 500,
                'content': 'Internal Server Error',
            }

        with HTTMock(harstorage_mock_server_error):
            uploader = haruploader.Uploader(self.test_dir, self.url)
            uploader.upload_hars()

        self.assertTrue(os.path.isfile(self.test_file))
Пример #3
0
    def test_success(self):
        """
        If a file is successfully sent to harstorage, then it is put in
        the 'completed_uploads' folder.
        """
        @urlmatch(method='post')
        def harstorage_mock_success(*args, **kwargs):
            return {
                'status_code': 200,
                'content': 'Successful'
            }

        with HTTMock(harstorage_mock_success):
            uploader = haruploader.Uploader(self.test_dir, self.url)
            uploader.upload_hars()

        expected_file = os.path.join(
            self.test_dir,
            'completed_uploads',
            os.path.basename(self.test_file)
        )

        self.assertTrue(os.path.isfile(expected_file))
Пример #4
0
    def test_failure_bad_file(self):
        """
        If a file fails to be sent to harstorage because it is malformed,
        then it is put in a folder of failed files so that we can possibly
        inspect them.
        """
        @urlmatch(method='post')
        def harstorage_mock_parsing_error(*args, **kwargs):
            return {
                'status_code': 200,
                'content': 'KeyError: timing'
            }

        with HTTMock(harstorage_mock_parsing_error):
            uploader = haruploader.Uploader(self.test_dir, self.url)
            uploader.upload_hars()

        expected_file = os.path.join(
            self.test_dir,
            'failed_uploads',
            os.path.basename(self.test_file)
        )

        self.assertTrue(os.path.isfile(expected_file))