1
1
import pytest
2
- from httpx import BasicAuth
2
+ from httpx import BasicAuth , Headers
3
3
from postgrest_py import PostgrestClient
4
4
5
5
@@ -9,33 +9,54 @@ async def postgrest_client():
9
9
yield client
10
10
11
11
12
- @pytest .mark .asyncio
13
- def test_constructor (postgrest_client ):
14
- session = postgrest_client .session
12
+ class TestConstructor :
13
+ @pytest .mark .asyncio
14
+ def test_simple (self , postgrest_client : PostgrestClient ):
15
+ session = postgrest_client .session
15
16
16
- assert session .base_url == "https://example.com"
17
- default_headers = {
18
- "accept" : "application/json" ,
19
- "content-type" : "application/json" ,
20
- "accept-profile" : "public" ,
21
- "content-profile" : "public" ,
22
- }
23
- assert default_headers .items () <= session .headers .items ()
17
+ assert session .base_url == "https://example.com"
18
+ headers = Headers (
19
+ {
20
+ "Accept" : "application/json" ,
21
+ "Content-Type" : "application/json" ,
22
+ "Accept-Profile" : "public" ,
23
+ "Content-Profile" : "public" ,
24
+ }
25
+ )
26
+ assert session .headers .items () >= headers .items ()
27
+
28
+ @pytest .mark .asyncio
29
+ async def test_custom_headers (self ):
30
+ async with PostgrestClient (
31
+ "https://example.com" , schema = "pub" , headers = {"Custom-Header" : "value" }
32
+ ) as client :
33
+ session = client .session
34
+
35
+ assert session .base_url == "https://example.com"
36
+ headers = Headers (
37
+ {
38
+ "Accept-Profile" : "pub" ,
39
+ "Content-Profile" : "pub" ,
40
+ "Custom-Header" : "value" ,
41
+ }
42
+ )
43
+ assert session .headers .items () >= headers .items ()
24
44
25
45
26
46
class TestAuth :
27
47
@pytest .mark .asyncio
28
- def test_auth_token (self , postgrest_client ):
48
+ def test_auth_token (self , postgrest_client : PostgrestClient ):
29
49
postgrest_client .auth ("s3cr3t" )
30
50
session = postgrest_client .session
31
51
32
52
assert session .headers ["Authorization" ] == "Bearer s3cr3t"
33
53
34
54
@pytest .mark .asyncio
35
- def test_auth_basic (self , postgrest_client ):
55
+ def test_auth_basic (self , postgrest_client : PostgrestClient ):
36
56
postgrest_client .auth (None , username = "admin" , password = "s3cr3t" )
37
57
session = postgrest_client .session
38
58
59
+ assert isinstance (session .auth , BasicAuth )
39
60
assert session .auth ._auth_header == BasicAuth ("admin" , "s3cr3t" )._auth_header
40
61
41
62
0 commit comments