Skip to content

Commit

Permalink
🚨 changed a few deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Lugrim committed Oct 9, 2023
1 parent f996250 commit 639ac60
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
54 changes: 27 additions & 27 deletions insalan/user/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def test_get_existing_full_user(self):
Test getting all the fields of an already created user
"""
u: User = User.objects.get(username="randomplayer")
self.assertEquals(u.get_username(), "randomplayer")
self.assertEquals(u.get_short_name(), "Random")
self.assertEquals(u.get_full_name(), "Random Player")
self.assertEquals(u.get_user_permissions(), set())
self.assertEqual(u.get_username(), "randomplayer")
self.assertEqual(u.get_short_name(), "Random")
self.assertEqual(u.get_full_name(), "Random Player")
self.assertEqual(u.get_user_permissions(), set())
self.assertTrue(u.has_usable_password())
self.assertTrue(u.check_password("IUseAVerySecurePassword"))
self.assertTrue(u.is_active)
Expand All @@ -68,10 +68,10 @@ def test_get_existing_minimal_user(self):
Test getting all the fields of an user created with only the required fields
"""
u: User = User.objects.get(username="anotherplayer")
self.assertEquals(u.get_username(), "anotherplayer")
self.assertEquals(u.get_short_name(), "")
self.assertEquals(u.get_full_name(), "")
self.assertEquals(u.get_user_permissions(), set())
self.assertEqual(u.get_username(), "anotherplayer")
self.assertEqual(u.get_short_name(), "")
self.assertEqual(u.get_full_name(), "")
self.assertEqual(u.get_user_permissions(), set())
self.assertTrue(u.has_usable_password())
self.assertTrue(u.check_password("ThisIsPassword"))
self.assertTrue(u.is_active)
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_register_invalid_data(self):

def send_invalid_data(data):
request = self.client.post("/v1/user/register/", data, format="json")
self.assertEquals(request.status_code, 400)
self.assertEqual(request.status_code, 400)

send_invalid_data({})
send_invalid_data({"username": "newuser"})
Expand All @@ -132,11 +132,11 @@ def send_valid_data(data, check_fields=[]):
"""
request = self.client.post("/v1/user/register/", data, format="json")

self.assertEquals(request.status_code, 201)
self.assertEqual(request.status_code, 201)

created_data: Dict = request.data
for k, v in check_fields:
self.assertEquals(created_data[k], v)
self.assertEqual(created_data[k], v)

send_valid_data(
{
Expand Down Expand Up @@ -185,11 +185,11 @@ def test_register_read_only_fields(self):
def send_valid_data(data, check_fields=[]):
request = self.client.post("/v1/user/register/", data, format="json")

self.assertEquals(request.status_code, 201)
self.assertEqual(request.status_code, 201)

created_data: Dict = request.data
for k, v in check_fields:
self.assertEquals(created_data[k], v)
self.assertEqual(created_data[k], v)

send_valid_data(
{
Expand Down Expand Up @@ -277,10 +277,10 @@ def test_register_can_confirm_email(self):
username = match["username"]
token = match["token"]

self.assertEquals(username, data["username"])
self.assertEqual(username, data["username"])

request = self.client.get(f"/v1/user/confirm/{username}/{token}")
self.assertEquals(request.status_code, 200)
self.assertEqual(request.status_code, 200)

self.assertTrue(User.objects.get(username=data["username"]).email_active)

Expand All @@ -307,10 +307,10 @@ def test_can_confirm_email_only_once(self):
token = match["token"]

request = self.client.get(f"/v1/user/confirm/{username}/{token}")
self.assertEquals(request.status_code, 200)
self.assertEqual(request.status_code, 200)

request = self.client.get(f"/v1/user/confirm/{username}/{token}")
self.assertEquals(request.status_code, 400)
self.assertEqual(request.status_code, 400)

def test_confirmation_email_is_token_checked(self):
"""
Expand Down Expand Up @@ -339,7 +339,7 @@ def test_confirmation_email_is_token_checked(self):

request = self.client.get(f"/v1/user/confirm/{username}/{token}")

self.assertEquals(request.status_code, 400)
self.assertEqual(request.status_code, 400)

def test_login_invalid_account(self):
"""
Expand All @@ -349,8 +349,8 @@ def test_login_invalid_account(self):
def send_valid_data(data):
request = self.client.post("/v1/user/login/", data, format="json")

self.assertEquals(request.status_code, 404)
self.assertEquals(
self.assertEqual(request.status_code, 404)
self.assertEqual(
request.data["user"][0],
_("Nom d'utilisateur ou mot de passe incorrect"),
)
Expand Down Expand Up @@ -495,7 +495,7 @@ def test_can_reset_password(self):

# self.assertFalse(User.objects.get(username=data["username"]).email_active)

# self.assertEquals(username, data["username"])
# self.assertEqual(username, data["username"])
data = {
"user": username,
"token": token,
Expand All @@ -506,23 +506,23 @@ def test_can_reset_password(self):
request = self.client.post(
"/v1/user/password-reset/submit/", data, format="json"
)
self.assertEquals(request.status_code, 200)
self.assertEqual(request.status_code, 200)
self.client.post("/v1/user/logout/", format="json")

login_data = {
"username": username,
"password": "UwU*nuzzles*621!",
}
request = self.client.post("/v1/user/login/", login_data, format="json")
self.assertEquals(request.status_code, 200)
self.assertEqual(request.status_code, 200)
self.client.post("/v1/user/logout/", format="json")

login_data = {
"username": username,
"password": "IUseAVerySecurePassword",
}
request = self.client.post("/v1/user/login/", login_data, format="json")
self.assertEquals(request.status_code, 404)
self.assertEqual(request.status_code, 404)

def test_can_reset_password_only_once(self):
"""
Expand Down Expand Up @@ -553,7 +553,7 @@ def test_can_reset_password_only_once(self):
request = self.client.post(
"/v1/user/password-reset/submit/", data, format="json"
)
self.assertEquals(request.status_code, 200)
self.assertEqual(request.status_code, 200)

data = {
"user": username,
Expand All @@ -565,7 +565,7 @@ def test_can_reset_password_only_once(self):
request = self.client.post(
"/v1/user/password-reset/submit/", data, format="json"
)
self.assertEquals(request.status_code, 400)
self.assertEqual(request.status_code, 400)

def test_password_reset_is_token_checked(self):
"""
Expand Down Expand Up @@ -599,4 +599,4 @@ def test_password_reset_is_token_checked(self):
request = self.client.post(
"/v1/user/password-reset/submit/", data, format="json"
)
self.assertEquals(request.status_code, 400)
self.assertEqual(request.status_code, 400)
30 changes: 18 additions & 12 deletions insalan/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
@require_GET
@ensure_csrf_cookie
def get_csrf(request):
"""
Returns a response setting CSRF cookie in headers
"""
return JsonResponse({"csrf": _("Le cookie a été défini")})


Expand All @@ -54,6 +57,9 @@ class UserMe(APIView):
permission_classes = [permissions.IsAuthenticated]

def get(self, request):
"""
Returns an user's own informations
"""
user = UserSerializer(request.user)
return Response(user.data)

Expand Down Expand Up @@ -170,24 +176,21 @@ def post(self, request):
user_object.set_password(data["password"])
user_object.save()
return Response()
else:
return Response(
{
"user": [_("Mot de passe trop simple ou invalide")],
"errors": validation_errors,
},
status=status.HTTP_400_BAD_REQUEST,
)
else:
return Response(
{"user": [_("Les mots de passe diffèrent")]},
{
"user": [_("Mot de passe trop simple ou invalide")],
"errors": validation_errors,
},
status=status.HTTP_400_BAD_REQUEST,
)
else:
return Response(
{"user": [_("Jeton de ré-initialisation invalide")]},
{"user": [_("Les mots de passe diffèrent")]},
status=status.HTTP_400_BAD_REQUEST,
)
return Response(
{"user": [_("Jeton de ré-initialisation invalide")]},
status=status.HTTP_400_BAD_REQUEST,
)

except User.DoesNotExist:
return Response(
Expand Down Expand Up @@ -257,6 +260,9 @@ class UserLogin(APIView):
authentication_classes = [SessionAuthentication]

def post(self, request):
"""
Submit a login form
"""
data = request.data
serializer = UserLoginSerializer(data=data)
if serializer.is_valid():
Expand Down

0 comments on commit 639ac60

Please sign in to comment.