Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
tests: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Jul 26, 2024
1 parent c948caa commit a19ca39
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def wait_for_themes(section):
timer = 0
with_themes = 0
total = len(section.all())
while timer < 180 and with_themes < total:
while timer < 600 and with_themes < total:
with_themes = 0
try:
for item in section.all():
Expand Down
48 changes: 32 additions & 16 deletions tests/unit/test_youtube_dl_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,43 @@

# lib imports
import pytest
import requests

# local imports
from Code import youtube_dl_helper

gh_url_prefix = 'https://raw.githubusercontent.com/LizardByte/ThemerrDB/gh-pages'

@pytest.mark.parametrize('url', [
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
'https://www.youtube.com/watch?v=Wb8j8Ojd4YQ&list=PLMYr5_xSeuXAbhxYHz86hA1eCDugoxXY0&pp=iAQB', # playlist test

# standard items setup by plexhints action
@pytest.fixture(scope='module', params=[
('https://www.youtube.com/watch?v=dQw4w9WgXcQ', True),
('https://www.youtube.com/watch?v=Wb8j8Ojd4YQ&list=PLMYr5_xSeuXAbhxYHz86hA1eCDugoxXY0&pp=iAQB', True), # playlist
('{}/movies/themoviedb/9761.json'.format(gh_url_prefix), True), # Elephants Dream
('{}/movies/themoviedb/20529.json'.format(gh_url_prefix), True), # Sita Sings the Blues
('{}/movies/themoviedb/10378.json'.format(gh_url_prefix), True), # Big Buck Bunny
('{}/movies/themoviedb/45745.json'.format(gh_url_prefix), True), # Sintel
('{}/tv_shows/themoviedb/1399.json'.format(gh_url_prefix), True), # Game of Thrones
('{}/tv_shows/themoviedb/48866.json'.format(gh_url_prefix), True), # The 100
('https://www.youtube.com/watch?v=notavideoid', False), # invalid A
('https://blahblahblah', False), # invalid B
])
def test_process_youtube(url):
# test valid urls
audio_url = youtube_dl_helper.process_youtube(url=url)
assert audio_url is not None
assert audio_url.startswith('https://')
def youtube_url(request):
if "youtube.com" in request.param:

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High test

The string
youtube.com
may be at an arbitrary position in the sanitized URL.
return request.param

# get the youtube_theme_url key from the json data
response = requests.get(request.param)
assert response.status_code == 200
data = response.json()
return data['youtube_theme_url']

@pytest.mark.parametrize('url', [
'https://www.youtube.com/watch?v=notavideoid',
'https://blahblahblah',
])
def test_process_youtube_invalid(url):
# test invalid urls
audio_url = youtube_dl_helper.process_youtube(url=url)
assert audio_url is None

def test_process_youtube(youtube_url):
# test valid urls
audio_url = youtube_dl_helper.process_youtube(url=youtube_url[0])
if youtube_url[1]:
assert audio_url is not None
assert audio_url.startswith('https://')
else:
assert audio_url is None

0 comments on commit a19ca39

Please sign in to comment.