Skip to content

Commit

Permalink
chore: fix up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran88 committed Dec 17, 2024
1 parent 82f12fa commit c355dff
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
24 changes: 12 additions & 12 deletions passageidentity/passage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from .openapi_client.models import (
CreateMagicLinkRequest,
CreateUserRequest,
CreateUserArgs,
MagicLinkType,
)

Expand All @@ -28,8 +28,8 @@

from .openapi_client.models import (
AppInfo,
UpdateUserRequest,
UserInfo,
PassageUser,
UpdateUserArgs,
WebAuthnDevices,
)

Expand Down Expand Up @@ -147,14 +147,14 @@ def getApp(self) -> AppInfo | PassageError: # noqa: N802
return client.get_app(self.app_id).app

@typing_extensions.deprecated("Passage.getUser() will be deprecated. Use Passage.user.get() instead.")
def getUser(self, user_id: str) -> UserInfo | PassageError: # noqa: N802
def getUser(self, user_id: str) -> PassageUser | PassageError: # noqa: N802
"""Use Passage API to get info for a user, look up by user ID."""
return self.user.get(user_id)

@typing_extensions.deprecated(
"Passage.getUserByIdentifier() will be deprecated. Use Passage.user.get_by_identifier() instead.",
)
def getUserByIdentifier(self, userIdentifier: str) -> UserInfo | PassageError: # noqa: N802, N803
def getUserByIdentifier(self, userIdentifier: str) -> PassageUser | PassageError: # noqa: N802, N803
"""Use Passage API to get info for a user, look up by user identifier."""
return self.user.get_by_identifier(userIdentifier)

Expand Down Expand Up @@ -212,21 +212,21 @@ def signOut( # noqa: N802
return True

@typing_extensions.deprecated("Passage.activateUser() will be deprecated. Use Passage.user.activate() instead.")
def activateUser(self, user_id: str) -> UserInfo | PassageError: # noqa: N802
def activateUser(self, user_id: str) -> PassageUser | PassageError: # noqa: N802
"""Activate Passage User."""
return self.user.activate(user_id)

@typing_extensions.deprecated("Passage.deactivateUser() will be deprecated. Use Passage.user.deactivate() instead.")
def deactivateUser(self, user_id: str) -> UserInfo | PassageError: # noqa: N802
def deactivateUser(self, user_id: str) -> PassageUser | PassageError: # noqa: N802
"""Deactivate Passage User."""
return self.user.deactivate(user_id)

@typing_extensions.deprecated("Passage.updateUser() will be deprecated. Use Passage.user.update() instead.")
def updateUser( # noqa: N802
self,
user_id: str,
attributes: UpdateUserRequest,
) -> UserInfo | PassageError:
attributes: UpdateUserArgs,
) -> PassageUser | PassageError:
"""Update Passage User."""
return self.user.update(user_id, attributes)

Expand All @@ -239,15 +239,15 @@ def deleteUser(self, user_id: str) -> bool | PassageError: # noqa: N802
@typing_extensions.deprecated("Passage.createUser() will be deprecated. Use Passage.user.create() instead.")
def createUser( # noqa: N802
self,
userAttributes: CreateUserRequest, # noqa: N803
) -> UserInfo | PassageError:
userAttributes: CreateUserArgs, # noqa: N803
) -> PassageUser | PassageError:
"""Create Passage User."""
if not ("phone" in userAttributes or "email" in userAttributes): # type: ignore[dict-item]
msg = "either phone or email must be provided to create the user"
raise PassageError(msg)

user_args = (
cast(CreateUserRequest, CreateUserRequest.from_dict(userAttributes))
cast(CreateUserArgs, CreateUserArgs.from_dict(userAttributes))
if isinstance(userAttributes, dict)
else userAttributes
)
Expand Down
12 changes: 3 additions & 9 deletions passageidentity/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@
UserDevicesApi,
UsersApi,
)
from .openapi_client.models import (
CreateUserRequest,
UpdateUserRequest,
UserInfo,
)

if TYPE_CHECKING:
from .openapi_client.models import (
CreateUserArgs,
PassageUser,
UpdateUserArgs,
WebAuthnDevices,
)

PassageUser = UserInfo
CreateUserArgs = CreateUserRequest
UpdateUserArgs = UpdateUserRequest


class User:
"""User class for handling operations to get and update user information."""
Expand Down
46 changes: 23 additions & 23 deletions tests/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from faker import Faker

from passageidentity.errors import PassageError
from passageidentity.openapi_client.models.update_user_request import UpdateUserRequest
from passageidentity.openapi_client.models.user_info import UserInfo
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 @@ -23,13 +23,13 @@ def test_get_by_identifier_valid_upper_case() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

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

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

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

assert user_by_identifier == user
Expand All @@ -45,21 +45,21 @@ def test_get_by_identifier_user_not_exist() -> None:

def test_get_user_info_valid() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)
user = cast(UserInfo, psg.getUser(PASSAGE_USER_ID))
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(UserInfo, psg.createUser({"email": email})) # type: ignore[arg-type]
new_user = cast(PassageUser, psg.createUser({"email": email})) # type: ignore[arg-type]
assert new_user.email == email

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

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

assert user_by_identifier == user
Expand All @@ -70,13 +70,13 @@ def test_get_user_info_by_identifier_phone_valid() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

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

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

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

assert user_by_identifier == user
Expand All @@ -85,15 +85,15 @@ def test_get_user_info_by_identifier_phone_valid() -> None:

def test_activate_user() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)
user = cast(UserInfo, psg.activateUser(PASSAGE_USER_ID))
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(UserInfo, psg.getUser(PASSAGE_USER_ID))
user = cast(UserInfo, psg.deactivateUser(user.id))
user = cast(PassageUser, psg.getUser(PASSAGE_USER_ID))
user = cast(PassageUser, psg.deactivateUser(user.id))
assert user.status == "inactive"


Expand All @@ -108,10 +108,10 @@ def test_update_user_phone() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

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

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

Expand All @@ -120,20 +120,20 @@ def test_update_user_email() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

email = f.email()
req = UpdateUserRequest(email=email)
user = cast(UserInfo, psg.updateUser(PASSAGE_USER_ID, req))
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(UserInfo, psg.updateUser(PASSAGE_USER_ID, {"email": email, "user_metadata": {"example1": "qwe"}})) # type: ignore[arg-type]
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(UserInfo, psg.updateUser(PASSAGE_USER_ID, {"email": email, "user_metadata": {"example1": "asd"}})) # type: ignore[arg-type]
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]

Expand All @@ -142,7 +142,7 @@ def test_create_user_with_metadata() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

email = f.email()
user = cast(UserInfo, psg.createUser({"email": email, "user_metadata": {"example1": "qwe"}})) # type: ignore[arg-type]
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)
Expand All @@ -152,7 +152,7 @@ def test_create_and_delete_user() -> None:
psg = Passage(PASSAGE_APP_ID, PASSAGE_API_KEY)

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

Expand Down

0 comments on commit c355dff

Please sign in to comment.