From 8de805b6d1ab77ebaf5ffd487f23f65c73448a89 Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 3 May 2023 12:59:47 -0600 Subject: [PATCH] Updating tests to match searching for Channel and Domain names for directories. --- modules/archive/lib.py | 2 +- modules/videos/models.py | 12 ++++++------ wrolpi/files/models.py | 4 ++-- wrolpi/files/test/test_api.py | 25 +++++++++++++++++++++---- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/modules/archive/lib.py b/modules/archive/lib.py index 494beed7..54b66adf 100644 --- a/modules/archive/lib.py +++ b/modules/archive/lib.py @@ -446,7 +446,7 @@ def search_archives(search_str: str, domain: str, limit: int, offset: int, order @optional_session def search_domains_by_directory(name: str, limit: int = 5, session: Session = None) -> List[Domain]: domains = session.query(Domain) \ - .filter(Domain.directory.ilike(f'%{name}%')) \ + .filter(Domain.domain.ilike(f'%{name}%')) \ .order_by(asc(Domain.domain)) \ .limit(limit) \ .all() diff --git a/modules/videos/models.py b/modules/videos/models.py index e827045b..42161d4c 100644 --- a/modules/videos/models.py +++ b/modules/videos/models.py @@ -247,7 +247,7 @@ class Video(ModelHelper, Base): @property def caption_files(self) -> List[dict]: - return self.file_group.my_files('text/srt') + self.file_group.my_files('text/vtt') + return self.file_group.my_files('text/vtt') + self.file_group.my_files('text/srt') @property def caption_paths(self) -> List[pathlib.Path]: @@ -258,14 +258,14 @@ class Video(ModelHelper, Base): caption_paths = self.caption_paths # Some SRT files are more supported than others, these are their preferred order. caption_text = None - if english_srt := [i for i in caption_paths if i.name.endswith('.en.srt')]: - caption_text = read_captions(english_srt[0]) - elif srt := [i for i in caption_paths if i.name.endswith('.srt')]: - caption_text = read_captions(srt[0]) - elif english_vtt := [i for i in caption_paths if i.name.endswith('.en.vtt')]: + if english_vtt := [i for i in caption_paths if i.name.endswith('.en.vtt')]: caption_text = read_captions(english_vtt[0]) elif vtt := [i for i in caption_paths if i.name.endswith('.vtt')]: caption_text = read_captions(vtt[0]) + elif english_srt := [i for i in caption_paths if i.name.endswith('.en.srt')]: + caption_text = read_captions(english_srt[0]) + elif srt := [i for i in caption_paths if i.name.endswith('.srt')]: + caption_text = read_captions(srt[0]) return caption_text diff --git a/wrolpi/files/models.py b/wrolpi/files/models.py index 1269eac3..26b62a19 100644 --- a/wrolpi/files/models.py +++ b/wrolpi/files/models.py @@ -175,8 +175,8 @@ class FileGroup(ModelHelper, Base): return self.my_files('image/') def my_subtitle_files(self) -> List[dict]: - """Return all my Files that have text/srt or text/vtt mimetype.""" - return self.my_files('text/srt', 'text/vtt') + """Return all my Files that have text/vtt or text/srt mimetype.""" + return self.my_files('text/vtt', 'text/srt') def my_text_files(self) -> List[dict]: """Return all my Files that have a text mimetype. But, do not include subtitle files.""" diff --git a/wrolpi/files/test/test_api.py b/wrolpi/files/test/test_api.py index b240610a..01cf214f 100644 --- a/wrolpi/files/test/test_api.py +++ b/wrolpi/files/test/test_api.py @@ -364,10 +364,27 @@ def test_post_search_directories(test_session, test_client, make_files_structure content = {'name': 'di'} request, response = test_client.post('/api/files/search_directories', content=json.dumps(content)) assert response.status_code == HTTPStatus.OK - # All directories contain "di", but directories filters out the Channel and Domain directories. - assert response.json['directories'] == [{'name': 'dir3', 'path': 'dir3'}, {'name': 'dir4', 'path': 'dir4'}] - assert response.json['channel_directories'] == [{'name': 'Channel Name', 'path': 'dir1'}, ] - assert response.json['domain_directories'] == [{'domain': 'example.com', 'path': 'dir2'}, ] + # All directories contain "di". The names of the Channel and Directory do not match. + assert response.json['directories'] == [{'name': 'dir1', 'path': 'dir1'}, {'name': 'dir2', 'path': 'dir2'}, + {'name': 'dir3', 'path': 'dir3'}, {'name': 'dir4', 'path': 'dir4'}] + assert response.json['channel_directories'] == [] + assert response.json['domain_directories'] == [] + + content = {'name': 'Chan'} + request, response = test_client.post('/api/files/search_directories', content=json.dumps(content)) + assert response.status_code == HTTPStatus.OK + # Channel name matches. + assert response.json['directories'] == [] + assert response.json['channel_directories'] == [{'name': 'Channel Name', 'path': 'dir1'}] + assert response.json['domain_directories'] == [] + + content = {'name': 'exam'} + request, response = test_client.post('/api/files/search_directories', content=json.dumps(content)) + assert response.status_code == HTTPStatus.OK + # Domain name matches. + assert response.json['directories'] == [] + assert response.json['channel_directories'] == [] + assert response.json['domain_directories'] == [{'domain': 'example.com', 'path': 'dir2'}] def test_post_upload_directory(test_session, test_client, test_directory, make_files_structure, make_multipart_form):