Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tester authored and Tester committed Jan 25, 2024
1 parent 85194c5 commit fb8805a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
37 changes: 10 additions & 27 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,18 @@ def _enforce_trailing_slash(self, url: URL) -> URL:
return url.copy_with(raw_path=url.raw_path + b"/")

def _get_proxy_map(
self, proxies: ProxyTypes | None, allow_env_proxies: bool
self, proxy: ProxyTypes | None, allow_env_proxies: bool
) -> dict[str, Proxy | None]:
if proxies is None:
if proxy is None:
if allow_env_proxies:
return {
key: None if url is None else Proxy(url=url)
for key, url in get_environment_proxies().items()
}
return {}
if isinstance(proxies, dict):
new_proxies = {}
for key, value in proxies.items():
proxy = Proxy(url=value) if isinstance(value, (str, URL)) else value
new_proxies[str(key)] = proxy
return new_proxies
else:
proxy = Proxy(url=proxies) if isinstance(proxies, (str, URL)) else proxies
return {"all://": proxy}

proxy = Proxy(url=proxy) if isinstance(proxy, (str, URL)) else proxy
return {"all://": proxy}

@property
def timeout(self) -> Timeout:
Expand Down Expand Up @@ -386,17 +380,6 @@ def _merge_url(self, url: URLTypes) -> URL:
return self.base_url.copy_with(raw_path=merge_raw_path)
return merge_url

def _merge_cookies(self, cookies: CookieTypes | None = None) -> CookieTypes | None:
"""
Merge a cookies argument together with any cookies on the client,
to create the cookies used for the outgoing request.
"""
if cookies or self.cookies:
merged_cookies = Cookies(self.cookies)
merged_cookies.update(cookies)
return merged_cookies
return cookies

def _merge_headers(self, headers: HeaderTypes | None = None) -> HeaderTypes | None:
"""
Merge a headers argument together with any headers on the client,
Expand Down Expand Up @@ -1215,7 +1198,7 @@ def delete(

def close(self) -> None:
"""
Close transport and proxies.
Close transport and mounts.
"""
if self._state != ClientState.CLOSED:
self._state = ClientState.CLOSED
Expand Down Expand Up @@ -1916,15 +1899,15 @@ async def delete(

async def aclose(self) -> None:
"""
Close transport and proxies.
Close transport and mounts.
"""
if self._state != ClientState.CLOSED:
self._state = ClientState.CLOSED

await self._transport.aclose()
for proxy in self._mounts.values():
if proxy is not None:
await proxy.aclose()
for transport in self._mounts.values():
if transport is not None:
transport.close()

async def __aenter__(self: U) -> U:
if self._state != ClientState.UNOPENED:
Expand Down
7 changes: 7 additions & 0 deletions tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ def test_put(server):
assert response.reason_phrase == "OK"


def test_put_json(server):
with httpx.Client() as client:
response = client.put(server.url, json={"text": "Hello, world!"})
assert response.status_code == 200
assert response.reason_phrase == "OK"


def test_patch(server):
with httpx.Client() as client:
response = client.patch(server.url, content=b"Hello, world!")
Expand Down

0 comments on commit fb8805a

Please sign in to comment.