-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create users in metadata backend via API (#289)
* Initial commit of rough draft. Allow creating users in metadata db via API. Signed-off-by: Grant Seward <[email protected]> * Cleaned up commented items Signed-off-by: Grant Seward <[email protected]> * Added abstract functions to fix make test Signed-off-by: Grant Seward <[email protected]> * added initial proxy test Signed-off-by: Grant Seward <[email protected]> * Added user tests, fixes for make file to pass Signed-off-by: Grant Seward <[email protected]> * Removed extra test mocks per PR feedback Signed-off-by: Grant Seward <[email protected]>
- Loading branch information
Showing
8 changed files
with
194 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Create or update a user | ||
--- | ||
tags: | ||
- 'user' | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/UserDetailFields' | ||
description: User attribute fields | ||
required: true | ||
responses: | ||
200: | ||
description: 'Existing user found and updated' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/UserDetailFields' | ||
201: | ||
description: 'New user created' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/UserDetailFields' | ||
400: | ||
description: 'Bad Request' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ErrorResponse' | ||
500: | ||
description: 'Internal server error' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ErrorResponse' |
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
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
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,6 +1,7 @@ | ||
# Copyright Contributors to the Amundsen project. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import json | ||
import unittest | ||
from http import HTTPStatus | ||
from unittest import mock | ||
|
@@ -37,6 +38,32 @@ def test_gets(self) -> None: | |
self.assertEqual(list(response)[1], HTTPStatus.OK) | ||
self.mock_client.get_users.assert_called_once() | ||
|
||
def test_put(self) -> None: | ||
m = MagicMock() | ||
m.data = json.dumps({'email': '[email protected]'}) | ||
with mock.patch("metadata_service.api.user.request", m): | ||
# Test user creation | ||
create_email = {'email': 'test_email'} | ||
self.mock_client.create_update_user.return_value = create_email, True | ||
test_user, test_user_created = self.api.put() | ||
self.assertEqual(test_user, json.dumps(create_email)) | ||
self.assertEqual(test_user_created, HTTPStatus.CREATED) | ||
|
||
# Test user update | ||
update_email = {'email': '[email protected]'} | ||
self.mock_client.create_update_user.return_value = update_email, False | ||
test_user2, test_user_updated = self.api.put() | ||
self.assertEqual(test_user2, json.dumps(update_email)) | ||
self.assertEqual(test_user_updated, HTTPStatus.OK) | ||
|
||
def test_put_no_inputs(self) -> None: | ||
# Test no data provided | ||
m2 = MagicMock() | ||
m2.data = {} | ||
with mock.patch("metadata_service.api.user.request", m2): | ||
_, status_code = self.api.put() | ||
self.assertEquals(status_code, HTTPStatus.BAD_REQUEST) | ||
|
||
|
||
class UserFollowsAPITest(unittest.TestCase): | ||
|
||
|
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