예제 #1
0
    def test_calls_functions_correctly(self, mocker: MockerFixture) -> None:
        mocker.patch("panel.tasks.subtitles.requests", MockRequest)
        mocker.patch("panel.tasks.tests.mocks.MockRequest.text", "lalala")
        request_from_api = mocker.spy(panel.tasks.subtitles,
                                      "_request_from_api")
        _file_hash: str = "abc"
        _file_byte_size: int = 1000
        _imdb_id: str = "tt01010101"
        _file_name: str = "video.mp4"
        _language: str = "eng"
        file_byte_size: str = f"/moviebytesize-{_file_byte_size}"
        file_hash: str = f"/moviehash-{_file_hash}"
        imdb_id = f"/imdbid-{_imdb_id[2:]}"
        _encoded_file_name: str = urllib.parse.quote(_file_name)
        file_name = f"/query-{_encoded_file_name}"
        language = f"/sublanguageid-{_language}"

        result = _get_response_from_api(
            file_hash=_file_hash,
            file_byte_size=_file_byte_size,
            imdb_id=_imdb_id,
            file_name=_file_name,
            language=_language,
        )

        request_from_api.assert_any_call(OS_URL + imdb_id + language)
        request_from_api.assert_any_call(OS_URL + file_name + imdb_id +
                                         language)
        request_from_api.assert_any_call(OS_URL + file_byte_size + file_hash +
                                         imdb_id + language)
        assert result is None
예제 #2
0
    def test_returns_response_correctly(self, mocker: MockerFixture) -> None:
        mocker.patch("panel.tasks.subtitles.requests", MockRequest)

        result = _get_response_from_api(
            file_hash="abcdef",
            file_byte_size=1,
            imdb_id="tt010101010",
            file_name="video.mp4",
        )

        assert isinstance(result, dict)
        assert result == json.loads(MockRequest._text)