From c355dff6f8903f54e7abe1e66b918288aba149b4 Mon Sep 17 00:00:00 2001 From: Chris Tran Date: Tue, 17 Dec 2024 13:31:45 -0600 Subject: [PATCH] chore: fix up imports --- passageidentity/passage.py | 24 ++++++++++---------- passageidentity/user.py | 12 +++------- tests/user_test.py | 46 +++++++++++++++++++------------------- 3 files changed, 38 insertions(+), 44 deletions(-) diff --git a/passageidentity/passage.py b/passageidentity/passage.py index a721593..b164709 100644 --- a/passageidentity/passage.py +++ b/passageidentity/passage.py @@ -19,7 +19,7 @@ ) from .openapi_client.models import ( CreateMagicLinkRequest, - CreateUserRequest, + CreateUserArgs, MagicLinkType, ) @@ -28,8 +28,8 @@ from .openapi_client.models import ( AppInfo, - UpdateUserRequest, - UserInfo, + PassageUser, + UpdateUserArgs, WebAuthnDevices, ) @@ -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) @@ -212,12 +212,12 @@ 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) @@ -225,8 +225,8 @@ def deactivateUser(self, user_id: str) -> UserInfo | PassageError: # noqa: N802 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) @@ -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 ) diff --git a/passageidentity/user.py b/passageidentity/user.py index 4fa9a98..d5996c3 100644 --- a/passageidentity/user.py +++ b/passageidentity/user.py @@ -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.""" diff --git a/tests/user_test.py b/tests/user_test.py index 2abbdb2..782e950 100644 --- a/tests/user_test.py +++ b/tests/user_test.py @@ -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() @@ -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 @@ -45,7 +45,7 @@ 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 @@ -53,13 +53,13 @@ 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 @@ -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 @@ -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" @@ -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) @@ -120,8 +120,8 @@ 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 @@ -129,11 +129,11 @@ 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] @@ -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) @@ -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)