-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_client_auth.py
More file actions
50 lines (44 loc) · 1.45 KB
/
test_api_client_auth.py
File metadata and controls
50 lines (44 loc) · 1.45 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import requests_mock
from .utils import get_test_client
from flareio.auth import _EmptyAuth
from flareio.auth import _StaticHeadersAuth
def test_custom_auth_empty() -> None:
client = get_test_client(
authenticated=False,
_auth=_EmptyAuth(),
)
with requests_mock.Mocker() as mocker:
mocker.register_uri(
"POST",
"https://api.flare.io/hello-post",
status_code=200,
)
client.post(
"https://api.flare.io/hello-post",
json={"foo": "bar"},
)
assert not mocker.last_request.headers.get("Authorization")
def test_custom_auth_static() -> None:
client = get_test_client(
authenticated=False,
_auth=_StaticHeadersAuth(
headers={
"first-header": "first-value",
"Authorization": "auth-value",
}
),
)
with requests_mock.Mocker() as mocker:
mocker.register_uri(
"POST",
"https://api.flare.io/hello-post",
status_code=200,
)
client.post(
"https://api.flare.io/hello-post",
json={"foo": "bar"},
headers={"second-header": "second-value"},
)
assert mocker.last_request.headers["Authorization"] == "auth-value"
assert mocker.last_request.headers["first-header"] == "first-value"
assert mocker.last_request.headers["second-header"] == "second-value"