Updating tests to match searching for Channel and Domain names for directories.

This commit is contained in:
Roland 2023-05-03 12:59:47 -06:00
parent 2cbc6e00e0
commit 8de805b6d1
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
4 changed files with 30 additions and 13 deletions

View file

@ -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()

View file

@ -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

View file

@ -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."""

View file

@ -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):