| 1 |
import unittest |
| 2 |
from unittest import mock |
| 3 |
|
| 4 |
from auth0.authentication.database import Database |
| 5 |
|
| 6 |
|
| 7 |
class TestDatabase(unittest.TestCase): |
| 8 |
@mock.patch("auth0.authentication.rest.RestClient.post") |
| 9 |
def test_signup(self, mock_post): |
| 10 |
d = Database("my.domain.com", "cid") |
| 11 |
|
| 12 |
|
| 13 |
d.signup(email="[email protected]", password="pswd", connection="conn") |
| 14 |
|
| 15 |
args, kwargs = mock_post.call_args |
| 16 |
|
| 17 |
self.assertEqual(args[0], "https://my.domain.com/dbconnections/signup") |
| 18 |
self.assertEqual( |
| 19 |
kwargs["data"], |
| 20 |
{ |
| 21 |
"client_id": "cid", |
| 22 |
"email": "[email protected]", |
| 23 |
"password": "pswd", |
| 24 |
"connection": "conn", |
| 25 |
}, |
| 26 |
) |
| 27 |
|
| 28 |
|
| 29 |
sample_meta = {"hobby": "surfing", "preference": {"color": "pink"}} |
| 30 |
d.signup( |
| 31 |
email="[email protected]", |
| 32 |
password="pswd", |
| 33 |
connection="conn", |
| 34 |
username="usr", |
| 35 |
user_metadata=sample_meta, |
| 36 |
given_name="john", |
| 37 |
family_name="doe", |
| 38 |
name="john doe", |
| 39 |
nickname="johnny", |
| 40 |
picture="avatars.com/john-doe", |
| 41 |
) |
| 42 |
|
| 43 |
args, kwargs = mock_post.call_args |
| 44 |
|
| 45 |
self.assertEqual(args[0], "https://my.domain.com/dbconnections/signup") |
| 46 |
self.assertEqual( |
| 47 |
kwargs["data"], |
| 48 |
{ |
| 49 |
"client_id": "cid", |
| 50 |
"email": "[email protected]", |
| 51 |
"password": "pswd", |
| 52 |
"connection": "conn", |
| 53 |
"username": "usr", |
| 54 |
"user_metadata": sample_meta, |
| 55 |
"given_name": "john", |
| 56 |
"family_name": "doe", |
| 57 |
"name": "john doe", |
| 58 |
"nickname": "johnny", |
| 59 |
"picture": "avatars.com/john-doe", |
| 60 |
}, |
| 61 |
) |
| 62 |
|
| 63 |
@mock.patch("auth0.authentication.rest.RestClient.post") |
| 64 |
def test_change_password(self, mock_post): |
| 65 |
d = Database("my.domain.com", "cid") |
| 66 |
|
| 67 |
|
| 68 |
d.change_password(email="[email protected]", password="pswd", connection="conn") |
| 69 |
|
| 70 |
args, kwargs = mock_post.call_args |
| 71 |
|
| 72 |
self.assertEqual(args[0], "https://my.domain.com/dbconnections/change_password") |
| 73 |
self.assertEqual( |
| 74 |
kwargs["data"], |
| 75 |
{ |
| 76 |
"client_id": "cid", |
| 77 |
"email": "[email protected]", |
| 78 |
"connection": "conn", |
| 79 |
}, |
| 80 |
) |
| 81 |
|
| 82 |
@mock.patch("auth0.authentication.rest.RestClient.post") |
| 83 |
def test_change_password_with_organization_param(self, mock_post): |
| 84 |
d = Database("my.domain.com", "cid") |
| 85 |
|
| 86 |
|
| 87 |
d.change_password( |
| 88 |
email="[email protected]", password="pswd", connection="conn", organization="org_id" |
| 89 |
) |
| 90 |
|
| 91 |
args, kwargs = mock_post.call_args |
| 92 |
|
| 93 |
self.assertEqual(args[0], "https://my.domain.com/dbconnections/change_password") |
| 94 |
self.assertEqual( |
| 95 |
kwargs["data"], |
| 96 |
{ |
| 97 |
"client_id": "cid", |
| 98 |
"email": "[email protected]", |
| 99 |
"connection": "conn", |
| 100 |
"organization": "org_id", |
| 101 |
}, |
| 102 |
) |