forked from replicate/replicate-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_client.py
More file actions
33 lines (27 loc) · 775 Bytes
/
Copy pathtest_client.py
File metadata and controls
33 lines (27 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
from unittest import mock
import httpx
import pytest
import respx
@pytest.mark.asyncio
async def test_authorization_when_setting_environ_after_import():
import replicate
router = respx.Router()
router.route(
method="GET",
url="https://api.replicate.com/",
headers={"Authorization": "Token test-set-after-import"},
).mock(
return_value=httpx.Response(
200,
json={},
)
)
token = "test-set-after-import" # noqa: S105
with mock.patch.dict(
os.environ,
{"REPLICATE_API_TOKEN": token},
):
client = replicate.Client(transport=httpx.MockTransport(router.handler))
resp = client._request("GET", "/")
assert resp.status_code == 200