mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 05:09:58 -05:00
test: do not leave videos_destination as an invalid template (#656)
* test: do not leave videos_destination as an invalid template test_format_videos_destination deliberately sets %(channel)s to prove unknown placeholders fail, then never restored the global WROLPi config. On xdist workers that later ran channel_factory without async_client re-init, the polluted template caused KeyError/FileNotFoundError in test_format_video_filename_uses_channel_name_over_info_json. * test: stop search_suggestions from flaking empty domains on CI A different failure than videos_destination pollution: under xdist load, search_suggestions sometimes returned no domains for a valid query while channels still matched. Harden the path by: - running channel/domain/author/subject searches sequentially on the shared Session (asyncio.gather is not safe with one SQLAlchemy session) - giving archive_factory a URL when only a domain is set so validate() does not clear collection_id via apply_domain() - rewriting test_search_suggestions without hardcoded Collection ids and with unique names that will not collide with other tests
This commit is contained in:
parent
8a74140f95
commit
57d842671f
5 changed files with 73 additions and 48 deletions
|
|
@ -77,6 +77,10 @@ def archive_factory(test_session, archive_directory, make_files_structure, image
|
|||
)
|
||||
test_session.add(collection)
|
||||
test_session.flush([collection])
|
||||
# Archive.validate() -> apply_domain() clears collection_id when URL is missing.
|
||||
# Give a URL derived from the domain so the link survives validation.
|
||||
if not url:
|
||||
url = f'https://{domain}/'
|
||||
else:
|
||||
collection = None
|
||||
|
||||
|
|
|
|||
|
|
@ -1493,6 +1493,7 @@ async def search_domains_by_name(session: Session, name: str, limit: int = 5) ->
|
|||
Returns:
|
||||
List of domain dicts matching the search (in old Domain format for backward compatibility)
|
||||
"""
|
||||
name = name or ''
|
||||
collections = session.query(Collection) \
|
||||
.filter(Collection.kind == 'domain') \
|
||||
.filter(Collection.name.ilike(f'%{name}%')) \
|
||||
|
|
|
|||
|
|
@ -337,30 +337,36 @@ def test_link_channel_and_downloads_by_source_id(test_session, channel_factory,
|
|||
async def test_format_videos_destination(async_client, test_directory):
|
||||
"""Videos destination is formatted according to the WROLPiConfig."""
|
||||
wrolpi_config = get_wrolpi_config()
|
||||
# Restore after mutating the global singleton so later tests (especially those that
|
||||
# call channel_factory without async_client re-init) do not inherit an invalid template.
|
||||
original_videos_destination = wrolpi_config.videos_destination
|
||||
|
||||
# Channel directory without a tag.
|
||||
wrolpi_config.videos_destination = 'videos/%(channel_tag)s/%(channel_name)s'
|
||||
assert format_videos_destination('Simple Channel', None, None) \
|
||||
== test_directory / 'videos/Simple Channel'
|
||||
try:
|
||||
# Channel directory without a tag.
|
||||
wrolpi_config.videos_destination = 'videos/%(channel_tag)s/%(channel_name)s'
|
||||
assert format_videos_destination('Simple Channel', None, None) \
|
||||
== test_directory / 'videos/Simple Channel'
|
||||
|
||||
# One tag can be applied to a Channel.
|
||||
assert format_videos_destination('Simple Channel', 'one', None) \
|
||||
== test_directory / 'videos/one/Simple Channel'
|
||||
# One tag can be applied to a Channel.
|
||||
assert format_videos_destination('Simple Channel', 'one', None) \
|
||||
== test_directory / 'videos/one/Simple Channel'
|
||||
|
||||
# Channel Domain is also supported.
|
||||
wrolpi_config.videos_destination = 'videos/%(channel_tag)s/%(channel_domain)s/%(channel_name)s'
|
||||
assert format_videos_destination('Simple Channel', 'one', 'https://example.com') \
|
||||
== test_directory / 'videos/one/example.com/Simple Channel'
|
||||
# Channel Domain is also supported.
|
||||
wrolpi_config.videos_destination = 'videos/%(channel_tag)s/%(channel_domain)s/%(channel_name)s'
|
||||
assert format_videos_destination('Simple Channel', 'one', 'https://example.com') \
|
||||
== test_directory / 'videos/one/example.com/Simple Channel'
|
||||
|
||||
# Channel name is not required.
|
||||
wrolpi_config.videos_destination = '%(channel_tag)s/%(channel_domain)s'
|
||||
assert format_videos_destination('Simple Channel', 'one', 'https://example.com') \
|
||||
== test_directory / 'one/example.com'
|
||||
# Channel name is not required.
|
||||
wrolpi_config.videos_destination = '%(channel_tag)s/%(channel_domain)s'
|
||||
assert format_videos_destination('Simple Channel', 'one', 'https://example.com') \
|
||||
== test_directory / 'one/example.com'
|
||||
|
||||
# Invalid `videos_destination` raises an error.
|
||||
wrolpi_config.videos_destination = '%(channel_tag)s/%(channel)s'
|
||||
with pytest.raises(FileNotFoundError):
|
||||
assert format_videos_destination()
|
||||
# Invalid `videos_destination` raises an error.
|
||||
wrolpi_config.videos_destination = '%(channel_tag)s/%(channel)s'
|
||||
with pytest.raises(FileNotFoundError):
|
||||
assert format_videos_destination()
|
||||
finally:
|
||||
wrolpi_config.videos_destination = original_videos_destination
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue