lib.itmens/catalog/movie/tests.py

118 lines
4.5 KiB
Python
Raw Normal View History

from django.test import TestCase
from catalog.common import *
class DoubanMovieTestCase(TestCase):
2024-07-13 00:16:47 -04:00
databases = "__all__"
def test_parse(self):
2022-12-29 23:57:02 -05:00
t_id = "3541415"
t_url = "https://movie.douban.com/subject/3541415/"
2023-06-05 10:06:16 -04:00
p1 = SiteManager.get_site_cls_by_id_type(IdType.DoubanMovie)
self.assertIsNotNone(p1)
self.assertEqual(p1.validate_url(t_url), True)
2022-12-15 17:29:35 -05:00
p2 = SiteManager.get_site_by_url(t_url)
self.assertEqual(p1.id_to_url(t_id), t_url)
self.assertEqual(p2.url_to_id(t_url), t_id)
@use_local_response
def test_scrape(self):
2022-12-29 23:57:02 -05:00
t_url = "https://movie.douban.com/subject/3541415/"
2022-12-15 17:29:35 -05:00
site = SiteManager.get_site_by_url(t_url)
self.assertEqual(site.ready, False)
2022-12-29 23:57:02 -05:00
self.assertEqual(site.id_value, "3541415")
2022-12-08 16:08:59 +00:00
site.get_resource_ready()
2022-12-29 23:57:02 -05:00
self.assertEqual(site.resource.metadata["title"], "盗梦空间")
2022-12-08 16:08:59 +00:00
self.assertEqual(site.resource.item.primary_lookup_id_type, IdType.IMDB)
2022-12-29 23:57:02 -05:00
self.assertEqual(site.resource.item.__class__.__name__, "Movie")
self.assertEqual(site.resource.item.imdb, "tt1375666")
class TMDBMovieTestCase(TestCase):
2024-07-13 00:16:47 -04:00
databases = "__all__"
def test_parse(self):
2022-12-29 23:57:02 -05:00
t_id = "293767"
t_url = (
"https://www.themoviedb.org/movie/293767-billy-lynn-s-long-halftime-walk"
)
t_url2 = "https://www.themoviedb.org/movie/293767"
2023-06-05 10:06:16 -04:00
p1 = SiteManager.get_site_cls_by_id_type(IdType.TMDB_Movie)
self.assertIsNotNone(p1)
self.assertEqual(p1.validate_url(t_url), True)
self.assertEqual(p1.validate_url(t_url2), True)
2022-12-15 17:29:35 -05:00
p2 = SiteManager.get_site_by_url(t_url)
self.assertEqual(p1.id_to_url(t_id), t_url2)
self.assertEqual(p2.url_to_id(t_url), t_id)
@use_local_response
def test_scrape(self):
2022-12-29 23:57:02 -05:00
t_url = "https://www.themoviedb.org/movie/293767"
2022-12-15 17:29:35 -05:00
site = SiteManager.get_site_by_url(t_url)
self.assertEqual(site.ready, False)
2022-12-29 23:57:02 -05:00
self.assertEqual(site.id_value, "293767")
2022-12-08 16:08:59 +00:00
site.get_resource_ready()
2024-07-13 00:16:47 -04:00
self.assertEqual(
site.resource.metadata["title"], "Billy Lynn's Long Halftime Walk"
)
2022-12-08 16:08:59 +00:00
self.assertEqual(site.resource.item.primary_lookup_id_type, IdType.IMDB)
2022-12-29 23:57:02 -05:00
self.assertEqual(site.resource.item.__class__.__name__, "Movie")
self.assertEqual(site.resource.item.imdb, "tt2513074")
class IMDBMovieTestCase(TestCase):
2024-07-13 00:16:47 -04:00
databases = "__all__"
def test_parse(self):
2022-12-29 23:57:02 -05:00
t_id = "tt1375666"
t_url = "https://www.imdb.com/title/tt1375666/"
t_url2 = "https://www.imdb.com/title/tt1375666/"
2023-06-05 10:06:16 -04:00
p1 = SiteManager.get_site_cls_by_id_type(IdType.IMDB)
self.assertIsNotNone(p1)
self.assertEqual(p1.validate_url(t_url), True)
self.assertEqual(p1.validate_url(t_url2), True)
2022-12-15 17:29:35 -05:00
p2 = SiteManager.get_site_by_url(t_url)
self.assertEqual(p1.id_to_url(t_id), t_url2)
self.assertEqual(p2.url_to_id(t_url), t_id)
@use_local_response
def test_scrape(self):
2022-12-29 23:57:02 -05:00
t_url = "https://www.imdb.com/title/tt1375666/"
2022-12-15 17:29:35 -05:00
site = SiteManager.get_site_by_url(t_url)
self.assertEqual(site.ready, False)
2022-12-29 23:57:02 -05:00
self.assertEqual(site.id_value, "tt1375666")
2022-12-08 16:08:59 +00:00
site.get_resource_ready()
2024-07-13 00:16:47 -04:00
self.assertEqual(site.resource.metadata["title"], "Inception")
2022-12-08 16:08:59 +00:00
self.assertEqual(site.resource.item.primary_lookup_id_type, IdType.IMDB)
2022-12-29 23:57:02 -05:00
self.assertEqual(site.resource.item.imdb, "tt1375666")
2023-10-31 04:29:28 -04:00
class BangumiMovieTestCase(TestCase):
2024-07-13 00:16:47 -04:00
databases = "__all__"
2023-10-31 04:29:28 -04:00
@use_local_response
def test_scrape(self):
url = "https://bgm.tv/subject/237"
site = SiteManager.get_site_by_url(url)
self.assertEqual(site.id_value, "237")
site.get_resource_ready()
2024-07-13 00:16:47 -04:00
self.assertEqual(site.resource.item.display_title, "GHOST IN THE SHELL")
2023-10-31 04:29:28 -04:00
self.assertEqual(site.resource.item.primary_lookup_id_type, IdType.IMDB)
self.assertEqual(site.resource.item.imdb, "tt0113568")
class MultiMovieSitesTestCase(TestCase):
2024-07-13 00:16:47 -04:00
databases = "__all__"
@use_local_response
def test_movies(self):
2022-12-29 23:57:02 -05:00
url1 = "https://www.themoviedb.org/movie/27205-inception"
url2 = "https://movie.douban.com/subject/3541415/"
url3 = "https://www.imdb.com/title/tt1375666/"
2022-12-15 17:29:35 -05:00
p1 = SiteManager.get_site_by_url(url1).get_resource_ready()
p2 = SiteManager.get_site_by_url(url2).get_resource_ready()
p3 = SiteManager.get_site_by_url(url3).get_resource_ready()
self.assertEqual(p1.item.id, p2.item.id)
self.assertEqual(p2.item.id, p3.item.id)