Skip to content

Commit

Permalink
test: remove tests for deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran88 committed Dec 23, 2024
1 parent 4ac4f0e commit aed30fa
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 207 deletions.
4 changes: 3 additions & 1 deletion passageidentity/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def get_by_identifier(self, identifier: str) -> PassageUser:
raise PassageError.from_response_error(e, msg) from e

if len(users) == 0:
raise PassageError.from_response_error(ApiException(status=404, data=Model404Error(code="user_not_found", error="User not found.")))
raise PassageError.from_response_error(
ApiException(status=404, data=Model404Error(code="user_not_found", error="User not found.")),
)

return self.get(users[0].id)

Expand Down
52 changes: 2 additions & 50 deletions tests/auth_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import os
from typing import cast

import pytest
from dotenv import load_dotenv
from faker import Faker

from passageidentity import PassageError
from passageidentity.openapi_client.models.app_info import AppInfo
from passageidentity.openapi_client.models.magic_link import MagicLink
from passageidentity.passage import Passage

load_dotenv()
Expand All @@ -19,50 +14,7 @@
PASSAGE_AUTH_TOKEN = os.environ.get("PASSAGE_AUTH_TOKEN") or ""


def test_valid_jwt() -> None:
psg = Passage(PASSAGE_APP_ID, auth_strategy=Passage.HEADER_AUTH)
user = psg.authenticateJWT(PASSAGE_AUTH_TOKEN)
assert user == PASSAGE_USER_ID


def test_invalid_jwt() -> None:
psg = Passage(PASSAGE_APP_ID, auth_strategy=Passage.HEADER_AUTH)
with pytest.raises(PassageError):
psg.authenticateJWT("invalid_token")


def test_validate_jwt() -> None:
psg = Passage(PASSAGE_APP_ID, auth_strategy=Passage.HEADER_AUTH)
user = psg.validateJwt(PASSAGE_AUTH_TOKEN)
assert user == PASSAGE_USER_ID


def test_get_app() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)
app = cast(AppInfo, psg.getApp())
assert app.id == PASSAGE_APP_ID


def test_create_magic_link() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)
magic_link = cast(
MagicLink,
psg.createMagicLink(
{
"email": "[email protected]",
"channel": "email",
"ttl": 12,
}, # type: ignore[arg-type]
),
)
assert magic_link.identifier == "[email protected]"
assert magic_link.ttl == 12


def test_smart_link_valid() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

email = f.email()
magic_link = cast(MagicLink, psg.createMagicLink({"email": email})) # type: ignore[arg-type]
assert magic_link.identifier == email
assert not magic_link.activated
user = psg.auth.validate_jwt(PASSAGE_AUTH_TOKEN)
assert user == PASSAGE_USER_ID
10 changes: 0 additions & 10 deletions tests/errors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ def test_error_with_all_values() -> None:
error = PassageError("some message", 400, "Bad Request", {"error": "some error", "code": "some_error_code"})
assert error.message == "some message"
assert error.status_code == 400
assert error.status_text == "Bad Request"
assert error.error == "some error"
assert error.error_code == "some_error_code"


def test_error_with_only_message() -> None:
error = PassageError("some message")
assert error.message == "some message"
assert error.status_code is None
assert error.status_text is None
assert error.error is None
assert error.error_code is None


Expand All @@ -40,8 +36,6 @@ def test_from_response_error() -> None:
assert error.message == "some message: some error"
assert error.status_code == 400
assert error.error_code == "invalid_request"
assert error.status_text is None
assert error.error is None


def test_from_response_error_without_message() -> None:
Expand All @@ -54,8 +48,6 @@ def test_from_response_error_without_message() -> None:
assert error.message == "some error"
assert error.status_code == 400
assert error.error_code == "invalid_request"
assert error.status_text is None
assert error.error is None


def test_from_response_error_without_data() -> None:
Expand All @@ -69,5 +61,3 @@ def test_from_response_error_without_data() -> None:
assert error.message == "some error"
assert error.status_code == 400
assert error.error_code is None
assert error.status_text is None
assert error.error is None
146 changes: 0 additions & 146 deletions tests/user_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
from typing import cast

import pytest
from dotenv import load_dotenv
from faker import Faker

from passageidentity.errors import PassageError
from passageidentity.openapi_client.models.passage_user import PassageUser
from passageidentity.openapi_client.models.update_user_args import UpdateUserArgs
from passageidentity.passage import Passage

load_dotenv()
Expand All @@ -19,151 +16,8 @@
PASSAGE_AUTH_TOKEN = os.environ.get("PASSAGE_AUTH_TOKEN") or ""


def test_get_by_identifier_valid_upper_case() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

email = f.email()
new_user = cast(PassageUser, psg.createUser({"email": email})) # type: ignore[arg-type]
assert new_user.email == email

user_by_identifier = cast(PassageUser, psg.getUserByIdentifier(email.upper()))
assert user_by_identifier.id == new_user.id

user = cast(PassageUser, psg.user.get(new_user.id))
assert user.id == new_user.id

assert user_by_identifier == user
assert psg.user.delete(new_user.id) is None


def test_get_by_identifier_user_not_exist() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

with pytest.raises(PassageError, match="User not found."):
psg.user.get_by_identifier("[email protected]")


def test_get_user_info_valid() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)
user = cast(PassageUser, psg.getUser(PASSAGE_USER_ID))
assert user.id == PASSAGE_USER_ID


def test_get_user_info_by_identifier_valid() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

email = f.email()
new_user = cast(PassageUser, psg.createUser({"email": email})) # type: ignore[arg-type]
assert new_user.email == email

user_by_identifier = cast(PassageUser, psg.getUserByIdentifier(email))
assert user_by_identifier.id == new_user.id

user = cast(PassageUser, psg.getUser(new_user.id))
assert user.id == new_user.id

assert user_by_identifier == user
assert psg.deleteUser(new_user.id)


def test_get_user_info_by_identifier_phone_valid() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

phone = "+15005550030"
new_user = cast(PassageUser, psg.createUser({"phone": phone})) # type: ignore[arg-type]
assert new_user.phone == phone

user_by_identifier = cast(PassageUser, psg.getUserByIdentifier(phone))
assert user_by_identifier.id == new_user.id

user = cast(PassageUser, psg.getUser(new_user.id))
assert user.id == new_user.id

assert user_by_identifier == user
assert psg.deleteUser(new_user.id)


def test_activate_user() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)
user = cast(PassageUser, psg.activateUser(PASSAGE_USER_ID))
assert user.status == "active"


def test_deactivate_user() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

user = cast(PassageUser, psg.getUser(PASSAGE_USER_ID))
user = cast(PassageUser, psg.deactivateUser(user.id))
assert user.status == "inactive"


def test_list_user_devices() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

devices = cast(list, psg.listUserDevices(PASSAGE_USER_ID))
assert len(devices) == 2


def test_update_user_phone() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

phone = "+15005550021"
new_user = cast(PassageUser, psg.createUser({"phone": phone})) # type: ignore[arg-type]

phone = "+15005550022"
user = cast(PassageUser, psg.updateUser(new_user.id, {"phone": phone})) # type: ignore[arg-type]
assert user.phone == phone
assert psg.deleteUser(new_user.id)


def test_update_user_email() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

email = f.email()
req = UpdateUserArgs(email=email)
user = cast(PassageUser, psg.updateUser(PASSAGE_USER_ID, req))
assert user.email == email


def test_update_user_with_metadata() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

email = f.email()
user = cast(PassageUser, psg.updateUser(PASSAGE_USER_ID, {"email": email, "user_metadata": {"example1": "qwe"}})) # type: ignore[arg-type]
assert user.email == email
assert user.user_metadata["example1"] == "qwe" # type: ignore[index]

user = cast(PassageUser, psg.updateUser(PASSAGE_USER_ID, {"email": email, "user_metadata": {"example1": "asd"}})) # type: ignore[arg-type]
assert user.email == email
assert user.user_metadata["example1"] == "asd" # type: ignore[index]


def test_create_user_with_metadata() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

email = f.email()
user = cast(PassageUser, psg.createUser({"email": email, "user_metadata": {"example1": "qwe"}})) # type: ignore[arg-type]
assert user.email == email
assert user.user_metadata["example1"] == "qwe" # type: ignore[index]
assert psg.deleteUser(user.id)


def test_create_and_delete_user() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

email = f.email()
new_user = cast(PassageUser, psg.createUser({"email": email})) # type: ignore[arg-type]
assert new_user.email == email
assert psg.deleteUser(new_user.id)


def test_sign_out() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

assert psg.signOut(PASSAGE_USER_ID)


def test_revoke_user_refresh_tokens() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

assert psg.revokeUserRefreshTokens(PASSAGE_USER_ID)

0 comments on commit aed30fa

Please sign in to comment.