Add tests for black_white and watched

This commit is contained in:
Luigi311
2023-03-08 22:01:44 -07:00
parent 1ee055faf5
commit b2a06b8fd3
2 changed files with 488 additions and 301 deletions

78
test/test_black_white.py Normal file
View File

@@ -0,0 +1,78 @@
import sys
import os
# getting the name of the directory
# where the this file is present.
current = os.path.dirname(os.path.realpath(__file__))
# Getting the parent directory name
# where the current directory is present.
parent = os.path.dirname(current)
# adding the parent directory to
# the sys.path.
sys.path.append(parent)
from src.black_white import setup_black_white_lists
def test_setup_black_white_lists():
# Simple
blacklist_library = "library1, library2"
whitelist_library = "library1, library2"
blacklist_library_type = "library_type1, library_type2"
whitelist_library_type = "library_type1, library_type2"
blacklist_users = "user1, user2"
whitelist_users = "user1, user2"
(
results_blacklist_library,
return_whitelist_library,
return_blacklist_library_type,
return_whitelist_library_type,
return_blacklist_users,
return_whitelist_users,
) = setup_black_white_lists(
blacklist_library,
whitelist_library,
blacklist_library_type,
whitelist_library_type,
blacklist_users,
whitelist_users,
)
assert results_blacklist_library == ["library1", "library2"]
assert return_whitelist_library == ["library1", "library2"]
assert return_blacklist_library_type == ["library_type1", "library_type2"]
assert return_whitelist_library_type == ["library_type1", "library_type2"]
assert return_blacklist_users == ["user1", "user2"]
assert return_whitelist_users == ["user1", "user2"]
# Library Mapping and user mapping
library_mapping = {"library1": "library3"}
user_mapping = {"user1": "user3"}
(
results_blacklist_library,
return_whitelist_library,
return_blacklist_library_type,
return_whitelist_library_type,
return_blacklist_users,
return_whitelist_users,
) = setup_black_white_lists(
blacklist_library,
whitelist_library,
blacklist_library_type,
whitelist_library_type,
blacklist_users,
whitelist_users,
library_mapping,
user_mapping,
)
assert results_blacklist_library == ["library1", "library2", "library3"]
assert return_whitelist_library == ["library1", "library2", "library3"]
assert return_blacklist_library_type == ["library_type1", "library_type2"]
assert return_whitelist_library_type == ["library_type1", "library_type2"]
assert return_blacklist_users == ["user1", "user2", "user3"]
assert return_whitelist_users == ["user1", "user2", "user3"]

View File

@@ -1,301 +1,410 @@
import sys import sys
import os import os
# getting the name of the directory # getting the name of the directory
# where the this file is present. # where the this file is present.
current = os.path.dirname(os.path.realpath(__file__)) current = os.path.dirname(os.path.realpath(__file__))
# Getting the parent directory name # Getting the parent directory name
# where the current directory is present. # where the current directory is present.
parent = os.path.dirname(current) parent = os.path.dirname(current)
# adding the parent directory to # adding the parent directory to
# the sys.path. # the sys.path.
sys.path.append(parent) sys.path.append(parent)
from src.main import cleanup_watched from src.watched import cleanup_watched, combine_watched_dicts
tv_shows_watched_list_1 = { tv_shows_watched_list_1 = {
frozenset( frozenset(
{ {
("tvdb", "75710"), ("tvdb", "75710"),
("title", "Criminal Minds"), ("title", "Criminal Minds"),
("imdb", "tt0452046"), ("imdb", "tt0452046"),
("locations", ("Criminal Minds",)), ("locations", ("Criminal Minds",)),
("tmdb", "4057"), ("tmdb", "4057"),
} }
): { ): {
"Season 1": [ "Season 1": [
{ {
"imdb": "tt0550489", "imdb": "tt0550489",
"tmdb": "282843", "tmdb": "282843",
"tvdb": "176357", "tvdb": "176357",
"locations": ( "locations": (
"Criminal Minds S01E01 Extreme Aggressor WEBDL-720p.mkv", "Criminal Minds S01E01 Extreme Aggressor WEBDL-720p.mkv",
), ),
}, },
{ {
"imdb": "tt0550487", "imdb": "tt0550487",
"tmdb": "282861", "tmdb": "282861",
"tvdb": "300385", "tvdb": "300385",
"locations": ("Criminal Minds S01E02 Compulsion WEBDL-720p.mkv",), "locations": ("Criminal Minds S01E02 Compulsion WEBDL-720p.mkv",),
}, },
] ]
}, },
frozenset({("title", "Test"), ("locations", ("Test",))}): { frozenset({("title", "Test"), ("locations", ("Test",))}): {
"Season 1": [ "Season 1": [
{"locations": ("Test S01E01.mkv",)}, {"locations": ("Test S01E01.mkv",)},
{"locations": ("Test S01E02.mkv",)}, {"locations": ("Test S01E02.mkv",)},
] ]
}, },
} }
movies_watched_list_1 = [ movies_watched_list_1 = [
{ {
"imdb": "tt2380307", "imdb": "tt2380307",
"tmdb": "354912", "tmdb": "354912",
"title": "Coco", "title": "Coco",
"locations": ("Coco (2017) Remux-1080p.mkv",), "locations": ("Coco (2017) Remux-1080p.mkv",),
}, },
{ {
"tmdbcollection": "448150", "tmdbcollection": "448150",
"imdb": "tt1431045", "imdb": "tt1431045",
"tmdb": "293660", "tmdb": "293660",
"title": "Deadpool", "title": "Deadpool",
"locations": ("Deadpool (2016) Remux-1080p.mkv",), "locations": ("Deadpool (2016) Remux-1080p.mkv",),
}, },
] ]
tv_shows_watched_list_2 = { tv_shows_watched_list_2 = {
frozenset( frozenset(
{ {
("tvdb", "75710"), ("tvdb", "75710"),
("title", "Criminal Minds"), ("title", "Criminal Minds"),
("imdb", "tt0452046"), ("imdb", "tt0452046"),
("locations", ("Criminal Minds",)), ("locations", ("Criminal Minds",)),
("tmdb", "4057"), ("tmdb", "4057"),
} }
): { ): {
"Season 1": [ "Season 1": [
{ {
"imdb": "tt0550487", "imdb": "tt0550487",
"tmdb": "282861", "tmdb": "282861",
"tvdb": "300385", "tvdb": "300385",
"locations": ("Criminal Minds S01E02 Compulsion WEBDL-720p.mkv",), "locations": ("Criminal Minds S01E02 Compulsion WEBDL-720p.mkv",),
}, },
{ {
"imdb": "tt0550498", "imdb": "tt0550498",
"tmdb": "282865", "tmdb": "282865",
"tvdb": "300474", "tvdb": "300474",
"locations": ( "locations": (
"Criminal Minds S01E03 Won't Get Fooled Again WEBDL-720p.mkv", "Criminal Minds S01E03 Won't Get Fooled Again WEBDL-720p.mkv",
), ),
}, },
] ]
}, },
frozenset({("title", "Test"), ("locations", ("Test",))}): { frozenset({("title", "Test"), ("locations", ("Test",))}): {
"Season 1": [ "Season 1": [
{"locations": ("Test S01E02.mkv",)}, {"locations": ("Test S01E02.mkv",)},
{"locations": ("Test S01E03.mkv",)}, {"locations": ("Test S01E03.mkv",)},
] ]
}, },
} }
movies_watched_list_2 = [ movies_watched_list_2 = [
{ {
"imdb": "tt2380307", "imdb": "tt2380307",
"tmdb": "354912", "tmdb": "354912",
"title": "Coco", "title": "Coco",
"locations": ("Coco (2017) Remux-1080p.mkv",), "locations": ("Coco (2017) Remux-1080p.mkv",),
}, },
{ {
"imdb": "tt0384793", "imdb": "tt0384793",
"tmdb": "9788", "tmdb": "9788",
"tvdb": "9103", "tvdb": "9103",
"title": "Accepted", "title": "Accepted",
"locations": ("Accepted (2006) Remux-1080p.mkv",), "locations": ("Accepted (2006) Remux-1080p.mkv",),
}, },
] ]
# Test to see if objects get deleted all the way up to the root. # Test to see if objects get deleted all the way up to the root.
tv_shows_2_watched_list_1 = { tv_shows_2_watched_list_1 = {
frozenset( frozenset(
{ {
("tvdb", "75710"), ("tvdb", "75710"),
("title", "Criminal Minds"), ("title", "Criminal Minds"),
("imdb", "tt0452046"), ("imdb", "tt0452046"),
("locations", ("Criminal Minds",)), ("locations", ("Criminal Minds",)),
("tmdb", "4057"), ("tmdb", "4057"),
} }
): { ): {
"Season 1": [ "Season 1": [
{ {
"imdb": "tt0550489", "imdb": "tt0550489",
"tmdb": "282843", "tmdb": "282843",
"tvdb": "176357", "tvdb": "176357",
"locations": ( "locations": (
"Criminal Minds S01E01 Extreme Aggressor WEBDL-720p.mkv", "Criminal Minds S01E01 Extreme Aggressor WEBDL-720p.mkv",
), ),
}, },
] ]
} }
} }
expected_tv_show_watched_list_1 = { expected_tv_show_watched_list_1 = {
frozenset( frozenset(
{ {
("tvdb", "75710"), ("tvdb", "75710"),
("title", "Criminal Minds"), ("title", "Criminal Minds"),
("imdb", "tt0452046"), ("imdb", "tt0452046"),
("locations", ("Criminal Minds",)), ("locations", ("Criminal Minds",)),
("tmdb", "4057"), ("tmdb", "4057"),
} }
): { ): {
"Season 1": [ "Season 1": [
{ {
"imdb": "tt0550489", "imdb": "tt0550489",
"tmdb": "282843", "tmdb": "282843",
"tvdb": "176357", "tvdb": "176357",
"locations": ( "locations": (
"Criminal Minds S01E01 Extreme Aggressor WEBDL-720p.mkv", "Criminal Minds S01E01 Extreme Aggressor WEBDL-720p.mkv",
), ),
} }
] ]
}, },
frozenset({("title", "Test"), ("locations", ("Test",))}): { frozenset({("title", "Test"), ("locations", ("Test",))}): {
"Season 1": [{"locations": ("Test S01E01.mkv",)}] "Season 1": [{"locations": ("Test S01E01.mkv",)}]
}, },
} }
expected_movie_watched_list_1 = [ expected_movie_watched_list_1 = [
{ {
"tmdbcollection": "448150", "tmdbcollection": "448150",
"imdb": "tt1431045", "imdb": "tt1431045",
"tmdb": "293660", "tmdb": "293660",
"title": "Deadpool", "title": "Deadpool",
"locations": ("Deadpool (2016) Remux-1080p.mkv",), "locations": ("Deadpool (2016) Remux-1080p.mkv",),
} }
] ]
expected_tv_show_watched_list_2 = { expected_tv_show_watched_list_2 = {
frozenset( frozenset(
{ {
("tvdb", "75710"), ("tvdb", "75710"),
("title", "Criminal Minds"), ("title", "Criminal Minds"),
("imdb", "tt0452046"), ("imdb", "tt0452046"),
("locations", ("Criminal Minds",)), ("locations", ("Criminal Minds",)),
("tmdb", "4057"), ("tmdb", "4057"),
} }
): { ): {
"Season 1": [ "Season 1": [
{ {
"imdb": "tt0550498", "imdb": "tt0550498",
"tmdb": "282865", "tmdb": "282865",
"tvdb": "300474", "tvdb": "300474",
"locations": ( "locations": (
"Criminal Minds S01E03 Won't Get Fooled Again WEBDL-720p.mkv", "Criminal Minds S01E03 Won't Get Fooled Again WEBDL-720p.mkv",
), ),
} }
] ]
}, },
frozenset({("title", "Test"), ("locations", ("Test",))}): { frozenset({("title", "Test"), ("locations", ("Test",))}): {
"Season 1": [{"locations": ("Test S01E03.mkv",)}] "Season 1": [{"locations": ("Test S01E03.mkv",)}]
}, },
} }
expected_movie_watched_list_2 = [ expected_movie_watched_list_2 = [
{ {
"imdb": "tt0384793", "imdb": "tt0384793",
"tmdb": "9788", "tmdb": "9788",
"tvdb": "9103", "tvdb": "9103",
"title": "Accepted", "title": "Accepted",
"locations": ("Accepted (2006) Remux-1080p.mkv",), "locations": ("Accepted (2006) Remux-1080p.mkv",),
} }
] ]
def test_simple_cleanup_watched(): def test_simple_cleanup_watched():
user_watched_list_1 = { user_watched_list_1 = {
"user1": { "user1": {
"TV Shows": tv_shows_watched_list_1, "TV Shows": tv_shows_watched_list_1,
"Movies": movies_watched_list_1, "Movies": movies_watched_list_1,
"Other Shows": tv_shows_2_watched_list_1, "Other Shows": tv_shows_2_watched_list_1,
}, },
} }
user_watched_list_2 = { user_watched_list_2 = {
"user1": { "user1": {
"TV Shows": tv_shows_watched_list_2, "TV Shows": tv_shows_watched_list_2,
"Movies": movies_watched_list_2, "Movies": movies_watched_list_2,
"Other Shows": tv_shows_2_watched_list_1, "Other Shows": tv_shows_2_watched_list_1,
} }
} }
expected_watched_list_1 = { expected_watched_list_1 = {
"user1": { "user1": {
"TV Shows": expected_tv_show_watched_list_1, "TV Shows": expected_tv_show_watched_list_1,
"Movies": expected_movie_watched_list_1, "Movies": expected_movie_watched_list_1,
} }
} }
expected_watched_list_2 = { expected_watched_list_2 = {
"user1": { "user1": {
"TV Shows": expected_tv_show_watched_list_2, "TV Shows": expected_tv_show_watched_list_2,
"Movies": expected_movie_watched_list_2, "Movies": expected_movie_watched_list_2,
} }
} }
return_watched_list_1 = cleanup_watched(user_watched_list_1, user_watched_list_2) return_watched_list_1 = cleanup_watched(user_watched_list_1, user_watched_list_2)
return_watched_list_2 = cleanup_watched(user_watched_list_2, user_watched_list_1) return_watched_list_2 = cleanup_watched(user_watched_list_2, user_watched_list_1)
assert return_watched_list_1 == expected_watched_list_1 assert return_watched_list_1 == expected_watched_list_1
assert return_watched_list_2 == expected_watched_list_2 assert return_watched_list_2 == expected_watched_list_2
def test_mapping_cleanup_watched(): def test_mapping_cleanup_watched():
user_watched_list_1 = { user_watched_list_1 = {
"user1": { "user1": {
"TV Shows": tv_shows_watched_list_1, "TV Shows": tv_shows_watched_list_1,
"Movies": movies_watched_list_1, "Movies": movies_watched_list_1,
"Other Shows": tv_shows_2_watched_list_1, "Other Shows": tv_shows_2_watched_list_1,
}, },
} }
user_watched_list_2 = { user_watched_list_2 = {
"user2": { "user2": {
"Shows": tv_shows_watched_list_2, "Shows": tv_shows_watched_list_2,
"Movies": movies_watched_list_2, "Movies": movies_watched_list_2,
"Other Shows": tv_shows_2_watched_list_1, "Other Shows": tv_shows_2_watched_list_1,
} }
} }
expected_watched_list_1 = { expected_watched_list_1 = {
"user1": { "user1": {
"TV Shows": expected_tv_show_watched_list_1, "TV Shows": expected_tv_show_watched_list_1,
"Movies": expected_movie_watched_list_1, "Movies": expected_movie_watched_list_1,
} }
} }
expected_watched_list_2 = { expected_watched_list_2 = {
"user2": { "user2": {
"Shows": expected_tv_show_watched_list_2, "Shows": expected_tv_show_watched_list_2,
"Movies": expected_movie_watched_list_2, "Movies": expected_movie_watched_list_2,
} }
} }
user_mapping = {"user1": "user2"} user_mapping = {"user1": "user2"}
library_mapping = {"TV Shows": "Shows"} library_mapping = {"TV Shows": "Shows"}
return_watched_list_1 = cleanup_watched( return_watched_list_1 = cleanup_watched(
user_watched_list_1, user_watched_list_1,
user_watched_list_2, user_watched_list_2,
user_mapping=user_mapping, user_mapping=user_mapping,
library_mapping=library_mapping, library_mapping=library_mapping,
) )
return_watched_list_2 = cleanup_watched( return_watched_list_2 = cleanup_watched(
user_watched_list_2, user_watched_list_2,
user_watched_list_1, user_watched_list_1,
user_mapping=user_mapping, user_mapping=user_mapping,
library_mapping=library_mapping, library_mapping=library_mapping,
) )
assert return_watched_list_1 == expected_watched_list_1 assert return_watched_list_1 == expected_watched_list_1
assert return_watched_list_2 == expected_watched_list_2 assert return_watched_list_2 == expected_watched_list_2
def test_combine_watched_dicts():
input = [
{
"test3": {
"Anime Movies": [
{
"title": "Ponyo",
"tmdb": "12429",
"imdb": "tt0876563",
"locations": ("Ponyo (2008) Bluray-1080p.mkv",),
},
{
"title": "Spirited Away",
"tmdb": "129",
"imdb": "tt0245429",
"locations": ("Spirited Away (2001) Bluray-1080p.mkv",),
},
{
"title": "Castle in the Sky",
"tmdb": "10515",
"imdb": "tt0092067",
"locations": ("Castle in the Sky (1986) Bluray-1080p.mkv",),
},
]
}
},
{"test3": {"Anime Shows": {}}},
{"test3": {"Cartoon Shows": {}}},
{
"test3": {
"Shows": {
frozenset(
{
("tmdb", "64464"),
("tvdb", "301824"),
("tvrage", "45210"),
("title", "11.22.63"),
("locations", ("11.22.63",)),
("imdb", "tt2879552"),
}
): {
"Season 1": [
{
"imdb": "tt4460418",
"title": "The Rabbit Hole",
"locations": (
"11.22.63 S01E01 The Rabbit Hole Bluray-1080p.mkv",
),
}
]
}
}
}
},
{"test3": {"Subbed Anime": {}}},
]
expected = {
"test3": {
"Anime Movies": [
{
"title": "Ponyo",
"tmdb": "12429",
"imdb": "tt0876563",
"locations": ("Ponyo (2008) Bluray-1080p.mkv",),
},
{
"title": "Spirited Away",
"tmdb": "129",
"imdb": "tt0245429",
"locations": ("Spirited Away (2001) Bluray-1080p.mkv",),
},
{
"title": "Castle in the Sky",
"tmdb": "10515",
"imdb": "tt0092067",
"locations": ("Castle in the Sky (1986) Bluray-1080p.mkv",),
},
],
"Anime Shows": {},
"Cartoon Shows": {},
"Shows": {
frozenset(
{
("tmdb", "64464"),
("tvdb", "301824"),
("tvrage", "45210"),
("title", "11.22.63"),
("locations", ("11.22.63",)),
("imdb", "tt2879552"),
}
): {
"Season 1": [
{
"imdb": "tt4460418",
"title": "The Rabbit Hole",
"locations": (
"11.22.63 S01E01 The Rabbit Hole Bluray-1080p.mkv",
),
}
]
}
},
"Subbed Anime": {},
}
}
assert combine_watched_dicts(input) == expected