Ejemplo n.º 1
0
    async def test_client_always_has_default_timeout_configured(self):

        client = HttpClient()
        client.session_class = self.session_class_mock

        await client.get(TEST_URL)

        client.session_class.assert_called_with(
            timeout=default_http_client_timeout,
            headers=ANY,
            raise_for_status=True,
        )
Ejemplo n.º 2
0
    async def test_delete(self):
        expected_headers = {"X-Header": "Value"}
        timeout = ClientTimeout(connect=5, total=10)
        client = HttpClient()
        client.session_class = self.session_class_mock

        await client.delete(TEST_URL, timeout=timeout, headers=expected_headers)
        client._session.request.assert_awaited_with(
            "delete",
            TEST_URL,
            timeout=timeout,
            headers=expected_headers,
            raise_for_status=True,
            allow_redirects=True,
        )
Ejemplo n.º 3
0
    async def test_always_make_request_with_follow_redirect(self):
        """
        Seguimos redirect por padrão
        """
        client = HttpClient()
        client.session_class = self.session_class_mock

        await client.get(TEST_URL)
        client._session.request.assert_called_with(
            "get",
            TEST_URL,
            timeout=ANY,
            headers=ANY,
            allow_redirects=True,
            raise_for_status=True,
        )
Ejemplo n.º 4
0
    async def test_can_override_option_to_automatically_raise_when_request_fails(
        self
    ):
        timeout = ClientTimeout(connect=1, total=5)
        client = HttpClient()
        client.session_class = self.session_class_mock

        await client.get(TEST_URL, raise_for_status=False)
        client._session.request.assert_awaited_with(
            "get",
            ANY,
            timeout=ANY,
            headers=ANY,
            raise_for_status=False,
            allow_redirects=True,
        )
Ejemplo n.º 5
0
    async def test_can_pass_extra_kwarg_to_aiohttp_client_sesson(self):
        """
        Confirmamos que quando passamos argumentos extras para o HttpClient
        isso é repassado para o ClientSession
        """
        client = HttpClient()
        client.session_class = self.session_class_mock

        await client.put(TEST_URL, json={"key": "value"})
        client._session.request.assert_awaited_with(
            "put",
            TEST_URL,
            timeout=None,
            headers={},
            raise_for_status=True,
            allow_redirects=True,
            json={"key": "value"},
        )
Ejemplo n.º 6
0
    async def test_can_choose_a_different_timeout_on_client_instantiation(self):
        new_timeout = ClientTimeout(total=2, connect=5)
        client = HttpClient(timeout=new_timeout)
        client.session_class = self.session_class_mock

        await client.get(TEST_URL)

        client.session_class.assert_called_with(
            timeout=new_timeout, headers=ANY, raise_for_status=True
        )

        client._session.request.assert_awaited_with(
            "get",
            ANY,
            timeout=None,
            headers=ANY,
            allow_redirects=True,
            raise_for_status=True,
        )
Ejemplo n.º 7
0
    async def test_can_override_timeout_passing_a_new_timeout_on_the_request(
        self
    ):
        """
        client.get(..., timeout=ClientTimeout(...))
        """
        timeout = ClientTimeout(connect=1, total=5)
        client = HttpClient()
        client.session_class = self.session_class_mock

        await client.get(TEST_URL, timeout=timeout)
        client._session.request.assert_awaited_with(
            "get",
            ANY,
            timeout=timeout,
            headers=ANY,
            allow_redirects=True,
            raise_for_status=True,
        )