Skip to content
Myr

test_auth.py

This file

Path

tests/client/test_auth.py

693 lines · 21.7 KiB · Python

Last changed by

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

History of this file

Take it

The walk stopped after 200 commits: lines older than 19bf211 point at it.

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 1–6why, one step back
1"""
2Integration tests for authentication.34Unit tests for auth classes also exist in tests/test_auth.py5"""6import asyncio

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 7why, one step back
7import hashlib

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 8why, one step back
8import json

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 9why, one step back
9import os

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

line 10why, one step back
10import threading

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 11–14why, one step back
11import typing
1213import pytest14

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 15why, one step back
15import httpx

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 16–18why, one step back
16from httpx import (
17 URL,18 Auth,

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 19why, one step back
19 BasicAuth,

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 20–25why, one step back
20 DigestAuth,
21 ProtocolError,22 Request,23 RequestBodyUnavailable,24 Response,25)

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 26why, one step back
26from tests.utils import AsyncMockTransport, MockTransport

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 27why, one step back
27

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 28why, one step back
28from ..common import FIXTURES_DIR

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 29why, one step back
29

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 30why, one step back
30

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 31–32why, one step back
31class App:
32 def __init__(self, auth_header: str = "", status_code: int = 200) -> None:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 33–35why, one step back
33 self.auth_header = auth_header
34 self.status_code = status_code35

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 36–40why, one step back
36 def __call__(self, request: httpx.Request) -> httpx.Response:
37 headers = {"www-authenticate": self.auth_header} if self.auth_header else {}38 data = {"auth": request.headers.get("Authorization")}39 content = json.dumps(data).encode("utf-8")40 return httpx.Response(self.status_code, headers=headers, content=content)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 41–42why, one step back
41
42

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 43why, one step back
43class DigestApp:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 44–56why, one step back
44 def __init__(
45 self,46 algorithm: str = "SHA-256",47 send_response_after_attempt: int = 1,48 qop: str = "auth",49 regenerate_nonce: bool = True,50 ) -> None:51 self.algorithm = algorithm52 self.send_response_after_attempt = send_response_after_attempt53 self.qop = qop54 self._regenerate_nonce = regenerate_nonce55 self._response_count = 056

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 57why, one step back
57 def __call__(self, request: httpx.Request) -> httpx.Response:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 58why, one step back
58 if self._response_count < self.send_response_after_attempt:

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 59why, one step back
59 return self.challenge_send(request)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 60why, one step back
60

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 61–63why, one step back
61 data = {"auth": request.headers.get("Authorization")}
62 content = json.dumps(data).encode("utf-8")63 return httpx.Response(200, content=content)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 64why, one step back
64

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 65why, one step back
65 def challenge_send(self, request: httpx.Request) -> httpx.Response:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 66–86why, one step back
66 self._response_count += 1
67 nonce = (68 hashlib.sha256(os.urandom(8)).hexdigest()69 if self._regenerate_nonce70 else "ee96edced2a0b43e4869e96ebe27563f369c1205a049d06419bb51d8aeddf3d3"71 )72 challenge_data = {73 "nonce": nonce,74 "qop": self.qop,75 "opaque": (76 "ee6378f3ee14ebfd2fff54b70a91a7c9390518047f242ab2271380db0e14bda1"77 ),78 "algorithm": self.algorithm,79 "stale": "FALSE",80 }81 challenge_str = ", ".join(82 '{}="{}"'.format(key, value)83 for key, value in challenge_data.items()84 if value85 )86

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 87–90why, one step back
87 headers = {
88 "www-authenticate": f'Digest realm="httpx@example.org", {challenge_str}',89 }90 return Response(401, headers=headers)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 91–92why, one step back
91
92

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 93–138why, one step back
93class RepeatAuth(Auth):
94 """95 A mock authentication scheme that requires clients to send96 the request a fixed number of times, and then send a last request containing97 an aggregation of nonces that the server sent in 'WWW-Authenticate' headers98 of intermediate responses.99 """100101 requires_request_body = True102103 def __init__(self, repeat: int):104 self.repeat = repeat105106 def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:107 nonces = []108109 for index in range(self.repeat):110 request.headers["Authorization"] = f"Repeat {index}"111 response = yield request112 nonces.append(response.headers["www-authenticate"])113114 key = ".".join(nonces)115 request.headers["Authorization"] = f"Repeat {key}"116 yield request117118119class ResponseBodyAuth(Auth):120 """121 A mock authentication scheme that requires clients to send an 'Authorization'122 header, then send back the contents of the response in the 'Authorization'123 header.124 """125126 requires_response_body = True127128 def __init__(self, token):129 self.token = token130131 def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:132 request.headers["Authorization"] = self.token133 response = yield request134 data = response.text135 request.headers["Authorization"] = data136 yield request137138

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 139–163why, one step back
139class SyncOrAsyncAuth(Auth):
140 """141 A mock authentication scheme that uses a different implementation for the142 sync and async cases.143 """144145 def __init__(self) -> None:146 self._lock = threading.Lock()147 self._async_lock = asyncio.Lock()148149 def sync_auth_flow(150 self, request: Request151 ) -> typing.Generator[Request, Response, None]:152 with self._lock:153 request.headers["Authorization"] = "sync-auth"154 yield request155156 async def async_auth_flow(157 self, request: Request158 ) -> typing.AsyncGenerator[Request, Response]:159 async with self._async_lock:160 request.headers["Authorization"] = "async-auth"161 yield request162163

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 164–167why, one step back
164@pytest.mark.asyncio
165async def test_basic_auth() -> None:166 url = "https://example.org/"167 auth = ("tomchristie", "password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 168why, one step back
168 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 169why, one step back
169

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 170why, one step back
170 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 171why, one step back
171 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 172–179why, one step back
172
173 assert response.status_code == 200174 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}175176177@pytest.mark.asyncio178async def test_basic_auth_in_url() -> None:179 url = "https://tomchristie:password123@example.org/"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 180why, one step back
180 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 181why, one step back
181

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 182why, one step back
182 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 183why, one step back
183 response = await client.get(url)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 184–192why, one step back
184
185 assert response.status_code == 200186 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}187188189@pytest.mark.asyncio190async def test_basic_auth_on_session() -> None:191 url = "https://example.org/"192 auth = ("tomchristie", "password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 193why, one step back
193 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 194why, one step back
194

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 195–197why, one step back
195 async with httpx.AsyncClient(
196 transport=AsyncMockTransport(app), auth=auth197 ) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 198why, one step back
198 response = await client.get(url)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 199–206why, one step back
199
200 assert response.status_code == 200201 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}202203204@pytest.mark.asyncio205async def test_custom_auth() -> None:206 url = "https://example.org/"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 207why, one step back
207 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 208–212why, one step back
208
209 def auth(request: Request) -> Request:210 request.headers["Authorization"] = "Token 123"211 return request212

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 213why, one step back
213 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 214why, one step back
214 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 215–221why, one step back
215
216 assert response.status_code == 200217 assert response.json() == {"auth": "Token 123"}218219220@pytest.mark.asyncio221async def test_netrc_auth() -> None:

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 222why, one step back
222 os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 223why, one step back
223 url = "http://netrcexample.org"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 224why, one step back
224 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 225why, one step back
225

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 226why, one step back
226 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 227why, one step back
227 response = await client.get(url)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 228–236why, one step back
228
229 assert response.status_code == 200230 assert response.json() == {231 "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"232 }233234235@pytest.mark.asyncio236async def test_auth_header_has_priority_over_netrc() -> None:

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 237why, one step back
237 os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 238why, one step back
238 url = "http://netrcexample.org"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 239why, one step back
239 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 240why, one step back
240

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 241why, one step back
241 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 242why, one step back
242 response = await client.get(url, headers={"Authorization": "Override"})

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 243–249why, one step back
243
244 assert response.status_code == 200245 assert response.json() == {"auth": "Override"}246247248@pytest.mark.asyncio249async def test_trust_env_auth() -> None:

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 250why, one step back
250 os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 251why, one step back
251 url = "http://netrcexample.org"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 252why, one step back
252 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 253why, one step back
253

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 254why, one step back
254 async with httpx.AsyncClient(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 255why, one step back
255 transport=AsyncMockTransport(app), trust_env=False

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 256–257why, one step back
256 ) as client:
257 response = await client.get(url)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 258–261why, one step back
258
259 assert response.status_code == 200260 assert response.json() == {"auth": None}261

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 262why, one step back
262 async with httpx.AsyncClient(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 263why, one step back
263 transport=AsyncMockTransport(app), trust_env=True

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 264–265why, one step back
264 ) as client:
265 response = await client.get(url)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 266–272why, one step back
266
267 assert response.status_code == 200268 assert response.json() == {269 "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"270 }271272

Allow disabling auth per-request using `auth=None` (#1115)Florimond Mancabefore adoptiona4463d0

lines 273–276why, one step back
273@pytest.mark.asyncio
274async def test_auth_disable_per_request() -> None:275 url = "https://example.org/"276 auth = ("tomchristie", "password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 277why, one step back
277 app = App()

Allow disabling auth per-request using `auth=None` (#1115)Florimond Mancabefore adoptiona4463d0

line 278why, one step back
278

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 279–281why, one step back
279 async with httpx.AsyncClient(
280 transport=AsyncMockTransport(app), auth=auth281 ) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 282why, one step back
282 response = await client.get(url, auth=None)

Allow disabling auth per-request using `auth=None` (#1115)Florimond Mancabefore adoptiona4463d0

lines 283–287why, one step back
283
284 assert response.status_code == 200285 assert response.json() == {"auth": None}286287

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 288–298why, one step back
288def test_auth_hidden_url() -> None:
289 url = "http://example-username:example-password@example.org/"290 expected = "URL('http://example-username:[secure]@example.org/')"291 assert url == URL(url)292 assert expected == repr(URL(url))293294295@pytest.mark.asyncio296async def test_auth_hidden_header() -> None:297 url = "https://example.org/"298 auth = ("example-username", "example-password")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 299why, one step back
299 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 300why, one step back
300

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 301why, one step back
301 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 302why, one step back
302 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 303–307why, one step back
303
304 assert "'authorization': '[secure]'" in str(response.request.headers)305306307@pytest.mark.asyncio

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 308why, one step back
308async def test_auth_property() -> None:

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 309–311why, one step back
309 app = App()
310311 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 312why, one step back
312 assert client.auth is None

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 313why, one step back
313

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 314–315why, one step back
314 client.auth = ("tomchristie", "password123") # type: ignore
315 assert isinstance(client.auth, BasicAuth)

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 316why, one step back
316

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 317–320why, one step back
317 url = "https://example.org/"
318 response = await client.get(url)319 assert response.status_code == 200320 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

lines 321–324why, one step back
321
322323@pytest.mark.asyncio324async def test_auth_invalid_type() -> None:

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 325–326why, one step back
325 app = App()
326

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 327why, one step back
327 with pytest.raises(TypeError):

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 328why, one step back
328 client = httpx.AsyncClient(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 329why, one step back
329 transport=AsyncMockTransport(app),

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

lines 330–332why, one step back
330 auth="not a tuple, not a callable", # type: ignore
331 )332

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 333why, one step back
333 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 334–335why, one step back
334 with pytest.raises(TypeError):
335 await client.get(auth="not a tuple, not a callable") # type: ignore

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 336why, one step back
336

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 337–338why, one step back
337 with pytest.raises(TypeError):
338 client.auth = "not a tuple, not a callable" # type: ignore

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 339why, one step back
339

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 340–344why, one step back
340
341@pytest.mark.asyncio342async def test_digest_auth_returns_no_auth_if_no_digest_header_in_response() -> None:343 url = "https://example.org/"344 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 345why, one step back
345 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 346why, one step back
346

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 347why, one step back
347 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 348why, one step back
348 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 349–354why, one step back
349
350 assert response.status_code == 200351 assert response.json() == {"auth": None}352 assert len(response.history) == 0353354

Handle multiple auth headers correctly (#1240)Tom Christiebefore adoption33d339a

lines 355–357why, one step back
355def test_digest_auth_returns_no_auth_if_alternate_auth_scheme() -> None:
356 url = "https://example.org/"357 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 358–359why, one step back
358 auth_header = "Token ..."
359 app = App(auth_header=auth_header, status_code=401)

Handle multiple auth headers correctly (#1240)Tom Christiebefore adoption33d339a

line 360why, one step back
360

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 361why, one step back
361 client = httpx.Client(transport=MockTransport(app))

Handle multiple auth headers correctly (#1240)Tom Christiebefore adoption33d339a

lines 362–368why, one step back
362 response = client.get(url, auth=auth)
363364 assert response.status_code == 401365 assert response.json() == {"auth": None}366 assert len(response.history) == 0367368

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 369–372why, one step back
369@pytest.mark.asyncio
370async def test_digest_auth_200_response_including_digest_auth_header() -> None:371 url = "https://example.org/"372 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 373–374why, one step back
373 auth_header = 'Digest realm="realm@host.com",qop="auth",nonce="abc",opaque="xyz"'
374 app = App(auth_header=auth_header, status_code=200)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 375why, one step back
375

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 376why, one step back
376 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 377why, one step back
377 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 378–387why, one step back
378
379 assert response.status_code == 200380 assert response.json() == {"auth": None}381 assert len(response.history) == 0382383384@pytest.mark.asyncio385async def test_digest_auth_401_response_without_digest_auth_header() -> None:386 url = "https://example.org/"387 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 388why, one step back
388 app = App(auth_header="", status_code=401)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 389why, one step back
389

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 390why, one step back
390 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 391why, one step back
391 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 392–416why, one step back
392
393 assert response.status_code == 401394 assert response.json() == {"auth": None}395 assert len(response.history) == 0396397398@pytest.mark.parametrize(399 "algorithm,expected_hash_length,expected_response_length",400 [401 ("MD5", 64, 32),402 ("MD5-SESS", 64, 32),403 ("SHA", 64, 40),404 ("SHA-SESS", 64, 40),405 ("SHA-256", 64, 64),406 ("SHA-256-SESS", 64, 64),407 ("SHA-512", 64, 128),408 ("SHA-512-SESS", 64, 128),409 ],410)411@pytest.mark.asyncio412async def test_digest_auth(413 algorithm: str, expected_hash_length: int, expected_response_length: int414) -> None:415 url = "https://example.org/"416 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 417why, one step back
417 app = DigestApp(algorithm=algorithm)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 418why, one step back
418

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 419why, one step back
419 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 420why, one step back
420 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 421–447why, one step back
421
422 assert response.status_code == 200423 assert len(response.history) == 1424425 authorization = typing.cast(dict, response.json())["auth"]426 scheme, _, fields = authorization.partition(" ")427 assert scheme == "Digest"428429 response_fields = [field.strip() for field in fields.split(",")]430 digest_data = dict(field.split("=") for field in response_fields)431432 assert digest_data["username"] == '"tomchristie"'433 assert digest_data["realm"] == '"httpx@example.org"'434 assert "nonce" in digest_data435 assert digest_data["uri"] == '"/"'436 assert len(digest_data["response"]) == expected_response_length + 2 # extra quotes437 assert len(digest_data["opaque"]) == expected_hash_length + 2438 assert digest_data["algorithm"] == algorithm439 assert digest_data["qop"] == "auth"440 assert digest_data["nc"] == "00000001"441 assert len(digest_data["cnonce"]) == 16 + 2442443444@pytest.mark.asyncio445async def test_digest_auth_no_specified_qop() -> None:446 url = "https://example.org/"447 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 448why, one step back
448 app = DigestApp(qop="")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 449why, one step back
449

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 450why, one step back
450 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 451why, one step back
451 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 452–479why, one step back
452
453 assert response.status_code == 200454 assert len(response.history) == 1455456 authorization = typing.cast(dict, response.json())["auth"]457 scheme, _, fields = authorization.partition(" ")458 assert scheme == "Digest"459460 response_fields = [field.strip() for field in fields.split(",")]461 digest_data = dict(field.split("=") for field in response_fields)462463 assert "qop" not in digest_data464 assert "nc" not in digest_data465 assert "cnonce" not in digest_data466 assert digest_data["username"] == '"tomchristie"'467 assert digest_data["realm"] == '"httpx@example.org"'468 assert len(digest_data["nonce"]) == 64 + 2 # extra quotes469 assert digest_data["uri"] == '"/"'470 assert len(digest_data["response"]) == 64 + 2471 assert len(digest_data["opaque"]) == 64 + 2472 assert digest_data["algorithm"] == "SHA-256"473474475@pytest.mark.parametrize("qop", ("auth, auth-int", "auth,auth-int", "unknown,auth"))476@pytest.mark.asyncio477async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str) -> None:478 url = "https://example.org/"479 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 480why, one step back
480 app = DigestApp(qop=qop)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 481why, one step back
481

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 482why, one step back
482 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 483why, one step back
483 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 484–492why, one step back
484
485 assert response.status_code == 200486 assert len(response.history) == 1487488489@pytest.mark.asyncio490async def test_digest_auth_qop_auth_int_not_implemented() -> None:491 url = "https://example.org/"492 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 493why, one step back
493 app = DigestApp(qop="auth-int")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 494why, one step back
494

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 495why, one step back
495 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 496–497why, one step back
496 with pytest.raises(NotImplementedError):
497 await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 498–503why, one step back
498
499500@pytest.mark.asyncio501async def test_digest_auth_qop_must_be_auth_or_auth_int() -> None:502 url = "https://example.org/"503 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 504why, one step back
504 app = DigestApp(qop="not-auth")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 505why, one step back
505

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 506why, one step back
506 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 507–508why, one step back
507 with pytest.raises(ProtocolError):
508 await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 509–514why, one step back
509
510511@pytest.mark.asyncio512async def test_digest_auth_incorrect_credentials() -> None:513 url = "https://example.org/"514 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 515why, one step back
515 app = DigestApp(send_response_after_attempt=2)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 516why, one step back
516

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 517why, one step back
517 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 518why, one step back
518 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 519–526why, one step back
519
520 assert response.status_code == 401521 assert len(response.history) == 1522523524@pytest.mark.parametrize(525 "auth_header",526 [

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 527–528why, one step back
527 'Digest realm="httpx@example.org", qop="auth"', # missing fields
528 'Digest realm="httpx@example.org", qop="auth,au', # malformed fields list

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 529–531why, one step back
529 ],
530)531@pytest.mark.asyncio

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 532why, one step back
532async def test_async_digest_auth_raises_protocol_error_on_malformed_header(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 533why, one step back
533 auth_header: str,

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 534–536why, one step back
534) -> None:
535 url = "https://example.org/"536 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 537–539why, one step back
537 app = App(auth_header=auth_header, status_code=401)
538539 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 540–541why, one step back
540 with pytest.raises(ProtocolError):
541 await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 542–543why, one step back
542
543

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 544–546why, one step back
544@pytest.mark.parametrize(
545 "auth_header",546 [

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 547–548why, one step back
547 'Digest realm="httpx@example.org", qop="auth"', # missing fields
548 'Digest realm="httpx@example.org", qop="auth,au', # malformed fields list

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 549–551why, one step back
549 ],
550)551def test_sync_digest_auth_raises_protocol_error_on_malformed_header(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 552why, one step back
552 auth_header: str,

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 553–555why, one step back
553) -> None:
554 url = "https://example.org/"555 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 556why, one step back
556 app = App(auth_header=auth_header, status_code=401)

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 557why, one step back
557

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 558why, one step back
558 with httpx.Client(transport=MockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 559–560why, one step back
559 with pytest.raises(ProtocolError):
560 client.get(url, auth=auth)

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 561–562why, one step back
561
562

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 563why, one step back
563@pytest.mark.asyncio

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 564why, one step back
564async def test_async_auth_history() -> None:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 565–568why, one step back
565 """
566 Test that intermediate requests sent as part of an authentication flow567 are recorded in the response history.568 """

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 569–570why, one step back
569 url = "https://example.org/"
570 auth = RepeatAuth(repeat=2)

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 571why, one step back
571 app = App(auth_header="abc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 572why, one step back
572

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 573why, one step back
573 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 574–575why, one step back
574 response = await client.get(url, auth=auth)
575

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 576–577why, one step back
576 assert response.status_code == 200
577 assert response.json() == {"auth": "Repeat abc.abc"}

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 578why, one step back
578

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 579–582why, one step back
579 assert len(response.history) == 2
580 resp1, resp2 = response.history581 assert resp1.json() == {"auth": "Repeat 0"}582 assert resp2.json() == {"auth": "Repeat 1"}

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 583why, one step back
583

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 584–585why, one step back
584 assert len(resp2.history) == 1
585 assert resp2.history == [resp1]

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 586why, one step back
586

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 587why, one step back
587 assert len(resp1.history) == 0

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 588–589why, one step back
588
589

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 590–594why, one step back
590def test_sync_auth_history() -> None:
591 """592 Test that intermediate requests sent as part of an authentication flow593 are recorded in the response history.594 """

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 595–596why, one step back
595 url = "https://example.org/"
596 auth = RepeatAuth(repeat=2)

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 597why, one step back
597 app = App(auth_header="abc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 598why, one step back
598

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 599why, one step back
599 with httpx.Client(transport=MockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 600–601why, one step back
600 response = client.get(url, auth=auth)
601

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 602–619why, one step back
602 assert response.status_code == 200
603 assert response.json() == {"auth": "Repeat abc.abc"}604605 assert len(response.history) == 2606 resp1, resp2 = response.history607 assert resp1.json() == {"auth": "Repeat 0"}608 assert resp2.json() == {"auth": "Repeat 1"}609610 assert len(resp2.history) == 1611 assert resp2.history == [resp1]612613 assert len(resp1.history) == 0614615616@pytest.mark.asyncio617async def test_digest_auth_unavailable_streaming_body():618 url = "https://example.org/"619 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 620why, one step back
620 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 621–622why, one step back
621
622 async def streaming_body():

Transport API (#963)Yeray Diaz Diazbefore adoptiond2816c9

line 623why, one step back
623 yield b"Example request body" # pragma: nocover

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 624why, one step back
624

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 625why, one step back
625 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 626–627why, one step back
626 with pytest.raises(RequestBodyUnavailable):
627 await client.post(url, data=streaming_body(), auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 628–630why, one step back
628
629630@pytest.mark.asyncio

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 631why, one step back
631async def test_async_auth_reads_response_body() -> None:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 632–635why, one step back
632 """
633 Test that we can read the response body in an auth flow if `requires_response_body`634 is set.635 """

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 636–637why, one step back
636 url = "https://example.org/"
637 auth = ResponseBodyAuth("xyz")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 638–640why, one step back
638 app = App()
639640 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 641why, one step back
641 response = await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 642why, one step back
642

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 643–644why, one step back
643 assert response.status_code == 200
644 assert response.json() == {"auth": '{"auth": "xyz"}'}

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 645–646why, one step back
645
646

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 647–651why, one step back
647def test_sync_auth_reads_response_body() -> None:
648 """649 Test that we can read the response body in an auth flow if `requires_response_body`650 is set.651 """

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 652–653why, one step back
652 url = "https://example.org/"
653 auth = ResponseBodyAuth("xyz")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 654why, one step back
654 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 655why, one step back
655

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 656why, one step back
656 with httpx.Client(transport=MockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 657–658why, one step back
657 response = client.get(url, auth=auth)
658

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 659–660why, one step back
659 assert response.status_code == 200
660 assert response.json() == {"auth": '{"auth": "xyz"}'}

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 661–671why, one step back
661
662663@pytest.mark.asyncio664async def test_async_auth() -> None:665 """666 Test that we can use an auth implementation specific to the async case, to667 support cases that require performing I/O or using concurrency primitives (such668 as checking a disk-based cache or fetching a token from a remote auth server).669 """670 url = "https://example.org/"671 auth = SyncOrAsyncAuth()

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 672why, one step back
672 app = App()

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

line 673why, one step back
673

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 674why, one step back
674 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 675–686why, one step back
675 response = await client.get(url, auth=auth)
676677 assert response.status_code == 200678 assert response.json() == {"auth": "async-auth"}679680681def test_sync_auth() -> None:682 """683 Test that we can use an auth implementation specific to the sync case.684 """685 url = "https://example.org/"686 auth = SyncOrAsyncAuth()

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 687why, one step back
687 app = App()

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

line 688why, one step back
688

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 689why, one step back
689 with httpx.Client(transport=MockTransport(app)) as client:

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 690–693why, one step back
690 response = client.get(url, auth=auth)
691692 assert response.status_code == 200693 assert response.json() == {"auth": "sync-auth"}