-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth0): Add upsert_user function (#828)
* feat(auth0): Add upsert_user function * chore(black): Fix formatting * chore(test): Create auth0.upsert_user test * chore(gitignore): ignore swp files * test(auth0): get correct tests --------- Co-authored-by: Tal Levy <[email protected]>
- Loading branch information
Showing
3 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,3 +124,4 @@ bill_com_credentials.* | |
|
||
docs/html | ||
docs/dirhtml | ||
*.sw* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from parsons import Auth0, Table | ||
import unittest | ||
import unittest.mock | ||
from test.utils import assert_matching_tables | ||
|
||
import requests_mock | ||
import unittest | ||
from parsons import Auth0, Table | ||
|
||
CLIENT_ID = "abc" | ||
CLIENT_SECRET = "def" | ||
|
@@ -11,6 +13,13 @@ | |
class TestAuth0(unittest.TestCase): | ||
def setUp(self): | ||
self.auth0 = Auth0(CLIENT_ID, CLIENT_SECRET, DOMAIN) | ||
self.fake_upsert_person = { | ||
"email": "[email protected]", | ||
"given_name": "Fakey", | ||
"family_name": "McFakerson", | ||
"username": "fakeusername", | ||
"user_id": 3, | ||
} | ||
|
||
@requests_mock.Mocker() | ||
def test_delete_user(self, m): | ||
|
@@ -29,3 +38,25 @@ def test_get_users_by_email(self, m): | |
assert_matching_tables( | ||
self.auth0.get_users_by_email(email), Table(mock_users), True | ||
) | ||
|
||
@requests_mock.Mocker() | ||
def test_upsert_user(self, m): | ||
user = self.fake_upsert_person | ||
email = user["email"] | ||
m.get( | ||
f"{self.auth0.base_url}/api/v2/users-by-email?email={email}", | ||
json=[user], | ||
) | ||
mock_resp = unittest.mock.MagicMock() | ||
mock_resp.status_code = 200 | ||
m.patch(f"{self.auth0.base_url}/api/v2/users/{user['user_id']}", [mock_resp]) | ||
m.post(f"{self.auth0.base_url}/api/v2/users", mock_resp) | ||
ret = self.auth0.upsert_user( | ||
email, | ||
user["username"], | ||
user["given_name"], | ||
user["family_name"], | ||
{}, | ||
{}, | ||
) | ||
self.assertEqual(ret.status_code, 200) |