Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: update url #229
  • Loading branch information
Angeluz-07 committed Nov 19, 2020
commit d6f5ad59dace2a5329d82e86bbf739293eb9e31d
20 changes: 9 additions & 11 deletions tests/time_tracker_api/users/users_namespace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@


def test_users_response_contains_expected_props(
client: FlaskClient,
valid_header: dict,
client: FlaskClient, valid_header: dict,
):

AzureConnection.users = Mock(
return_value=[{'name': 'dummy', 'email': 'dummy', 'role': 'dummy'}]
)

response = client.get(
'/users',
headers=valid_header,
)
response = client.get('/users', headers=valid_header,)

assert HTTPStatus.OK == response.status_code
assert 'name' in json.loads(response.data)[0]
Expand All @@ -26,17 +22,17 @@ def test_users_response_contains_expected_props(


def test_update_user_role_response_contains_expected_props(
client: FlaskClient,
valid_header: dict,
user_id: str,
client: FlaskClient, valid_header: dict, user_id: str,
):
valid_user_role_data = {'role': 'admin'}
AzureConnection.update_user_role = Mock(
return_value={'name': 'dummy', 'email': 'dummy', 'role': 'dummy'}
)

response = client.put(
f'/users/{user_id}', headers=valid_header, json=valid_user_role_data
f'/users/{user_id}/roles',
headers=valid_header,
json=valid_user_role_data,
)

assert HTTPStatus.OK == response.status_code
Expand All @@ -55,7 +51,9 @@ def test_update_user_role_is_being_called_with_valid_arguments(

valid_user_role_data = {'role': 'admin'}
response = client.put(
f'/users/{user_id}', headers=valid_header, json=valid_user_role_data
f'/users/{user_id}/roles',
headers=valid_header,
json=valid_user_role_data,
)

assert HTTPStatus.OK == response.status_code
Expand Down
14 changes: 4 additions & 10 deletions time_tracker_api/users/users_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,19 @@ def get(self):
return azure_connection.users()


@ns.route('/<string:id>')
@ns.route('/<string:id>/roles')
@ns.response(HTTPStatus.NOT_FOUND, 'User not found')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User not found? I would say it is better to say Role not found

@ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format')
@ns.param('id', 'The user identifier')
class User(Resource):
@ns.doc('get_user')
@ns.marshal_with(user_response_fields)
def get(self, id):
"""Get an user"""
return {}

@ns.doc('update_user')
class UserRole(Resource):
@ns.doc('update_user_role')
@ns.expect(user_input_fields)
@ns.response(
HTTPStatus.BAD_REQUEST, 'Invalid format or structure of the user'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid format or structure of the user? Is not this for roles?

)
@ns.marshal_with(user_response_fields)
def put(self, id):
"""Update an user"""
"""Update user's role"""
from utils.azure_users import AzureConnection

azure_connection = AzureConnection()
Expand Down