Skip to content

Commit

Permalink
test: add more tests to client layer
Browse files Browse the repository at this point in the history
  • Loading branch information
leynier committed Dec 2, 2021
1 parent 26783b5 commit a2ca372
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
80 changes: 80 additions & 0 deletions tests/_async/test_client_with_auto_confirm_enabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ async def test_get_user(client: AsyncGoTrueClient):
assert False, str(e)


@pytest.mark.asyncio
@pytest.mark.depends(on=[test_sign_in.__name__])
async def test_get_session(client: AsyncGoTrueClient):
try:
await client.init_recover()
response = client.session()
assert isinstance(response, Session)
assert response.access_token
assert response.refresh_token
assert response.expires_in
assert response.expires_at
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
@pytest.mark.depends(on=[test_sign_in.__name__])
async def test_update_user(client: AsyncGoTrueClient):
Expand Down Expand Up @@ -250,7 +265,10 @@ async def test_get_user_after_update(client: AsyncGoTrueClient):
@pytest.mark.depends(on=[test_get_user_after_update.__name__])
async def test_sign_out(client: AsyncGoTrueClient):
try:
await client.init_recover()
await client.sign_out()
response = client.session()
assert response is None
except Exception as e:
assert False, str(e)

Expand All @@ -266,6 +284,20 @@ async def test_get_user_after_sign_out(client: AsyncGoTrueClient):
assert False, str(e)


@pytest.mark.asyncio
@pytest.mark.depends(on=[test_sign_out.__name__])
async def test_get_update_user_after_sign_out(client: AsyncGoTrueClient):
expected_error_message = "Not logged in."
try:
await client.init_recover()
await client.update(attributes=UserAttributes(data={"hello": "world"}))
assert False
except ValueError as e:
assert str(e) == expected_error_message
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
@pytest.mark.depends(on=[test_get_user_after_sign_out.__name__])
async def test_sign_in_with_the_wrong_password(client: AsyncGoTrueClient):
Expand All @@ -276,3 +308,51 @@ async def test_sign_in_with_the_wrong_password(client: AsyncGoTrueClient):
assert True
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
async def test_sign_up_with_password_none(client: AsyncGoTrueClient):
expected_error_message = "Password must be defined, can't be None."
try:
await client.sign_up(email=email)
assert False
except ValueError as e:
assert str(e) == expected_error_message
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
async def test_sign_up_with_email_and_phone_none(client: AsyncGoTrueClient):
expected_error_message = "Email or phone must be defined, both can't be None."
try:
await client.sign_up(password=password)
assert False
except ValueError as e:
assert str(e) == expected_error_message
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
async def test_sign_in_with_all_nones(client: AsyncGoTrueClient):
expected_error_message = (
"Email, phone, refresh_token, or provider must be defined, "
"all can't be None."
)
try:
await client.sign_in()
assert False
except ValueError as e:
assert str(e) == expected_error_message
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
async def test_sign_in_with_magic_link(client: AsyncGoTrueClient):
try:
response = await client.sign_in(email=email)
assert response is None
except Exception as e:
assert False, str(e)
80 changes: 80 additions & 0 deletions tests/_sync/test_client_with_auto_confirm_enabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ def test_get_user(client: SyncGoTrueClient):
assert False, str(e)


@pytest.mark.asyncio
@pytest.mark.depends(on=[test_sign_in.__name__])
def test_get_session(client: SyncGoTrueClient):
try:
client.init_recover()
response = client.session()
assert isinstance(response, Session)
assert response.access_token
assert response.refresh_token
assert response.expires_in
assert response.expires_at
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
@pytest.mark.depends(on=[test_sign_in.__name__])
def test_update_user(client: SyncGoTrueClient):
Expand Down Expand Up @@ -244,7 +259,10 @@ def test_get_user_after_update(client: SyncGoTrueClient):
@pytest.mark.depends(on=[test_get_user_after_update.__name__])
def test_sign_out(client: SyncGoTrueClient):
try:
client.init_recover()
client.sign_out()
response = client.session()
assert response is None
except Exception as e:
assert False, str(e)

Expand All @@ -260,6 +278,20 @@ def test_get_user_after_sign_out(client: SyncGoTrueClient):
assert False, str(e)


@pytest.mark.asyncio
@pytest.mark.depends(on=[test_sign_out.__name__])
def test_get_update_user_after_sign_out(client: SyncGoTrueClient):
expected_error_message = "Not logged in."
try:
client.init_recover()
client.update(attributes=UserAttributes(data={"hello": "world"}))
assert False
except ValueError as e:
assert str(e) == expected_error_message
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
@pytest.mark.depends(on=[test_get_user_after_sign_out.__name__])
def test_sign_in_with_the_wrong_password(client: SyncGoTrueClient):
Expand All @@ -270,3 +302,51 @@ def test_sign_in_with_the_wrong_password(client: SyncGoTrueClient):
assert True
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
def test_sign_up_with_password_none(client: SyncGoTrueClient):
expected_error_message = "Password must be defined, can't be None."
try:
client.sign_up(email=email)
assert False
except ValueError as e:
assert str(e) == expected_error_message
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
def test_sign_up_with_email_and_phone_none(client: SyncGoTrueClient):
expected_error_message = "Email or phone must be defined, both can't be None."
try:
client.sign_up(password=password)
assert False
except ValueError as e:
assert str(e) == expected_error_message
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
def test_sign_in_with_all_nones(client: SyncGoTrueClient):
expected_error_message = (
"Email, phone, refresh_token, or provider must be defined, "
"all can't be None."
)
try:
client.sign_in()
assert False
except ValueError as e:
assert str(e) == expected_error_message
except Exception as e:
assert False, str(e)


@pytest.mark.asyncio
def test_sign_in_with_magic_link(client: SyncGoTrueClient):
try:
response = client.sign_in(email=email)
assert response is None
except Exception as e:
assert False, str(e)

0 comments on commit a2ca372

Please sign in to comment.