Skip to content

Commit 20f1d16

Browse files
committed
Update Tests and Swagger Docs for reset_token
Fix #171 Changes to be committed: modified: authentication/apis.py modified: tests/fixtures/test_data.json new file: tests/test_views/test_api_auth_reset_token.py
1 parent 2e016b8 commit 20f1d16

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

authentication/apis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class ResetTokenApi(APIView):
271271
manual_parameters=auth,
272272
responses={
273273
200: "Token reset is successful.",
274-
400: "Bad request.",
274+
403: "Invalid token.",
275275
},
276276
tags=["Authentication"],
277277
)

tests/fixtures/test_data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@
13501350
"username": "test50",
13511351
"first_name": "",
13521352
"last_name": "",
1353-
"email": "",
1353+
"email": "[email protected]",
13541354
"is_staff": false,
13551355
"is_active": true,
13561356
"date_joined": "2022-05-10T20:50:39.093Z",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
"""Reset Token
4+
Tests for 'Token reset is successful.' 200, and 'Bad request.', 400.
5+
"""
6+
7+
from django.test import TestCase, Client
8+
from rest_framework.test import APIClient
9+
from rest_framework.authtoken.models import Token
10+
from django.contrib.auth.models import User
11+
12+
class ResetTokenTestCase(TestCase):
13+
fixtures = ['tests/fixtures/test_data']
14+
15+
def setUp(self) -> None:
16+
self.client = APIClient()
17+
18+
def test_reset_successful(self):
19+
"""Token reset is successful. 200
20+
"""
21+
22+
token = Token.objects.get(user=User.objects.get(username='test50')).key
23+
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
24+
response = self.client.post('/api/auth/reset_token/')
25+
self.assertEqual(response.status_code, 200)
26+
27+
def test_invalid_token(self):
28+
"""Inclid token. 403
29+
"""
30+
31+
# token = Token.objects.get(user=User.objects.get(username='test50')).key
32+
token = 'this-is-an-invalid-token'
33+
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
34+
response = self.client.post('/api/auth/reset_token/')
35+
self.assertEqual(response.status_code, 403)

0 commit comments

Comments
 (0)