示例#1
0
    def test_base_api_request_after_handler_with_preview_no_return(self, mock_get):
        mock_get.return_value = self._mock_api_response

        base_api = BaseApi(self._api_key, [self._request_handler_mock_no_return])
        endpoint_name = "endpoint_xx"
        method_name = "method_xx"
        region = "region_xx"
        url_ext = "url_xx"
        kwarg = "extra_xx"

        ret = base_api.request(endpoint_name, method_name, region, url_ext, extra=kwarg)

        self._request_handler_mock_no_return.after_request.assert_called_once_with(
            region,
            endpoint_name,
            method_name,
            "https://region_xx.api.riotgames.com%s" % url_ext,
            self._mock_api_response,
        )

        mock_get.assert_called_once_with(
            "https://region_xx.api.riotgames.com%s" % url_ext,
            headers={"X-Riot-Token": self._api_key},
            params={"extra": kwarg},
        )

        self.assertEqual(ret, self._mock_api_response)
示例#2
0
    def test_base_api_request_static_preview_handler(self):
        base_api = BaseApi(self._api_key, [self._request_handler_mock])
        version = "version_xx"
        locale = "locale_xx"
        url_ext = "url_xx"

        ret = base_api.request_static(version, locale, url_ext)

        self._request_handler_mock.preview_static_request.assert_called_once_with(
            "https://ddragon.leagueoflegends.com/cdn/%s/data/%s/%s.json"
            % (version, locale, url_ext),
            {},
        )
示例#3
0
    def test_raw_request_static_default_timeout(self, mock_get):
        expected_url, expected_query_params = "url", {}
        expected_resp = object()

        api = BaseApi("12345")

        mock_get.return_value = expected_resp

        resp = api.raw_request_static(expected_url, expected_query_params)

        assert resp is expected_resp

        mock_get.assert_called_once_with(expected_url, params=expected_query_params)
示例#4
0
    def test_raw_request_static_default_timeout(self, mock_get):
        expected_url, expected_query_params = "url", {}
        expected_resp = object()

        api = BaseApi("12345")

        mock_get.return_value = expected_resp

        resp = api.raw_request_static(expected_url, expected_query_params)

        assert resp is expected_resp

        mock_get.assert_called_once_with(expected_url, params=expected_query_params)
示例#5
0
    def test_base_api_request_preview_handler(self):
        base_api = BaseApi(self._api_key, [self._request_handler_mock])
        endpoint_name = "endpoint_xx"
        method_name = "method_xx"
        region = "region_xx"
        url_ext = "url_xx"
        kwarg = "extra_xx"

        base_api.request(endpoint_name, method_name, region, url_ext, extra=kwarg)

        self._request_handler_mock.preview_request.assert_called_once_with(
            region,
            endpoint_name,
            method_name,
            "https://region_xx.api.riotgames.com%s" % url_ext,
            {"extra": kwarg},
        )
示例#6
0
    def test_base_api_request_after_handler_with_preview_return(self):
        base_api = BaseApi(self._api_key, [self._request_handler_mock])
        endpoint_name = "endpoint_xx"
        method_name = "method_xx"
        region = "region_xx"
        url_ext = "url_xx"
        kwarg = "extra_xx"

        ret = base_api.request(endpoint_name, method_name, region, url_ext, extra=kwarg)

        self._request_handler_mock.after_request.assert_called_once_with(
            region,
            endpoint_name,
            method_name,
            "https://region_xx.api.riotgames.com%s" % url_ext,
            self._expected_preview_return,
        )

        self.assertEqual(ret, self._expected_after_return)
示例#7
0
    def test_raw_request_default_timeout(self, mock_get):
        expected_url, expected_query_params = "url", {}
        expected_api_key = "12345"
        expected_headers = {"X-Riot-Token": expected_api_key}
        expected_resp = object()

        api = BaseApi(expected_api_key)

        mock_get.return_value = expected_resp

        resp = api.raw_request(
            "endpoint", "method", "region", expected_url, expected_query_params
        )

        assert resp is expected_resp

        mock_get.assert_called_once_with(
            expected_url, params=expected_query_params, headers=expected_headers
        )
示例#8
0
    def test_raw_request_default_timeout(self, mock_get):
        expected_url, expected_query_params = "url", {}
        expected_api_key = "12345"
        expected_headers = {"X-Riot-Token": expected_api_key}
        expected_resp = object()

        api = BaseApi(expected_api_key)

        mock_get.return_value = expected_resp

        resp = api.raw_request(
            "endpoint", "method", "region", expected_url, expected_query_params
        )

        assert resp is expected_resp

        mock_get.assert_called_once_with(
            expected_url, params=expected_query_params, headers=expected_headers
        )
示例#9
0
    def test_base_api_request_static_after_handler_with_preview_no_return(
        self, mock_get
    ):
        mock_get.return_value = self._mock_api_response

        base_api = BaseApi(self._api_key, [self._request_handler_mock_no_return])
        version = "version_xx"
        locale = "locale_xx"
        url_ext = "url_xx"

        ret = base_api.request_static(version, locale, url_ext)

        self._request_handler_mock_no_return.after_static_request.assert_called_once_with(
            "https://ddragon.leagueoflegends.com/cdn/%s/data/%s/%s.json"
            % (version, locale, url_ext),
            self._mock_api_response,
        )

        mock_get.assert_called_once_with(
            "https://ddragon.leagueoflegends.com/cdn/%s/data/%s/%s.json"
            % (version, locale, url_ext)
        )

        self.assertEqual(ret, self._mock_api_response)