Beispiel #1
0
def test_tmdb_search_movies__success():
    expected_top_level_keys = {
        "page",
        "results",
        "total_pages",
        "total_results",
    }
    expected_results_keys = {
        "adult",
        "backdrop_path",
        "genre_ids",
        "id",
        "original_language",
        "original_title",
        "overview",
        "popularity",
        "poster_path",
        "release_date",
        "title",
        "video",
        "vote_average",
        "vote_count",
    }
    result = tmdb_search_movies(Tmdb.api_key, "the goonies", 1985)
    assert isinstance(result, dict)
    assert set(result.keys()) == expected_top_level_keys
    assert isinstance(result["results"], list)
    assert expected_results_keys == set(result.get("results", [{}])[0].keys())
    assert len(result["results"]) == 1
    assert result["results"][0]["original_title"] == "The Goonies"
    result = tmdb_search_movies(Tmdb.api_key, "the goonies")
    assert len(result["results"]) > 1
Beispiel #2
0
 def _search_name(self, name: str, year: Optional[str],
                  language: Optional[Language]):
     assert self.api_key
     year_from, year_to = year_range_parse(year, 5)
     page = 1
     page_max = 5  # each page yields a maximum of 20 results
     found = False
     while True:
         response = tmdb_search_movies(
             self.api_key,
             name,
             f"{year_from}-{year_to}",
             language,
             page=page,
             cache=self.cache,
         )
         for entry in response["results"]:
             try:
                 meta = MetadataMovie(
                     id_tmdb=entry["id"],
                     name=entry["title"],
                     language=language,
                     synopsis=entry["overview"],
                     year=entry["release_date"],
                 )
                 if not meta.year:
                     continue
                 if year_from <= int(meta.year) <= year_to:
                     yield meta
                     found = True
             except (AttributeError, KeyError, TypeError, ValueError):
                 continue
         if page == response["total_pages"]:
             break
         elif page >= page_max:
             break
         page += 1
     if not found:
         raise MnamerNotFoundException
Beispiel #3
0
def test_tmdb_search_movies__bad_year():
    with pytest.raises(MnamerException):
        tmdb_search_movies(Tmdb.api_key,
                           "the goonies",
                           year=JUNK_TEXT,
                           cache=False)
Beispiel #4
0
def test_tmdb_search_movies__bad_title():
    with pytest.raises(MnamerNotFoundException):
        tmdb_search_movies(Tmdb.api_key, JUNK_TEXT, cache=False)
Beispiel #5
0
def test_tmdb_search_movies__bad_api_key():
    with pytest.raises(MnamerException):
        tmdb_search_movies(JUNK_TEXT, "the goonies", cache=False)
Beispiel #6
0
def test_search_movies__language():
    results = tmdb_search_movies(Tmdb.api_key,
                                 "the goonies",
                                 language=RUSSIAN_LANG)
    assert any(result["title"] == "Балбесы" for result in results["results"])