Skip to content

Commit

Permalink
feat: generate tests for sync client
Browse files Browse the repository at this point in the history
  • Loading branch information
leynier committed Oct 18, 2021
1 parent b3cba71 commit 46373e4
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.7, 3.8, 3.9]
# python-version: [3.7, 3.8, 3.9] # TODO
python-version: [3.7]
runs-on: ${{ matrix.os }}
# TODO(fedden): We need to discuss these steps: We could just use a test-supabase instance or we could update the docker image and use that for the tests.
steps:
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ build_sync:
if [ -d "build" ]; then rm -r "build"; fi
python build_sync.py build
if [ -d "gotrue/_sync" ]; then rm -r "gotrue/_sync"; fi
if [ -d "tests/_sync" ]; then rm -r "tests/_sync"; fi
cp -r "build/lib/gotrue/_sync" "gotrue/_sync"
cp -r "build/lib/tests/_sync" "tests/_sync"
rm -r "build"

install:
Expand Down
3 changes: 1 addition & 2 deletions build_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from unasync import cmdclass_build_py

setup(
packages=find_packages(exclude=["tests"]),
# package_dir={"": "gotrue"},
packages=find_packages(),
cmdclass={"build_py": cmdclass_build_py()}, # type: ignore
)
Empty file added tests/_async/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
Empty file added tests/_sync/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions tests/_sync/test_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest

from gotrue import SyncGoTrueClient
from gotrue.common.types import Provider

client = SyncGoTrueClient(auto_refresh_token=False, persist_session=False)


@pytest.mark.asyncio
def test_sign_in_with_provider():
response = client.sign_in(provider=Provider.google)
assert isinstance(response, str)


@pytest.mark.asyncio
def test_sign_in_with_provider_can_append_a_redirect_url():
response = client.sign_in(
provider=Provider.google,
redirect_to="https://localhost:9000/welcome",
)
assert isinstance(response, str)


@pytest.mark.asyncio
def test_sign_in_with_provider_can_append_scopes():
response = client.sign_in(provider=Provider.google, scopes="repo")
assert isinstance(response, str)


@pytest.mark.asyncio
def test_sign_in_with_provider_can_append_multiple_options():
response = client.sign_in(
provider=Provider.google,
redirect_to="https://localhost:9000/welcome",
scopes="repo",
)
assert isinstance(response, str)
17 changes: 17 additions & 0 deletions tests/_sync/test_subscriptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from gotrue import SyncGoTrueClient

client = SyncGoTrueClient()

subscription = client.on_auth_state_change(lambda _, __: print("Auth state changed"))


def test_subscribe_a_listener():
assert len(client.state_change_emitters)


@pytest.mark.depends(on=[test_subscribe_a_listener.__name__])
def test_unsubscribe_a_listener():
subscription.unsubscribe()
assert not len(client.state_change_emitters)

0 comments on commit 46373e4

Please sign in to comment.