def test_returns_correct_info(self, mock_getsize, mock_current_app,
                               mock_decrypt_filename):
     pairpath = '/pa/th/path'
     files = ['metaid_m1_1-captions-eng.vtt']
     mock_decrypt_filename.return_value = {
         'manifestation': '1',
         'fileset': '1',
         'kind': 'captions',
         'language': 'eng',
     }
     mock_getsize.return_value = 256
     expected = {
         '1': {
             '1': [{
                 'MIMETYPE': 'text/vtt',
                 'USE': 'vtt',
                 'flocat':
                 'http://example.com/pa/th/path/metaid_m1_1-captions-eng.vtt',
                 'SIZE': '256',
                 'vtt_kind': 'captions',
                 'language': 'eng',
             }]
         }
     }
     result = get_files_info(pairpath, files)
     assert result == expected
 def test_path_does_not_exist(self, mock_getsize, mock_current_app,
                              mock_decrypt_filename):
     pairpath = '/pa/th/path'
     files = ['id_m1_1-captions-eng.vtt']
     mock_decrypt_filename.return_value = {
         'manifestation': '1',
         'fileset': '1',
         'kind': 'captions',
         'language': 'eng'
     }
     mock_getsize.side_effect = OSError
     result = get_files_info(pairpath, files)
     assert result == {}
 def test_flocat_has_single_slash(self, mock_getsize, mock_current_app,
                                  mock_decrypt_filename, transcription_url):
     mock_current_app.config[''] = transcription_url
     pairpath = '/pa/th/path'
     files = ['metaid_m1_1-captions-eng.vtt']
     mock_decrypt_filename.return_value = {
         'manifestation': '1',
         'fileset': '1',
         'kind': 'captions',
         'language': 'eng',
     }
     mock_getsize.return_value = 256
     expected_flocat = 'http://example.com/pa/th/path/metaid_m1_1-captions-eng.vtt'
     result = get_files_info(pairpath, files)
     assert result['1']['1'][0]['flocat'] == expected_flocat
 def test_removes_bad_extensions(self, mock_getsize, mock_current_app,
                                 mock_decrypt_filename):
     pairpath = '/pa/th/path'
     files = [
         'id_m1_1-captions-eng.vtt', 'id_m1_1-captions-ger.txt',
         'id_m1_1-captions-fr.vtt'
     ]
     mock_decrypt_filename.return_value = {
         'manifestation': '1',
         'fileset': '1',
         'kind': 'captions',
         'language': 'eng'
     }
     mock_getsize.return_value = 256
     result = get_files_info(pairpath, files)
     assert len(result['1']['1']) == 2
     assert result['1']['1'][0]['flocat'].endswith('.vtt')
     assert result['1']['1'][1]['flocat'].endswith('.vtt')
 def test_manifestation_and_fileset_structure(self, mock_getsize,
                                              mock_current_app,
                                              mock_decrypt_filename):
     pairpath = '/pa/th/path'
     files = [
         'metaid_m1_8-captions-eng.vtt', 'metaid_m2_5-captions-ger.vtt'
     ]
     mock_decrypt_filename.side_effect = [{
         'manifestation': '1',
         'fileset': '8',
         'kind': 'captions',
         'language': 'eng',
     }, {
         'manifestation': '2',
         'fileset': '5',
         'kind': 'captions',
         'language': 'ger',
     }]
     mock_getsize.return_value = 256
     result = get_files_info(pairpath, files)
     assert result['1']['8']
     assert result['2']['5']
     assert not result['1']['1']
 def test_bad_filenames(self, mock_current_app, mock_decrypt_filename,
                        files):
     pairpath = '/pa/th/path'
     mock_decrypt_filename.return_value = {}
     result = get_files_info(pairpath, files)
     assert result == {}