Пример #1
0
    def test_raises_when_response_not_200(self, mocker: MonkeyPatch) -> None:
        mocker.patch("panel.tasks.moviedb.requests", MockRequest)
        mocker.patch("panel.tasks.tests.mocks.MockRequest.status_code", 404)

        with pytest.raises(Exception) as exc:
            _get_response_from_moviedb_api("http://test")

        assert str(exc.value) == "Moviedb API returned the status code 404"
Пример #2
0
    def test_returns_result(self, mocker: MonkeyPatch) -> None:
        mocker.patch("panel.tasks.moviedb.requests", MockRequest)
        mocker.patch(
            "panel.tasks.tests.mocks.MockRequest.text",
            json.dumps(MOVIEDB).encode("UTF-8"),
        )
        mocker.patch.object(
            panel.tasks.tests.mocks.MockRequest, "json", lambda x: {"dummy": "response"}
        )

        assert _get_response_from_moviedb_api("http://test") == MOVIEDB
Пример #3
0
    def test_raises_when_response_has_only_empty_lists(
        self, mocker: MonkeyPatch
    ) -> None:
        result: Dict[str, Any] = {
            "movie_results": [],
            "person_results": [],
            "tv_results": [],
            "tv_episode_results": [],
            "tv_season_results": [],
        }
        mocker.patch("panel.tasks.moviedb.requests", MockRequest)
        mocker.patch.object(
            panel.tasks.tests.mocks.MockRequest, "json", lambda x: result
        )

        with pytest.raises(Exception) as exc:
            _get_response_from_moviedb_api("http://test")

        assert (
            str(exc.value) == "Moviedb API returned no results. Possible wrong IMDB ID"
        )