def test_unmached_item(self): item = ParsedMediaItem(title="The Goat", year="2015", filename="The Goat 2015.mp4", path="c:/movies") source = TMDBApi() source.match = MagicMock(return_value=[ MovieMatchCandidate(title="Will Never Match", release_year=1959) ]) media_matching_observer = MediaItemMatchingObserver( job_context=MockJobContext(), matcher=SourceMatcher(source=source), resolver=SkipExistingMediaTargetResolver( media_target_builder=NoOpMediaTargetBuilder())) media_matching_observer.on_next(index_and_media=(1, item)) unmatched_item = UnmatchedItem.query.join(ParsedMediaItem) \ .filter(ParsedMediaItem.title == 'The Goat').first() movies_count = Movie.query.count() self.assertIsNotNone(unmatched_item) self.assertEqual('2015', unmatched_item.parsed_media_item.year) self.assertEqual(0, movies_count)
def test_perfect_match(self): item = ParsedMediaItem(title="The Goat", year="2015", filename="The Goat 2015.mp4", path="c:/movies") source = TMDBApi() source.match = MagicMock(return_value=[ MovieMatchCandidate(title="The Goat", release_year=2015) ]) media_matching_observer = MediaItemMatchingObserver( job_context=MockJobContext(), matcher=SourceMatcher(source=source), resolver=SkipExistingMediaTargetResolver( media_target_builder=NoOpMediaTargetBuilder())) media_matching_observer.on_next(index_and_media=(1, item)) matched_movie = Movie.query.filter(Movie.title == 'The Goat').first() matched_movies_count = Movie.query.filter( Movie.title == 'The Goat').count() self.assertIsNotNone(matched_movie) self.assertEqual('The Goat', matched_movie.title) self.assertEqual(2015, matched_movie.release_year) self.assertEqual(1, matched_movies_count)
def test_match_against_original_title(self): tmdb_source = TMDBApi() file_with_original_title = replace(self.file, title="Moje Córki Krowy") tmdb_source.match = MagicMock(return_value=[self.movie_match_candidate]) matches = SourceMatcher(tmdb_source).top5_matches(file_with_original_title) tmdb_source.match.assert_called_with(title='Moje Córki Krowy') self.assertEqual(100, matches[0].match)
def test_matched_is_case_insesnsitive(self): tmdb_source = TMDBApi() tmdb_source.match = MagicMock(return_value=[self.movie_match_candidate]) matches = SourceMatcher(tmdb_source).top5_matches(self.file) tmdb_source.match.assert_called_with(title='THESE daughters of MINE') self.assertEqual(1, len(matches)) self.assertEqual(100, matches[0].match)
def test_match_against_akas(self): tmdb_source = TMDBApi() file_with_foereign_title = replace(self.file, title="Mine døtre kuene") self.movie_match_candidate.akas = ["Foo", "bar", "Mine døtre kuene"] tmdb_source.match = MagicMock(return_value=[self.movie_match_candidate]) matches = SourceMatcher(tmdb_source).top5_matches(file_with_foereign_title) tmdb_source.match.assert_called_with(title='Mine døtre kuene') self.assertEqual(100, matches[0].match)
def test_fallback_matcher(self): tmdb_source = TMDBApi() tmdb_source.match = MagicMock(return_value=[]) imdb_source = IMDBApi() imdb_source.match = MagicMock(return_value=[self.movie_match_candidate]) matcher = FallbackSourceMatcher(primary=tmdb_source, secondary=imdb_source) matches = matcher.top5_matches(self.file) tmdb_source.match.assert_called_with(title='THESE daughters of MINE') imdb_source.match.assert_called_with(title='THESE daughters of MINE') self.assertEqual(1, len(matches)) self.assertEqual(100, matches[0].match)
def test_low_threshold_fallback_matcher_with_boost(self): tmdb_source = TMDBApi() tmdb_source.match = MagicMock(return_value=[ replace(self.movie_match_candidate), replace(self.movie_match_candidate, release_year=2012), replace(self.movie_match_candidate, release_year=2011)]) imdb_source = IMDBApi() imdb_source.match = MagicMock(return_value=[]) matcher = FallbackLowThresholdSourceMatcher(primary=tmdb_source, secondary=imdb_source) matches = matcher.top5_matches(replace(self.file, year=2014)) self.assertEqual(3, len(matches)) self.assertEqual(97, matches[0].match) self.assertEqual(96, matches[1].match) self.assertEqual(96, matches[2].match)
def test_low_threshold_fallback_matcher_no_dedupliaction(self): tmdb_source = TMDBApi() tmdb_source.match = MagicMock(return_value=[replace(self.movie_match_candidate, title="DO NOT MATCH", original_title="DO NOT MATCH", external_id=123456)]) tmdb_source.get_by_imdbid_id = MagicMock(return_value=replace(self.movie_match_candidate, external_id=234567)) imdb_source = IMDBApi() imdb_source.match = MagicMock(return_value=[self.movie_match_candidate]) matcher = FallbackLowThresholdSourceMatcher(primary=tmdb_source, secondary=imdb_source) matches = matcher.top5_matches(self.file) self.assertEqual(2, len(matches)) self.assertEqual(100, matches[0].match) tmdb_source.match.assert_called_with(title='THESE daughters of MINE') tmdb_source.get_by_imdbid_id.assert_called_with(4834762) imdb_source.match.assert_called_with(title='THESE daughters of MINE')