Freesound tests should mock out `head` requests
AetherUnbound opened this issue · 1 comments
AetherUnbound commented
Description
While trying to work on some other issues, I've noticed that some Freesound tests are failing. Error messages below:
The head
requests being performed in _get_audio_file_size
should be mocked out for these tests.
Test errors
__________________________________________________________________________________________________ test_get_tags ___________________________________________________________________________________________________
audio_data = {'avg_rating': 0.0, 'bitdepth': 16, 'bitrate': 1381, 'created': '2018-01-15T00:02:51', ...}
def test_get_tags(audio_data):
> item_data = freesound._extract_audio_data(audio_data)
tests/dags/providers/provider_api_scripts/test_freesound.py:220:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
openverse_catalog/dags/providers/provider_api_scripts/freesound.py:171: in _extract_audio_data
main_audio, alt_files = _get_audio_files(media_data)
openverse_catalog/dags/providers/provider_api_scripts/freesound.py:259: in _get_audio_files
main_file["filesize"] = _get_audio_file_size(main_file["audio_url"])
.local/lib/python3.9/site-packages/decorator.py:232: in fun
return caller(func, *(extras + args), **kw)
.local/lib/python3.9/site-packages/retry/api.py:73: in retry_decorator
return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
.local/lib/python3.9/site-packages/retry/api.py:33: in __retry_internal
return f()
openverse_catalog/dags/providers/provider_api_scripts/freesound.py:238: in _get_audio_file_size
return int(requests.head(url).headers["content-length"])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = {'Connection': 'close'}, key = 'content-length'
def __getitem__(self, key):
> return self._store[key.lower()][1]
E KeyError: 'content-length'
.local/lib/python3.9/site-packages/requests/structures.py:54: KeyError
============================================================================================= short test summary info ==============================================================================================
FAILED tests/dags/providers/provider_api_scripts/test_freesound.py::test_get_items - KeyError: 'content-length'
FAILED tests/dags/providers/provider_api_scripts/test_freesound.py::test_process_item_batch_handles_example_batch[False] - KeyError: 'content-length'
FAILED tests/dags/providers/provider_api_scripts/test_freesound.py::test_process_item_batch_handles_example_batch[True] - KeyError: 'content-length'
FAILED tests/dags/providers/provider_api_scripts/test_freesound.py::test_extract_audio_data_handles_example_dict - KeyError: 'content-length'
FAILED tests/dags/providers/provider_api_scripts/test_freesound.py::test_get_tags - KeyError: 'content-length'
Reproduction
just test
on main
is failing for me currently.
Additional context
Resolution
- 🙋 I would be interested in resolving this bug.
AetherUnbound commented
Well, it looks like this may have just been associated with an outage because they're working again now 🤔 We shouldn't really be dependent on Freesound's status for our testing though, so I'm going to update this issue to something more specific.