From aed30fa7eda76b7f81a533695785fa65a4fced81 Mon Sep 17 00:00:00 2001 From: Chris Tran Date: Mon, 23 Dec 2024 14:34:00 -0600 Subject: [PATCH] test: remove tests for deprecated code --- passageidentity/user.py | 4 +- tests/auth_test.py | 52 +------------- tests/errors_test.py | 10 --- tests/user_test.py | 146 ---------------------------------------- 4 files changed, 5 insertions(+), 207 deletions(-) diff --git a/passageidentity/user.py b/passageidentity/user.py index e620d2b..0f5b11a 100644 --- a/passageidentity/user.py +++ b/passageidentity/user.py @@ -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) diff --git a/tests/auth_test.py b/tests/auth_test.py index 788e893..2878191 100644 --- a/tests/auth_test.py +++ b/tests/auth_test.py @@ -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() @@ -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": "chris@passage.id", - "channel": "email", - "ttl": 12, - }, # type: ignore[arg-type] - ), - ) - assert magic_link.identifier == "chris@passage.id" - 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 diff --git a/tests/errors_test.py b/tests/errors_test.py index b87730c..84bd8cd 100644 --- a/tests/errors_test.py +++ b/tests/errors_test.py @@ -16,8 +16,6 @@ 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" @@ -25,8 +23,6 @@ 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 @@ -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: @@ -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: @@ -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 diff --git a/tests/user_test.py b/tests/user_test.py index 782e950..94de714 100644 --- a/tests/user_test.py +++ b/tests/user_test.py @@ -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() @@ -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("error@passage.id") - - -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)