Skip to content

Commit

Permalink
feat: add X-Client-Info to default headers
Browse files Browse the repository at this point in the history
  • Loading branch information
leynier authored Nov 16, 2021
1 parent 283bd9f commit ec2c893
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 5 additions & 1 deletion gotrue/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import annotations

from gotrue import __version__

GOTRUE_URL = "http://localhost:9999"
AUDIENCE = ""
DEFAULT_HEADERS = {}
DEFAULT_HEADERS = {
"X-Client-Info": f"gotrue-py/{__version__}",
}
EXPIRY_MARGIN = 60 * 1000
STORAGE_KEY = "supabase.auth.token"
COOKIE_OPTIONS = {
Expand Down
11 changes: 10 additions & 1 deletion tests/_async/test_client_with_sign_ups_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from faker import Faker

from gotrue import AsyncGoTrueAPI, AsyncGoTrueClient
from gotrue.constants import COOKIE_OPTIONS
from gotrue.constants import COOKIE_OPTIONS, DEFAULT_HEADERS
from gotrue.exceptions import APIError
from gotrue.types import CookieOptions, LinkType, User, UserAttributes

Expand Down Expand Up @@ -118,3 +118,12 @@ async def test_create_user(auth_admin: AsyncGoTrueAPI):
assert user.email == email2
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
def test_default_headers(client: AsyncGoTrueClient):
"""Test client for existing default headers"""
default_key = "X-Client-Info"
assert default_key in DEFAULT_HEADERS
assert default_key in client.api.headers
assert client.api.headers[default_key] == DEFAULT_HEADERS[default_key]
11 changes: 10 additions & 1 deletion tests/_sync/test_client_with_sign_ups_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from faker import Faker

from gotrue import SyncGoTrueAPI, SyncGoTrueClient
from gotrue.constants import COOKIE_OPTIONS
from gotrue.constants import COOKIE_OPTIONS, DEFAULT_HEADERS
from gotrue.exceptions import APIError
from gotrue.types import CookieOptions, LinkType, User, UserAttributes

Expand Down Expand Up @@ -118,3 +118,12 @@ def test_create_user(auth_admin: SyncGoTrueAPI):
assert user.email == email2
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
def test_default_headers(client: SyncGoTrueClient):
"""Test client for existing default headers"""
default_key = "X-Client-Info"
assert default_key in DEFAULT_HEADERS
assert default_key in client.api.headers
assert client.api.headers[default_key] == DEFAULT_HEADERS[default_key]

0 comments on commit ec2c893

Please sign in to comment.