forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request galaxyproject#2595 from carlfeberhard/users.api-up…
…date Users API: add the update endpoint
- Loading branch information
Showing
6 changed files
with
162 additions
and
17 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
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,3 +1,5 @@ | ||
import json | ||
from requests import put | ||
from base import api | ||
|
||
TEST_USER_EMAIL = "[email protected]" | ||
|
@@ -18,7 +20,64 @@ def test_index( self ): | |
|
||
def test_index_only_self_for_nonadmins( self ): | ||
self._setup_user( TEST_USER_EMAIL ) | ||
with self._different_user( ): | ||
with self._different_user(): | ||
all_users_response = self._get( "users" ) | ||
# Non admin users can only see themselves | ||
assert len( all_users_response.json() ) == 1 | ||
|
||
def test_show( self ): | ||
user = self._setup_user( TEST_USER_EMAIL ) | ||
with self._different_user( email=TEST_USER_EMAIL ): | ||
show_response = self.__show( user ) | ||
self._assert_status_code_is( show_response, 200 ) | ||
self.__assert_matches_user( user, show_response.json() ) | ||
|
||
def test_update( self ): | ||
new_name = 'linnaeus' | ||
user = self._setup_user( TEST_USER_EMAIL ) | ||
not_the_user = self._setup_user( '[email protected]' ) | ||
with self._different_user( email=TEST_USER_EMAIL ): | ||
|
||
# working | ||
update_response = self.__update( user, username=new_name ) | ||
self._assert_status_code_is( update_response, 200 ) | ||
update_json = update_response.json() | ||
self.assertEqual( update_json[ 'username' ], new_name ) | ||
|
||
# too short | ||
update_response = self.__update( user, username='mu' ) | ||
self._assert_status_code_is( update_response, 400 ) | ||
|
||
# not them | ||
update_response = self.__update( not_the_user, username=new_name ) | ||
self._assert_status_code_is( update_response, 403 ) | ||
|
||
# non-existent | ||
no_user_id = self.security.encode_id( 100 ) | ||
update_url = self._api_url( "users/%s" % ( no_user_id ), use_key=True ) | ||
update_response = put( update_url, data=json.dumps( dict( username=new_name ) ) ) | ||
self._assert_status_code_is( update_response, 404 ) | ||
|
||
def test_admin_update( self ): | ||
new_name = 'flexo' | ||
user = self._setup_user( TEST_USER_EMAIL ) | ||
|
||
update_url = self._api_url( "users/%s" % ( user[ "id" ] ), params=dict( key=self.master_api_key ) ) | ||
update_response = put( update_url, data=json.dumps( dict( username=new_name ) ) ) | ||
self._assert_status_code_is( update_response, 200 ) | ||
update_json = update_response.json() | ||
self.assertEqual( update_json[ 'username' ], new_name ) | ||
|
||
def __show( self, user ): | ||
return self._get( "users/%s" % ( user[ 'id' ] ) ) | ||
|
||
def __update( self, user, **new_data ): | ||
update_url = self._api_url( "users/%s" % ( user[ "id" ] ), use_key=True ) | ||
# TODO: Awkward json.dumps required here because of https://trello.com/c/CQwmCeG6 | ||
body = json.dumps( new_data ) | ||
return put( update_url, data=body ) | ||
|
||
def __assert_matches_user( self, userA, userB ): | ||
self._assert_has_keys( userB, "id", "username", "total_disk_usage" ) | ||
assert userA[ "id" ] == userB[ "id" ] | ||
assert userA[ "username" ] == userB[ "username" ] |
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