"""Test asset file details model.""" from asset_file_details.models import file_details \ as file_details_model from asset_file_details.queries import file_details def test_get_file_details_model(mocker): """Test getting a valid file details from the model.""" file_format = 'wav' upc = 1234567890 audio_channels = 2 frequency = 44100 physical_location_id = 1 bits_per_sample = 16 filename = '1234567890_1_1.wav' md5_hash = '098f6bcd4621d373cade4e832627b4f6' initial_folder = 'WAV45/' folder_structure = '{upc(0,6)}/{upc(6,3)}/{upc}' host = '10.10.40.150' test_result = [{ 'audio_channels': audio_channels, 'frequency': frequency, 'bits_per_sample': bits_per_sample, 'filename': filename, 'md5_hash': md5_hash, 'initial_folder': initial_folder, 'folder_structure': folder_structure, 'host': host }] session_mock = mocker.Mock() session_mock.execute.return_value.mappings.return_value.all.return_value = test_result mocked_query_obj = mocker.patch('asset_file_details.models.file_details.sqlalchemy.text') expected_query_args = {'upc': upc, 'asset_type': file_format, 'physical_location_id': physical_location_id} result = file_details_model.get_file_details_by_format( file_format, upc, session=session_mock) mocked_query_obj.assert_called_with(file_details.get_file_details) session_mock.execute.assert_called_with(mocked_query_obj(), expected_query_args) assert result == test_result def test_get_file_details_model_with_physical_location_id(mocker): """Test getting a valid file details from the model with a specified physical location id.""" file_format = 'wav' upc = 1234567890 audio_channels = 2 frequency = 44100 physical_location_id = 1337 bits_per_sample = 16 filename = '1234567890_1_1.wav' md5_hash = '098f6bcd4621d373cade4e832627b4f6' initial_folder = 'WAV45/' folder_structure = '{upc(0,6)}/{upc(6,3)}/{upc}' host = '10.10.40.150' test_result = [{ 'audio_channels': audio_channels, 'frequency': frequency, 'bits_per_sample': bits_per_sample, 'filename': filename, 'md5_hash': md5_hash, 'initial_folder': initial_folder, 'folder_structure': folder_structure, 'host': host }] session_mock = mocker.Mock() session_mock.execute.return_value.mappings.return_value.all.return_value = test_result mocked_query_obj = mocker.patch('asset_file_details.models.file_details.sqlalchemy.text') expected_query_args = {'upc': upc, 'asset_type': file_format, 'physical_location_id': physical_location_id} result = file_details_model.get_file_details_by_format( file_format, upc, physical_location_id=physical_location_id, session=session_mock) mocked_query_obj.assert_called_with(file_details.get_file_details) session_mock.execute.assert_called_with(mocked_query_obj(), expected_query_args) assert result == test_result