def test_wrap_list(self, resolwe_mock): process = self.process_mock Resolwe._process_inputs(resolwe_mock, {"src_list": ["/path/to/file"]}, process) resolwe_mock._process_file_field.assert_called_once_with('/path/to/file') resolwe_mock.reset_mock() Resolwe._process_inputs(resolwe_mock, {"src_list": "/path/to/file"}, process) resolwe_mock._process_file_field.assert_called_once_with('/path/to/file')
def test_bad_inputs(self, resolwe_mock, os_mock): # Good file, upload fails becouse of bad input keyword os_mock.path.isfile.return_value = True process = self.process_mock resolwe_mock._upload_file = MagicMock(return_value=None) message = r'Field .* not in process .* input schema.' with self.assertRaisesRegex(ValidationError, message): Resolwe._process_inputs(resolwe_mock, {"bad_key": "/good/path/to/file"}, process)
def test_bad_inputs(self, resolwe_mock, os_mock): # Good file, upload fails becouse of bad input keyword os_mock.path.isfile.return_value = True process = self.process_json[0] resolwe_mock._upload_file = MagicMock(return_value=None) message = r'Field .* not in process .* input schema.' with six.assertRaisesRegex(self, ValidationError, message): Resolwe._process_inputs(resolwe_mock, {"bad_key": "/good/path/to/file"}, process)
def test_wrap_list(self, resolwe_mock): process = self.process_json[0] Resolwe._process_inputs(resolwe_mock, {"src_list": ["/path/to/file"]}, process) resolwe_mock._process_file_field.assert_called_once_with('/path/to/file') resolwe_mock.reset_mock() Resolwe._process_inputs(resolwe_mock, {"src_list": "/path/to/file"}, process) resolwe_mock._process_file_field.assert_called_once_with('/path/to/file')
def test_dehydrate_data(self, resolwe_mock): data_obj = Data(id=1, resolwe=MagicMock()) data_obj.id = 1 # this is overriden when initialized process = self.process_mock result = Resolwe._process_inputs(resolwe_mock, {"genome": data_obj}, process) self.assertEqual(result, {'genome': 1}) result = Resolwe._process_inputs(resolwe_mock, {"reads": [data_obj]}, process) self.assertEqual(result, {'reads': [1]})
def test_dehydrate_data(self, resolwe_mock): data_obj = Data(id=1, resolwe=MagicMock()) data_obj.id = 1 # this is overriden when initialized process = self.process_json[0] result = Resolwe._process_inputs(resolwe_mock, {"genome": data_obj}, process) self.assertEqual(result, {'genome': 1}) result = Resolwe._process_inputs(resolwe_mock, {"reads": [data_obj]}, process) self.assertEqual(result, {'reads': [1]})
def test_dehydrate_data(self, resolwe_mock, copy_mock): data_obj = Data(id=1, resolwe=MagicMock()) data_obj.id = 1 # this is overriden when initialized process = self.process_mock # I appears it is not possible to deepcopy MagicMocks so we just patch # the deepcopy functionality: copy_mock.deepcopy = MagicMock(return_value={"genome": data_obj}) result = Resolwe._process_inputs(resolwe_mock, {"genome": data_obj}, process) self.assertEqual(result, {'genome': 1}) # I appears it is not possible to deepcopy MagicMocks so we just patch # the deepcopy functionality: copy_mock.deepcopy = MagicMock(return_value={"reads": data_obj}) result = Resolwe._process_inputs(resolwe_mock, {"reads": [data_obj]}, process) self.assertEqual(result, {'reads': [1]})
def test_keep_input(self, resolwe_mock): process = self.process_mock input_dict = {"src_list": ["/path/to/file"]} Resolwe._process_inputs(resolwe_mock, input_dict, process) self.assertEqual(input_dict, {"src_list": ["/path/to/file"]})