Skip to content

Commit dd90a57

Browse files
authored
Update tests for httpx v0.16.x (#4)
1 parent cac7fe2 commit dd90a57

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

.github/workflows/ci-python.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: [3.7, 3.8]
10+
python-version: [3.7, 3.8, 3.9]
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v2

postgrest_py/client.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Union
22

33
from deprecation import deprecated
4-
from httpx import AsyncClient, Response
4+
from httpx import AsyncClient, BasicAuth, Response
55

66
from postgrest_py.__version__ import __version__
77
from postgrest_py.request_builder import RequestBuilder
@@ -33,11 +33,11 @@ def auth(
3333
token: str,
3434
*,
3535
username: Union[str, bytes] = None,
36-
password: Union[str, bytes] = None,
36+
password: Union[str, bytes] = "",
3737
):
3838
"""Authenticate the client with either bearer token or basic authentication."""
3939
if username:
40-
self.session.auth = (username, password)
40+
self.session.auth = BasicAuth(username, password)
4141
else:
4242
self.session.headers["Authorization"] = f"Bearer {token}"
4343
return self

postgrest_py/request_builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def filter(self, column: str, operator: str, criteria: str):
6060
operator = f"not.{operator}"
6161
key, val = sanitize_param(column), f"{operator}.{criteria}"
6262
if key in self.session.params:
63-
self.session.params.update({key: self.session.params.getlist(key) + [val]})
63+
self.session.params.update({key: self.session.params.get_list(key) + [val]})
6464
else:
6565
self.session.params[key] = val
6666
return self

tests/test_client.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from httpx import Headers
2+
from httpx import BasicAuth
33
from postgrest_py import PostgrestClient
44

55

@@ -14,14 +14,13 @@ def test_constructor(postgrest_client):
1414
session = postgrest_client.session
1515

1616
assert session.base_url == "https://example.com"
17-
assert session.headers == Headers(
18-
{
19-
"accept": "application/json",
20-
"content-type": "application/json",
21-
"accept-profile": "public",
22-
"content-profile": "public",
23-
}
24-
)
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()
2524

2625

2726
class TestAuth:
@@ -37,7 +36,7 @@ def test_auth_basic(self, postgrest_client):
3736
postgrest_client.auth(None, username="admin", password="s3cr3t")
3837
session = postgrest_client.session
3938

40-
assert session.auth == ("admin", "s3cr3t")
39+
assert session.auth._auth_header == BasicAuth("admin", "s3cr3t")._auth_header
4140

4241

4342
@pytest.mark.asyncio

0 commit comments

Comments
 (0)