1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
import unittest
from unittest import mock
from ...authentication.passwordless import Passwordless
class TestPasswordless(unittest.TestCase):
@mock.patch("auth0.rest.RestClient.post")
def test_send_email(self, mock_post):
p = Passwordless("my.domain.com", "cid")
p.email(email="a@b.com", send="snd")
args, kwargs = mock_post.call_args
self.assertEqual(args[0], "https://my.domain.com/passwordless/start")
self.assertEqual(
kwargs["data"],
{
"client_id": "cid",
"email": "a@b.com",
"send": "snd",
"connection": "email",
},
)
@mock.patch("auth0.rest.RestClient.post")
def test_send_email_with_auth_params(self, mock_post):
p = Passwordless("my.domain.com", "cid")
p.email(email="a@b.com", send="snd", auth_params={"a": "b"})
args, kwargs = mock_post.call_args
self.assertEqual(args[0], "https://my.domain.com/passwordless/start")
self.assertEqual(
kwargs["data"],
{
"client_id": "cid",
"email": "a@b.com",
"send": "snd",
"authParams": {"a": "b"},
"connection": "email",
},
)
@mock.patch("auth0.rest.RestClient.post")
def test_send_email_with_client_secret(self, mock_post):
p = Passwordless("my.domain.com", "cid", client_secret="csecret")
p.email(email="a@b.com", send="snd")
args, kwargs = mock_post.call_args
self.assertEqual(args[0], "https://my.domain.com/passwordless/start")
self.assertEqual(
kwargs["data"],
{
"client_id": "cid",
"client_secret": "csecret",
"email": "a@b.com",
"send": "snd",
"connection": "email",
},
)
@mock.patch("auth0.rest.RestClient.post")
def test_send_sms(self, mock_post):
p = Passwordless("my.domain.com", "cid")
p.sms(phone_number="123456")
args, kwargs = mock_post.call_args
self.assertEqual(args[0], "https://my.domain.com/passwordless/start")
self.assertEqual(
kwargs["data"],
{
"client_id": "cid",
"phone_number": "123456",
"connection": "sms",
},
)
@mock.patch("auth0.rest.RestClient.post")
def test_send_sms_with_client_secret(self, mock_post):
p = Passwordless("my.domain.com", "cid", client_secret="csecret")
p.sms(phone_number="123456")
args, kwargs = mock_post.call_args
self.assertEqual(args[0], "https://my.domain.com/passwordless/start")
self.assertEqual(
kwargs["data"],
{
"client_id": "cid",
"client_secret": "csecret",
"phone_number": "123456",
"connection": "sms",
},
)
|