-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
253 additions
and
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,29 +34,6 @@ all fields are mandatory | |
> | `401` | `application/json` | `{"errors": ["AAA", "BBB", "..."]}` | | ||
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | | ||
>errors can be combined | ||
> errors can be : | ||
> - Username empty | ||
> - Username already taken | ||
> - Username length {len(username)} > 20 | ||
> - Username must be alphanumeric | ||
> - Email {email} already taken | ||
> - Email empty | ||
> - Email length {len(email)} > 50 | ||
> - Email missing @ | ||
> - Email missing "." character | ||
> - Email contains more than one @ character | ||
> - Password empty | ||
> - Password length {len(password)} < 8 | ||
> - Password missing uppercase character | ||
> - Password missing digit | ||
> - Password missing special character | ||
> - Invalid JSON format in the request body | ||
> - An unexpected error occurred | ||
</details> | ||
|
@@ -89,16 +66,6 @@ all fields are mandatory | |
> | `201` | `application/json` | `{"refresh_token": "eyJhbGci.."}` | | ||
> | `401` | `application/json` | `{"errors": [ "AAA","BBB", "..."]}` | | ||
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | | ||
> | ||
> errors can be combined | ||
> errors can be : | ||
> - Username empty | ||
> - Password empty | ||
> - Username not found | ||
> - Invalid password | ||
> - Invalid JSON format in the request body | ||
> - An unexpected error occurred | ||
</details> | ||
|
@@ -131,15 +98,6 @@ will return a boolean | |
> | `401` | `application/json` | `{"errors": [ "AAA","BBB", "..."]}` | | ||
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | | ||
> | ||
> errors can be combined | ||
> errors can be : | ||
> - Invalid JSON format in the request body | ||
> - An unexpected error occurred | ||
> | ||
> NB : An empty username is considered as not taken | ||
</details> | ||
## `/user/email-exist/` | ||
|
@@ -170,14 +128,6 @@ will return a boolean | |
> | `401` | `application/json` | `{"errors": [ "AAA","BBB", "..."]}` | | ||
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | | ||
> | ||
> errors can be combined | ||
> errors can be : | ||
> - Empty email | ||
> - Invalid JSON format in the request body | ||
> - An unexpected error occurred | ||
</details> | ||
|
@@ -208,17 +158,6 @@ all fields are mandatory | |
> | `400` | `application/json` | `{"errors": ["AAA", "BBB", "..."]}` | | ||
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | | ||
>errors can be combined | ||
> errors can be : | ||
> - Refresh token not found | ||
> - Signature verification failed | ||
> - No expiration date found | ||
> - Signature has expired | ||
> - No user_id in payload | ||
> - User does not exist | ||
> - Invalid JSON format in the request body | ||
> - An unexpected error occurred | ||
</details> | ||
|
@@ -250,13 +189,6 @@ all fields are mandatory | |
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | | ||
> errors can be : | ||
> - No email provided | ||
> - Email can not be empty | ||
> - Username not found | ||
> - Invalid JSON format in the request body : decode error | ||
> - An unexpected error occurred | ||
</details> | ||
## `/user/forgot-password/check-code/` | ||
|
@@ -287,16 +219,6 @@ all fields are mandatory | |
> | `400` | `application/json` | `{"errors": "AAA", errors details : "aaa" }` | | ||
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | | ||
> errors details are optional | ||
> errors can be : | ||
> - Mandatory value missing : 'email' | ||
> - Mandatory value missing : 'code' | ||
> - Email empty | ||
> - Code empty | ||
> - Username not found | ||
> - Invalid code | ||
> - Code expired | ||
</details> | ||
|
@@ -351,19 +273,6 @@ Might be extended to return more information in the future, if needed | |
> | `400` | `application/json` | `{"errors": "AAA", errors details : "aaa" }` | | ||
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | | ||
> errors details are optional | ||
> errors can be : | ||
> - Mandatory value missing : 'username' | ||
> - Mandatory value missing : 'code' | ||
> - Mandatory value missing : 'password' | ||
> - Email empty | ||
> - Code empty | ||
> - Username not found | ||
> - Invalid code | ||
> - Code expired | ||
> - (all the errors from the is_valid_password function in the sign_up route) | ||
</details> | ||
|
@@ -397,11 +306,6 @@ will return a list of usernames that contains the searched username | |
> | `400` | `application/json` | `{"errors": ["AAA"]}` | | ||
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | | ||
> | ||
> errors can be : | ||
> - Invalid JSON format in the request body | ||
> - An unexpected error occurred | ||
> - No username found | ||
</details> | ||
|
@@ -459,4 +363,41 @@ This endpoint handles the callback after successful OAuth authentication and ret | |
> | `400` | `application/json` | `{"errors": ["An unexpected error occurred : ..."]}` | | ||
> | `500` | `application/json` | `{"errors": ['Failed to create or get user']}` | | ||
</details> | ||
</details> | ||
## '/user/update-infos/' | ||
### Update user's information | ||
will return 200 if successful | ||
<details> | ||
<summary><code>POST</code><code><b>/user/update-infos/</b></code></summary> | ||
### Parameters | ||
#### Body | ||
mandatory field : change_list, access_token | ||
all other fields are optional and depend on the change_list | ||
> ``` javascript | ||
> { | ||
> "access_token": "d2d040fj..." | ||
> "change_list": ["username", "email", "password"] | ||
> "username": "NewUsername", | ||
> "email": "[email protected]", | ||
> "password": "NewPassword42*" | ||
> } | ||
> NB : change_list must contain at least one of the following values : "username", "email", "password" | ||
> ``` | ||
#### Responses | ||
> | http code | content-type | response | | ||
> |-----------|--------------------|------------------------------------------------------| | ||
> | `200` | `application/json` | `{"ok": "ok"}` | | ||
> | `400` | `application/json` | `{"errors": ["AAA", "BBB", "..."]}` | | ||
> | `500` | `application/json` | `{"errors": ['An unexpected error occurred : ...']}` | |
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 |
---|---|---|
|
@@ -404,3 +404,59 @@ def test_search_username(self): | |
self.assertEqual(result.status_code, 200) | ||
self.assertTrue('users' in result.json()) | ||
self.assertEqual(len(result.json()['users']), 0) | ||
|
||
|
||
class TestsUserUpdateInfos(TestCase): | ||
""" 1) first, create a user with /user/signup | ||
2) get the access token of the user just created with /user/refresh-access-jwt | ||
3) then, update the user infos with /user/update-infos | ||
4) finally, check if the user infos have been updated with /user/user-id | ||
5) test invalid data""" | ||
def test_user_update_infos(self): | ||
# 1) | ||
data_preparation = { | ||
'username': 'UpdateThisUser', | ||
'email': '[email protected]', | ||
'password': 'Validpass42*', | ||
} | ||
url = reverse('signup') | ||
result = self.client.post(url, json.dumps(data_preparation), content_type='application/json') | ||
refresh_token = result.json()['refresh_token'] | ||
user = User.objects.filter(username='UpdateThisUser').first() | ||
|
||
# 2) | ||
url = reverse('refresh-access-jwt') | ||
result = self.client.post(url, json.dumps({'refresh_token': refresh_token}), content_type='application/json') | ||
access_token = result.json()['access_token'] | ||
|
||
# 3) | ||
data = { | ||
'access_token': access_token, | ||
'change_list': ['username', 'email', 'password'], | ||
'username': 'UpdatedUser', | ||
'email': '[email protected]', | ||
'password': 'AnotherValidpass42*' | ||
} | ||
url = reverse('update-infos') | ||
result = self.client.post(url, json.dumps(data), content_type='application/json') | ||
|
||
# 4) | ||
self.assertEqual(result.status_code, 200) | ||
user = User.objects.filter(username='UpdatedUser').first() | ||
self.assertEqual(user.username, 'UpdatedUser') | ||
self.assertEqual(user.email, '[email protected]') | ||
|
||
# 5) | ||
data = { | ||
'access_token': access_token, | ||
'change_list': ['username', 'email', 'password'], | ||
'username': 'I', | ||
'email': 'a.fr', | ||
'password': 'aninvalidpassword' | ||
} | ||
|
||
url = reverse('update-infos') | ||
result = self.client.post(url, json.dumps(data), content_type='application/json') | ||
self.assertEqual(result.status_code, 400) | ||
self.assertTrue('errors' in result.json()) | ||
self.assertTrue(result.json()['errors']) |
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
Oops, something went wrong.