Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set localhost as default base_url (instead of prod link) #88

Merged
merged 10 commits into from
Nov 28, 2022
6 changes: 5 additions & 1 deletion descope/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import sys
from enum import Enum

from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT, AuthException

DEFAULT_BASE_URL = "https://api.descope.com"
if "unittest" in sys.modules:
DEFAULT_BASE_URL = "http://127.0.0.1"
else:
DEFAULT_BASE_URL = "https://api.descope.com" # pragma: no cover

PHONE_REGEX = """^(?:(?:\\(?(?:00|\\+)([1-4]\\d\\d|[1-9]\\d?)\\)?)?[\\-\\.\\ \\\\/]?)?((?:\\(?\\d{1,}\\)?[\\-\\.\\ \\\\/]?){0,})(?:[\\-\\.\\ \\\\/]?(?:#|ext\\.?|extension|x)[\\-\\.\\ \\\\/]?(\\d+))?$"""

Expand Down
73 changes: 37 additions & 36 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 0 additions & 37 deletions tests/test_magiclink.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,6 @@ def test_sign_in(self):
magiclink = MagicLink(Auth(self.dummy_project_id, self.public_key_dict))

# Test failed flows
self.assertRaises(
AuthException,
magiclink.sign_in,
DeliveryMethod.EMAIL,
"dummy@dummy",
"http://test.me",
)
self.assertRaises(
AuthException,
magiclink.sign_in,
DeliveryMethod.EMAIL,
"",
"http://test.me",
)
self.assertRaises(
AuthException,
magiclink.sign_in,
Expand Down Expand Up @@ -176,22 +162,6 @@ def test_sign_up(self):
magiclink = MagicLink(Auth(self.dummy_project_id, self.public_key_dict))

# Test failed flows
self.assertRaises(
AuthException,
magiclink.sign_up,
DeliveryMethod.EMAIL,
"dummy@dummy",
"http://test.me",
signup_user_details,
)
self.assertRaises(
AuthException,
magiclink.sign_up,
DeliveryMethod.EMAIL,
"",
"http://test.me",
signup_user_details,
)
self.assertRaises(
AuthException,
magiclink.sign_up,
Expand Down Expand Up @@ -247,13 +217,6 @@ def test_sign_up_or_in(self):
magiclink = MagicLink(Auth(self.dummy_project_id, self.public_key_dict))

# Test failed flows
self.assertRaises(
AuthException,
magiclink.sign_up_or_in,
DeliveryMethod.EMAIL,
"dummy@dummy",
"http://test.me",
)

with patch("requests.post") as mock_post:
mock_post.return_value.ok = False
Expand Down
4 changes: 2 additions & 2 deletions tests/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def test_exchange_token(self):
self.assertRaises(AuthException, oauth.exchange_token, "")
self.assertRaises(AuthException, oauth.exchange_token, None)

with patch("requests.get") as mock_get:
mock_get.return_value.ok = False
with patch("requests.post") as mock_post:
guyp-descope marked this conversation as resolved.
Show resolved Hide resolved
mock_post.return_value.ok = False
self.assertRaises(AuthException, oauth.exchange_token, "c1")

# Test success flow
Expand Down
28 changes: 13 additions & 15 deletions tests/test_otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ def test_compose_update_user_email_body(self):
)

def test_sign_up(self):
invalid_signup_user_details = {
"username": "jhon",
"name": "john",
"phone": "972525555555",
"email": "dummy@dummy",
}
signup_user_details = {
"username": "jhon",
"name": "john",
Expand All @@ -105,21 +111,23 @@ def test_sign_up(self):
client.otp.sign_up,
DeliveryMethod.EMAIL,
"dummy@dummy",
signup_user_details,
invalid_signup_user_details,
)
invalid_signup_user_details["email"] = "[email protected]" # set valid mail
invalid_signup_user_details["phone"] = "aaaaaaaa" # set invalid phone
self.assertRaises(
AuthException,
client.otp.sign_up,
DeliveryMethod.EMAIL,
"",
signup_user_details,
invalid_signup_user_details,
)
self.assertRaises(
AuthException,
client.otp.sign_up,
DeliveryMethod.EMAIL,
None,
signup_user_details,
DeliveryMethod.PHONE,
"[email protected]",
invalid_signup_user_details,
)

with patch("requests.post") as mock_post:
Expand Down Expand Up @@ -167,9 +175,6 @@ def test_sign_in(self):
client = DescopeClient(self.dummy_project_id, self.public_key_dict)

# Test failed flows
self.assertRaises(
AuthException, client.otp.sign_in, DeliveryMethod.EMAIL, "dummy@dummy"
)
self.assertRaises(AuthException, client.otp.sign_in, DeliveryMethod.EMAIL, "")
self.assertRaises(AuthException, client.otp.sign_in, DeliveryMethod.EMAIL, None)

Expand Down Expand Up @@ -225,13 +230,6 @@ def test_verify_code(self):

client = DescopeClient(self.dummy_project_id, self.public_key_dict)

self.assertRaises(
AuthException,
client.otp.verify_code,
DeliveryMethod.EMAIL,
"dummy@dummy",
code,
)
self.assertRaises(
AuthException, client.otp.verify_code, DeliveryMethod.EMAIL, "", code
)
Expand Down
Loading