When netrc auth is being used and a request is made to a host that is in the netrc file, then the relevant credentials should be applied.
()
| 235 | |
| 236 | |
| 237 | def test_netrc_auth_credentials_exist() -> None: |
| 238 | """ |
| 239 | When netrc auth is being used and a request is made to a host that is |
| 240 | in the netrc file, then the relevant credentials should be applied. |
| 241 | """ |
| 242 | netrc_file = str(FIXTURES_DIR / ".netrc") |
| 243 | url = "http://netrcexample.org" |
| 244 | app = App() |
| 245 | auth = httpx.NetRCAuth(netrc_file) |
| 246 | |
| 247 | with httpx.Client(transport=httpx.MockTransport(app), auth=auth) as client: |
| 248 | response = client.get(url) |
| 249 | |
| 250 | assert response.status_code == 200 |
| 251 | assert response.json() == { |
| 252 | "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk" |
| 253 | } |
| 254 | |
| 255 | |
| 256 | def test_netrc_auth_credentials_do_not_exist() -> None: |