diff --git a/tests/conftest.py b/tests/conftest.py index 86ede664..5fa09faf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # standard imports from functools import partial import os @@ -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 diff --git a/tests/functional/test_plex_plugin.py b/tests/functional/test_plex_plugin.py index 8b6eccd6..43beb533 100644 --- a/tests/functional/test_plex_plugin.py +++ b/tests/functional/test_plex_plugin.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # standard imports import os diff --git a/tests/functional/test_webapp.py b/tests/functional/test_webapp.py index ba60cd19..1dda0acd 100644 --- a/tests/functional/test_webapp.py +++ b/tests/functional/test_webapp.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # lib imports import pytest diff --git a/tests/unit/test_code.py b/tests/unit/test_code.py index f0a8b03b..fc8f1f5b 100644 --- a/tests/unit/test_code.py +++ b/tests/unit/test_code.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # local imports import Code from Code import ValidatePrefs diff --git a/tests/unit/test_general_helper.py b/tests/unit/test_general_helper.py index 05d82b4f..5802d65b 100644 --- a/tests/unit/test_general_helper.py +++ b/tests/unit/test_general_helper.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # standard imports import os import shutil diff --git a/tests/unit/test_lizardbyte_db_helper.py b/tests/unit/test_lizardbyte_db_helper.py index dd59e11a..27d7c9dc 100644 --- a/tests/unit/test_lizardbyte_db_helper.py +++ b/tests/unit/test_lizardbyte_db_helper.py @@ -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(): diff --git a/tests/unit/test_scheduled_tasks.py b/tests/unit/test_scheduled_tasks.py index e735bb2b..fcbd162f 100644 --- a/tests/unit/test_scheduled_tasks.py +++ b/tests/unit/test_scheduled_tasks.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + # standard imports import time diff --git a/tests/unit/test_themerr_db_helper.py b/tests/unit/test_themerr_db_helper.py index 026a280e..c0672553 100644 --- a/tests/unit/test_themerr_db_helper.py +++ b/tests/unit/test_themerr_db_helper.py @@ -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] diff --git a/tests/unit/test_tmdb_helper.py b/tests/unit/test_tmdb_helper.py index 0fc0367c..c74d2948 100644 --- a/tests/unit/test_tmdb_helper.py +++ b/tests/unit/test_tmdb_helper.py @@ -1,22 +1,23 @@ # -*- 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(): @@ -24,16 +25,14 @@ def test_get_tmdb_id_from_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(): diff --git a/tests/unit/test_youtube_dl_helper.py b/tests/unit/test_youtube_dl_helper.py index 1486aacd..4a522d92 100644 --- a/tests/unit/test_youtube_dl_helper.py +++ b/tests/unit/test_youtube_dl_helper.py @@ -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