Skip to content

Commit 1b27bb4

Browse files
authored
Fix tests and some reformatting (#138)
* test(api): fix test for update password * reformat: ran black * fix: bump black in pre-commit file * reformat: update doctstrings and ran flake8
1 parent 932f219 commit 1b27bb4

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exclude: .+/migrations/.+\.py
22
repos:
33
- repo: https://github.com/psf/black
4-
rev: 22.1.0
4+
rev: 22.3.0
55
hooks:
66
- id: black
77

drf_user/views.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ class RegisterView(CreateAPIView):
4343
4444
Register a new user to the system.
4545
The data required are username, email, name, password and mobile (optional).
46-
47-
Author: Himanshu Shankar (https://himanshus.com)
48-
Aditya Gupta (https://github.com/ag93999)
4946
"""
5047

5148
renderer_classes = (JSONRenderer,)
@@ -77,9 +74,6 @@ class LoginView(APIView):
7774
7875
username -- Either username or mobile or email address.
7976
password -- Password of the user.
80-
81-
Author: Himanshu Shankar (https://himanshus.com)
82-
Aditya Gupta (https://github.com/ag93999)
8377
"""
8478

8579
renderer_classes = (JSONRenderer,)
@@ -126,9 +120,6 @@ class CheckUniqueView(APIView):
126120
doesn't exists yet)
127121
'prop' -- A property to check for uniqueness (username/email/mobile)
128122
'value' -- Value against property which is to be checked for.
129-
130-
Author: Himanshu Shankar (https://himanshus.com)
131-
Aditya Gupta (https://github.com/ag93999)
132123
"""
133124

134125
renderer_classes = (JSONRenderer,)
@@ -187,9 +178,6 @@ class OTPView(APIView):
187178
188179
>>> {"destination": "[email protected]", "is_login": True,
189180
>>> "verify_otp": 1234232}
190-
191-
Author: Himanshu Shankar (https://himanshus.com)
192-
Aditya Gupta (https://github.com/ag93999)
193181
"""
194182

195183
permission_classes = (AllowAny,)
@@ -243,9 +231,6 @@ class RetrieveUpdateUserAccountView(RetrieveUpdateAPIView):
243231
get: Fetch Account Details
244232
put: Update all details
245233
patch: Update some details
246-
247-
Author: Himanshu Shankar (https://himanshus.com)
248-
Aditya Gupta( https://github.com/ag93999)
249234
"""
250235

251236
queryset = User.objects.all()
@@ -264,7 +249,7 @@ def update(self, request, *args, **kwargs):
264249
response = super(RetrieveUpdateUserAccountView, self).update(
265250
request, *args, **kwargs
266251
)
267-
# we need to set_password after save the user otherwise it'll save the raw_password in db.
252+
# we need to set_password after save the user otherwise it'll save the raw_password in db. # noqa
268253
if "password" in request.data.keys():
269254
self.request.user.set_password(request.data["password"])
270255
self.request.user.save()
@@ -286,9 +271,6 @@ class OTPLoginView(APIView):
286271
email -- Required
287272
mobile -- Required
288273
verify_otp -- Not Required (only when verifying OTP)
289-
290-
Author: Himanshu Shankar (https://himanshus.com)
291-
Aditya Gupta (https://github.com/ag93999)
292274
"""
293275

294276
permission_classes = (AllowAny,)
@@ -341,7 +323,9 @@ def post(self, request, *args, **kwargs):
341323
otp_obj_email.save()
342324
message["email"] = {"otp": _("OTP has been sent successfully.")}
343325
else:
344-
message["email"] = {"otp": _(f'OTP sending failed {sentotp_email["message"]}')}
326+
message["email"] = {
327+
"otp": _(f'OTP sending failed {sentotp_email["message"]}')
328+
}
345329

346330
if sentotp_mobile["success"]:
347331
otp_obj_mobile.send_counter += 1
@@ -352,7 +336,6 @@ def post(self, request, *args, **kwargs):
352336
"otp": _(f'OTP sending failed {sentotp_mobile["message"]}')
353337
}
354338

355-
356339
if sentotp_email["success"] or sentotp_mobile["success"]:
357340
curr_status = status.HTTP_201_CREATED
358341
else:

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-r requirements.txt
2-
black==21.9b0
2+
black==22.3.0
33
Faker==8.13.2
44
flake8==3.9.2
55
ipython==7.16.3

tests/settings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@
4242
# https://docs.djangoproject.com/en/dev/ref/settings/#password-hashers
4343
PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"]
4444

45+
MIDDLEWARE = [
46+
"django.middleware.security.SecurityMiddleware",
47+
"django.contrib.sessions.middleware.SessionMiddleware",
48+
"django.contrib.auth.middleware.AuthenticationMiddleware",
49+
"django.contrib.messages.middleware.MessageMiddleware",
50+
]
51+
52+
TEMPLATES = [
53+
{
54+
"BACKEND": "django.template.backends.django.DjangoTemplates",
55+
"OPTIONS": {
56+
"context_processors": [
57+
"django.contrib.auth.context_processors.auth",
58+
"django.contrib.messages.context_processors.messages",
59+
],
60+
},
61+
},
62+
]
4563

4664
# EMAIL
4765
# ------------------------------------------------------------------------------

tests/test_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def test_update_password(self):
152152
response = self.client.patch(self.url, {"password": "my_unique_password"})
153153

154154
self.assertEqual(200, response.status_code)
155-
self.assertEqual("my_unique_password", self.user.password)
155+
self.assertIn("md5", self.user.password)
156156

157157

158158
class TestCheckUniqueView(APITestCase):

0 commit comments

Comments
 (0)