def test_archived_testcase(self): """Ensure that we properly unpack archived test cases.""" self.mock.request.return_value = (FakeResponse(200, filename='test.zip'), 'zip data') self.mock.get_file_list.return_value = ['test.html', 'resource.js'] testcase = reproduce.SerializedTestcase({ 'archive_state': data_types.ArchiveStatus.ALL, 'absolute_path': '/path/to/test.html', 'minimized_keys': 'key', }) current_testcase_directory = os.path.join(reproduce.CONFIG_DIRECTORY, 'current-testcase') zip_path = os.path.join(current_testcase_directory, 'test.zip') reproduce._download_testcase(1, testcase, self.config) self.mock.write_data_to_file.assert_called_once_with( 'zip data', zip_path) self.mock.unpack.assert_called_once_with(zip_path, current_testcase_directory)
def test_archived_testcase(self): """Ensure that we properly unpack archived test cases.""" self.mock.request.return_value = ( FakeResponse(200, filename="test.zip"), "zip data", ) self.mock.get_file_list.return_value = ["test.html", "resource.js"] testcase = reproduce.SerializedTestcase({ "archive_state": data_types.ArchiveStatus.ALL, "absolute_path": "/path/to/test.html", "minimized_keys": "key", }) current_testcase_directory = os.path.join(reproduce.CONFIG_DIRECTORY, "current-testcase") zip_path = os.path.join(current_testcase_directory, "test.zip") reproduce._download_testcase(1, testcase, self.config) self.mock.write_data_to_file.assert_called_once_with( "zip data", zip_path) self.mock.unpack.assert_called_once_with(zip_path, current_testcase_directory)
def test_archive_missing_file(self): """Ensure that we raise if the archive is missing an expected file.""" self.mock.request.return_value = (FakeResponse(200, filename='test.zip'), 'zip data') self.mock.get_file_list.return_value = [] testcase = reproduce.SerializedTestcase({ 'archive_state': data_types.ArchiveStatus.ALL, 'absolute_path': '/path/to/test.html', 'minimized_keys': 'key', }) with self.assertRaises(errors.ReproduceToolUnrecoverableError): reproduce._download_testcase(1, testcase, self.config)
def test_non_archived_testcase(self): """Ensure that we properly unpack non-archived test cases.""" self.mock.request.return_value = (FakeResponse(200, filename='test.html'), 'html data') testcase = reproduce.SerializedTestcase({ 'archive_state': data_types.ArchiveStatus.NONE, 'minimized_keys': 'key', }) reproduce._download_testcase(1, testcase, self.config) self.mock.write_data_to_file.assert_called_once_with( 'html data', os.path.join(reproduce.CONFIG_DIRECTORY, 'current-testcase', 'test.html'))
def test_non_archived_testcase(self): """Ensure that we properly unpack non-archived test cases.""" self.mock.request.return_value = ( FakeResponse(200, filename="test.html"), "html data", ) testcase = reproduce.SerializedTestcase({ "archive_state": data_types.ArchiveStatus.NONE, "minimized_keys": "key" }) reproduce._download_testcase(1, testcase, self.config) self.mock.write_data_to_file.assert_called_once_with( "html data", os.path.join(reproduce.CONFIG_DIRECTORY, "current-testcase", "test.html"), )
def test_initial_request_failed(self): """Ensure that we bail out if the initial request fails.""" self.mock.request.return_value = (FakeResponse(500), '') testcase = reproduce.SerializedTestcase({}) with self.assertRaises(errors.ReproduceToolUnrecoverableError): reproduce._download_testcase(1, testcase, self.config)