-
Notifications
You must be signed in to change notification settings - Fork 2
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 #33 from JoshuaOndieki/ft-edit-user-158791587
[Delivers #158791587] Edit User API Endpoint
- Loading branch information
Showing
7 changed files
with
204 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
""" | ||
This module tests edit user | ||
""" | ||
import unittest | ||
import json | ||
|
||
from ridemyway.tests.tests_v2 import V2BaseTest | ||
from ridemyway.tests.tests_v2.urls import SIGNUP, LOGIN, USER | ||
from ridemyway.tests.tests_v2.data import VALID_DRIVER | ||
|
||
|
||
class TestEditUser(V2BaseTest): | ||
""" | ||
Tests edit user API endpoint | ||
- Users: '/api/v2/users' # PUT | ||
""" | ||
|
||
def test_user_can_edit_successfully(self): | ||
self.client().post(SIGNUP, data=VALID_DRIVER) | ||
self.response = self.client().post(LOGIN, data=VALID_DRIVER) | ||
access_token = json.loads(self.response.data.decode())['access_token'] | ||
# Edit user | ||
EDITS = { | ||
'name': 'New Name' | ||
} | ||
self.response = self.client().put(USER, | ||
data=EDITS, | ||
headers=dict( | ||
Authorization="Bearer " + | ||
access_token)) | ||
self.assertEqual(self.response.status_code, 201, | ||
msg='Should return 201 status code for edits made') | ||
|
||
def test_cannot_edit_username(self): | ||
self.client().post(SIGNUP, data=VALID_DRIVER) | ||
self.response = self.client().post(LOGIN, data=VALID_DRIVER) | ||
access_token = json.loads(self.response.data.decode())['access_token'] | ||
# Edit user | ||
EDITS = { | ||
'username': 'newer' | ||
} | ||
self.response = self.client().put(USER, | ||
data=EDITS, | ||
headers=dict( | ||
Authorization="Bearer " + | ||
access_token)) | ||
result = json.loads(self.response.data.decode()) | ||
self.assertIn('username', result['warnings'], | ||
msg='Should not allow edits of username') | ||
|
||
def test_cannot_edit_usertype(self): | ||
self.client().post(SIGNUP, data=VALID_DRIVER) | ||
self.response = self.client().post(LOGIN, data=VALID_DRIVER) | ||
access_token = json.loads(self.response.data.decode())['access_token'] | ||
# Edit user | ||
EDITS = { | ||
'usertype': 'rider' | ||
} | ||
self.response = self.client().put(USER, | ||
data=EDITS, | ||
headers=dict( | ||
Authorization="Bearer " + | ||
access_token)) | ||
result = json.loads(self.response.data.decode()) | ||
self.assertIn('usertype', result['warnings'], | ||
msg='Should not allow edits of usertype') | ||
|
||
def test_cannot_edit_date_joined(self): | ||
self.client().post(SIGNUP, data=VALID_DRIVER) | ||
self.response = self.client().post(LOGIN, data=VALID_DRIVER) | ||
access_token = json.loads(self.response.data.decode())['access_token'] | ||
# Edit user | ||
EDITS = { | ||
'date_joined': '31/12/1901 12:00AM' | ||
} | ||
self.response = self.client().put(USER, | ||
data=EDITS, | ||
headers=dict( | ||
Authorization="Bearer " + | ||
access_token)) | ||
result = json.loads(self.response.data.decode()) | ||
self.assertIn('date_joined', result['warnings'], | ||
msg='Should not allow edits of date joined') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
""" | ||
Module for checking warnings | ||
""" | ||
|
||
|
||
def edit_warnings(**kwargs): | ||
message = 'Edit successful with Warnings | Some data cannot be edited after signup' | ||
warnings = {} | ||
if 'username' in kwargs: | ||
warnings['username'] = 'Your attempt to edit username was ignored' | ||
if 'usertype' in kwargs: | ||
warnings['usertype'] = 'Your attempt to edit usertype was ignored' | ||
if 'date_joined' in kwargs: | ||
warnings['date_joined'] = 'Your attempt to edit date joined was ignored' | ||
meta = {'warnings': len(warnings)} | ||
if warnings: | ||
return warnings, meta, message |