def test_add_roles_to_person_by_movie_titles(self, movie_kwargs1, movie_kwargs2): movie1 = MovieFactory(**movie_kwargs1) movie2 = MovieFactory(**movie_kwargs2) kp_person = KinopoiskPersonFactory(id=9843) # Dennis Hopper kp_person.sync_career() self.assert_dennis_hopper_career(kp_person, movie1, movie2)
def test_search_and_sync_right_movie_by_person(self, search_movie): movie1 = MovieFactory(year=2014, title_en='The Prince') movie2 = MovieFactory(year=2014, title_en='The Prince') ImdbPersonFactory(id=2357819, person=CastFactory(movie=movie1).person) ImdbPersonFactory(id=3167230, person=CastFactory(movie=movie2).person) sync_movie(movie1.id) sync_movie(movie2.id) self.assertEqual(movie1.imdb.id, 1085492) self.assertEqual(movie2.imdb.id, 3505782) self.assertFalse(search_movie.called)
def test_movie(self): m = MovieFactory() self.assertGreater(len(m.title), 0) self.assertIsNotNone(m.year) self.assertGreater(m.genres.count(), 0) self.assertGreater(m.countries.count(), 0) self.assertGreater(m.languages.count(), 0)
def test_movie_with_cast(self): m = MovieFactory() for i in range(100): cast = CastFactory(movie=m) CastFactory(role=cast.role) query = ''' query Movie($id: ID!, $role: ID!) { movie(id: $id) { id cast(role: $role) { edges { node { name person { firstNameEn, lastNameEn } role { nameEn } } } } } } ''' with self.assertNumQueries(3): result = self.execute( query, dict(id=global_id(m), role=global_id(cast.role))) self.assertEqual(len(result['movie']['cast']['edges']), m.cast.filter(role=cast.role).count())
def test_movie_with_cast(self): movie = MovieFactory() movie.cast.add(CastFactory()) movie.cast.add(CastFactory()) self.assertEqual(Person.objects.count(), 2) self.assertEqual(Cast.objects.count(), 2) self.assertEqual(movie.cast.count(), 2)
def test_search_and_sync_movie_matrix(self): movie = MovieFactory(year=1999, title_en='The Matrix', genres=[], languages=[], countries=[]) sync_movie(movie.id) self.assert_matrix(movie.imdb)
def test_sync_person_movies_with_the_same_title(self): # person has 2 movies "The Conversation" 1974 and 1995 movie1 = MovieFactory(title_en='The Conversation', year=1974) imdb_person = ImdbPersonFactory(id=338) CastFactory(movie=movie1, person=imdb_person.person, role=self.producer) sync_person(imdb_person.person.id, roles='all') self.assertTrue( imdb_person.person.career.get(role=self.producer, movie=movie1, movie__imdb__id=71360)) self.assertTrue( imdb_person.person.career.get(role=self.producer, movie__imdb__id=8041860))
def test_movie_without_related_sites(self): m = MovieFactory() query = ''' query Movie($id: ID!) { movie(id: $id) { id imdb { id, rating, votes } kinopoisk { id, rating, votes, info } } } ''' with self.assertNumQueries(1): result = self.execute(query, dict(id=global_id(m))) self.assertEqual(result['movie']['imdb'], None) self.assertEqual(result['movie']['kinopoisk'], None)
def test_movie_with_related_movie(self): m = MovieFactory(prequel_for=MovieFactory(), sequel_for=MovieFactory(), remake_for=MovieFactory()) m_id = global_id(m) prequel_id = global_id(m.prequel_for) sequel_id = global_id(m.sequel_for) remake_id = global_id(m.remake_for) query = ''' query Movie($id: ID!) { movie(id: $id) { id, year prequelFor { id, year } sequelFor { id, year } remakeFor { id, year } } } ''' with self.assertNumQueries(1): result = self.execute(query, dict(id=m_id)) self.assertEqual(result['movie']['id'], m_id) self.assertEqual(result['movie']['prequelFor']['id'], prequel_id) self.assertEqual(result['movie']['sequelFor']['id'], sequel_id) self.assertEqual(result['movie']['remakeFor']['id'], remake_id)
def test_download_kinopoisk_image_for_object(self): url = '//st.kp.yandex.net/im/poster/4/8/3/kinopoisk.ru-Les-amants-r_26_23233_3Bguliers-483294.jpg' movie = MovieFactory() image1, downloaded = movie.images.get_or_download(url) self.assertEqual(downloaded, True) self.assertEqual(image1.image.source, 'st.kp.yandex.net') self.assertEqual(image1.image.source_type, ImageSourceType.KINOPOISK) self.assertEqual(image1.image.source_id, '483294') self.assertEqual(image1.object, movie) self.assertEqual(image1, movie.images.last()) image2, downloaded = movie.images.get_or_download(url) self.assertEqual(downloaded, False) self.assertEqual(image1, image2)
def test_movie_with_m2m(self): m = MovieFactory() query = ''' query Movie($id: ID!) { movie(id: $id) { id genres { nameEn } countries { nameEn } languages { nameEn } } } ''' with self.assertNumQueries(4): result = self.execute(query, dict(id=global_id(m))) self.assertGreater(len(result['movie']['genres']), 0) self.assertGreater(len(result['movie']['languages']), 0) self.assertGreater(len(result['movie']['countries']), 0) self.assert_m2m_rel(result['movie']['genres'], m.genres) self.assert_m2m_rel(result['movie']['languages'], m.languages) self.assert_m2m_rel(result['movie']['countries'], m.countries)
def test_movie_title_transliteration(self): movie = MovieFactory(title='', title_en='', title_ru='Ирония судьбы, или с легким паром!') self.assertEqual(len(movie.title), 0) movie.set_transliteratable_fields() self.assertEqual(movie.title, movie.title_en) self.assertGreater(len(movie.title), 0)
def test_movie_year(self): with self.assertRaises(ValidationError): MovieFactory(year=0) with self.assertRaises(ValidationError): MovieFactory(year=2100)
def easy_rider(self): return MovieFactory(title_en='Easy Rider', title_ru='Беспечный Ездок', year=1969)
def test_movie_url(self): movie = MovieFactory() KinopoiskMovie.objects.create(id=1, movie=movie) self.assertEqual(movie.kinopoisk.url, 'http://www.kinopoisk.ru/film/1/')
def setUp(self): for i in range(self.count): MovieFactory()
def test_add_roles_to_person_by_movie_titles(self): movie1 = MovieFactory(title_en='Easy Rider', year=1969) movie2 = MovieFactory(title_en='True Romance', year=1993) imdb_person = self.imdb_dennis_hopper() imdb_person.sync(roles=True) self.assert_dennis_hopper_career(imdb_person, movie1, movie2)
def test_movie_url(self): movie = MovieFactory() ImdbMovie.objects.create(id=1, movie=movie) self.assertEqual(movie.imdb.url, 'http://www.imdb.com/title/tt0000001/')