diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ff6993e..24dce4fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: [3.8, 3.9, "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11"] runs-on: ${{ matrix.os }} steps: - name: Clone Repository diff --git a/supabase/client.py b/supabase/client.py index 73182832..5870bcc4 100644 --- a/supabase/client.py +++ b/supabase/client.py @@ -59,12 +59,12 @@ def __init__( self.supabase_url = supabase_url self.supabase_key = supabase_key options.headers.update(self._get_auth_headers()) - self.rest_url: str = f"{supabase_url}/rest/v1" - self.realtime_url: str = f"{supabase_url}/realtime/v1".replace("http", "ws") - self.auth_url: str = f"{supabase_url}/auth/v1" + self.rest_url = f"{supabase_url}/rest/v1" + self.realtime_url = f"{supabase_url}/realtime/v1".replace("http", "ws") + self.auth_url = f"{supabase_url}/auth/v1" self.storage_url = f"{supabase_url}/storage/v1" self.functions_url = f"{supabase_url}/functions/v1" - self.schema: str = options.schema + self.schema = options.schema # Instantiate clients. self.auth = self._init_supabase_auth_client( diff --git a/supabase/lib/auth_client.py b/supabase/lib/auth_client.py index 2e091294..10800a52 100644 --- a/supabase/lib/auth_client.py +++ b/supabase/lib/auth_client.py @@ -1,4 +1,4 @@ -from typing import Dict, Union +from typing import Dict, Optional from gotrue import SyncGoTrueClient, SyncMemoryStorage, SyncSupportedStorage @@ -18,14 +18,17 @@ def __init__( self, *, url: str, - headers: Dict[str, str] = {}, - storage_key: Union[str, None] = None, + headers: Optional[Dict[str, str]] = None, + storage_key: Optional[str] = None, auto_refresh_token: bool = True, persist_session: bool = True, storage: SyncSupportedStorage = SyncMemoryStorage(), - http_client: Union[SyncClient, None] = None, + http_client: Optional[SyncClient] = None, ): """Instantiate SupabaseAuthClient instance.""" + if headers is None: + headers = {} + SyncGoTrueClient.__init__( self, url=url, diff --git a/tests/test_client_options.py b/tests/test_client_options.py index 3a637e5e..75361722 100644 --- a/tests/test_client_options.py +++ b/tests/test_client_options.py @@ -3,41 +3,41 @@ from supabase.lib.client_options import ClientOptions -def test__client_options__replace__returns_updated_options(): - storage = SyncMemoryStorage() - storage.set_item("key", "value") - options = ClientOptions( - schema="schema", - headers={"key": "value"}, - auto_refresh_token=False, - persist_session=False, - storage=storage, - realtime={"key": "value"}, - ) - - actual = options.replace(schema="new schema") - expected = ClientOptions( - schema="new schema", - headers={"key": "value"}, - auto_refresh_token=False, - persist_session=False, - storage=storage, - realtime={"key": "value"}, - ) - - assert actual == expected - - -def test__client_options__replace__updates_only_new_options(): - # Arrange - storage = SyncMemoryStorage() - storage.set_item("key", "value") - options = ClientOptions(storage=storage) - new_options = options.replace() - - # Act - new_options.storage.set_item("key", "new_value") - - # Assert - assert options.storage.get_item("key") == "new_value" - assert new_options.storage.get_item("key") == "new_value" +class TestClientOptions: + def test_replace_returns_updated_options(self): + storage = SyncMemoryStorage() + storage.set_item("key", "value") + options = ClientOptions( + schema="schema", + headers={"key": "value"}, + auto_refresh_token=False, + persist_session=False, + storage=storage, + realtime={"key": "value"}, + ) + + actual = options.replace(schema="new schema") + expected = ClientOptions( + schema="new schema", + headers={"key": "value"}, + auto_refresh_token=False, + persist_session=False, + storage=storage, + realtime={"key": "value"}, + ) + + assert actual == expected + + def test_replace_updates_only_new_options(self): + # Arrange + storage = SyncMemoryStorage() + storage.set_item("key", "value") + options = ClientOptions(storage=storage) + new_options = options.replace() + + # Act + new_options.storage.set_item("key", "new_value") + + # Assert + assert options.storage.get_item("key") == "new_value" + assert new_options.storage.get_item("key") == "new_value"