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

Commit

Permalink
test: improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Dec 11, 2023
1 parent 5b4ecc8 commit cb1eb41
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 67 deletions.
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

# standard imports
from functools import partial
import os
Expand All @@ -14,8 +15,10 @@
import requests

# add Contents directory to the system path
if os.path.isdir('Contents'):
sys.path.append('Contents')
pytest.root_dir = root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
pytest.contents_dir = contents_dir = os.path.join(root_dir, 'Contents')
if os.path.isdir(contents_dir):
sys.path.append(contents_dir)

# local imports
from Code import constants
Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_plex_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

# standard imports
import os

Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_webapp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

# lib imports
import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

# local imports
import Code
from Code import ValidatePrefs
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_general_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

# standard imports
import os
import shutil
Expand Down
43 changes: 15 additions & 28 deletions tests/unit/test_lizardbyte_db_helper.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
# -*- coding: utf-8 -*-

# lib imports
import pytest

# local imports
from Code import lizardbyte_db_helper


def test_get_igdb_id_from_collection():
tests = [
{
'search_query': 'James Bond',
'collection_type': 'game_collections',
'expected_type': 'game_collections',
'expected_id': 326,
},
{
'search_query': 'James Bond',
'collection_type': 'game_franchises',
'expected_type': 'game_franchises',
'expected_id': 37,
},
{
'search_query': 'James Bond',
'collection_type': None,
'expected_type': 'game_collections',
'expected_id': 326,
},
]

for test in tests:
igdb_id = lizardbyte_db_helper.get_igdb_id_from_collection(
search_query=test['search_query'],
collection_type=test['collection_type']
)
assert igdb_id == (test['expected_id'], test['expected_type'])
@pytest.mark.parametrize('search_query, collection_type, expected_type, expected_id', [
('James Bond', 'game_collections', 'game_collections', 326),
('James Bond', 'game_franchises', 'game_franchises', 37),
('James Bond', None, 'game_collections', 326),
])
def test_get_igdb_id_from_collection(search_query, collection_type, expected_type, expected_id):
igdb_id = lizardbyte_db_helper.get_igdb_id_from_collection(
search_query=search_query,
collection_type=collection_type
)
assert igdb_id == (expected_id, expected_type)


def test_get_igdb_id_from_collection_invalid():
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_scheduled_tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

# standard imports
import time

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_themerr_db_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def test_update_cache(empty_themerr_db_cache):


def test_item_exists(empty_themerr_db_cache, movies):
items = movies.all()
for item in items:
for item in movies.all():
database_info = plex_api_helper.get_database_info(item=item)

database_type = database_info[0]
Expand Down
35 changes: 17 additions & 18 deletions tests/unit/test_tmdb_helper.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
# -*- coding: utf-8 -*-

# lib imports
import plexhints
import pytest

# local imports
from Code import tmdb_helper


def test_get_tmdb_id_from_imdb_id():
@pytest.mark.parametrize('tmdb_test_id', [
'tt1254207',
])
def test_get_tmdb_id_from_imdb_id(tmdb_test_id):
print(plexhints.CONTENTS)
print(plexhints.ELEVATED_POLICY)
tests = [
'tt1254207'
]

for test in tests:
tmdb_id = tmdb_helper.get_tmdb_id_from_imdb_id(imdb_id=test)
assert tmdb_id, "No tmdb_id found for {}".format(test)
assert isinstance(tmdb_id, int), "tmdb_id is not an int: {}".format(tmdb_id)
tmdb_id = tmdb_helper.get_tmdb_id_from_imdb_id(imdb_id=tmdb_test_id)
assert tmdb_id, "No tmdb_id found for {}".format(tmdb_test_id)
assert isinstance(tmdb_id, int), "tmdb_id is not an int: {}".format(tmdb_id)


def test_get_tmdb_id_from_imdb_id_invalid():
test = tmdb_helper.get_tmdb_id_from_imdb_id(imdb_id='invalid')
assert test is None, "tmdb_id found for invalid imdb_id: {}".format(test)


def test_get_tmdb_id_from_collection():
tests = [
'James Bond',
'James Bond Collection',
]

for test in tests:
tmdb_id = tmdb_helper.get_tmdb_id_from_collection(search_query=test)
assert tmdb_id, "No tmdb_id found for {}".format(test)
assert isinstance(tmdb_id, int), "tmdb_id is not an int: {}".format(tmdb_id)
@pytest.mark.parametrize('tmdb_test_collection', [
'James Bond',
'James Bond Collection',
])
def test_get_tmdb_id_from_collection(tmdb_test_collection):
tmdb_id = tmdb_helper.get_tmdb_id_from_collection(search_query=tmdb_test_collection)
assert tmdb_id, "No tmdb_id found for {}".format(tmdb_test_collection)
assert isinstance(tmdb_id, int), "tmdb_id is not an int: {}".format(tmdb_id)


def test_get_tmdb_id_from_collection_invalid():
Expand Down
36 changes: 19 additions & 17 deletions tests/unit/test_youtube_dl_helper.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# -*- coding: utf-8 -*-

# lib imports
import pytest

# local imports
from Code import youtube_dl_helper


def test_process_youtube():
@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
])
def test_process_youtube(url):
# test valid urls
valid_urls = [
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
'https://www.youtube.com/watch?v=Wb8j8Ojd4YQ&list=PLMYr5_xSeuXAbhxYHz86hA1eCDugoxXY0&pp=iAQB', # playlist test
]
for url in valid_urls:
audio_url = youtube_dl_helper.process_youtube(url=url)
assert audio_url is not None
assert audio_url.startswith('https://')
audio_url = youtube_dl_helper.process_youtube(url=url)
assert audio_url is not None
assert audio_url.startswith('https://')


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

0 comments on commit cb1eb41

Please sign in to comment.