chore: blacked

This commit is contained in:
Pablo Moreno
2024-05-13 00:42:51 +02:00
parent f3b4f3e509
commit 236fd5c37b
10 changed files with 190 additions and 134 deletions
+71 -47
View File
@@ -7,79 +7,103 @@ User = get_user_model()
class TestChangePassword(APITestCase):
def setUp(self) -> None:
self.password = 'theonering'
self.password = "theonering"
self.user = User.objects.create(
username='sauron',
email='sauron@mordor.middleearth',
username="sauron",
email="sauron@mordor.middleearth",
)
self.user.set_password(self.password)
self.user.save()
def test_login_then_change_password(self):
response = self.client.post('/api/v1/auth/login/', {
'username': self.user.username,
'password': self.password,
})
response = self.client.post(
"/api/v1/auth/login/",
{
"username": self.user.username,
"password": self.password,
},
)
assert response.status_code == status.HTTP_200_OK
jwt_token = response.data.get('access')
self.client.credentials(HTTP_AUTHORIZATION=f'JWT {jwt_token}')
response = self.client.put('/api/v1/auth/change-password/', {
'new_password': 'barad-dur',
'new_password2': 'barad-dur',
'old_password': self.password,
})
jwt_token = response.data.get("access")
self.client.credentials(HTTP_AUTHORIZATION=f"JWT {jwt_token}")
response = self.client.put(
"/api/v1/auth/change-password/",
{
"new_password": "barad-dur",
"new_password2": "barad-dur",
"old_password": self.password,
},
)
assert response.status_code == status.HTTP_200_OK
def test_login_then_change_password_with_wrong_password(self):
response = self.client.post('/api/v1/auth/login/', {
'username': self.user.username,
'password': self.password,
})
response = self.client.post(
"/api/v1/auth/login/",
{
"username": self.user.username,
"password": self.password,
},
)
assert response.status_code == status.HTTP_200_OK
jwt_token = response.data.get('access')
self.client.credentials(HTTP_AUTHORIZATION=f'JWT {jwt_token}')
response = self.client.put('/api/v1/auth/change-password/', {
'new_password': 'barad-dur',
'new_password2': 'barad-dur',
'old_password': 'incorrectoldpassword',
})
jwt_token = response.data.get("access")
self.client.credentials(HTTP_AUTHORIZATION=f"JWT {jwt_token}")
response = self.client.put(
"/api/v1/auth/change-password/",
{
"new_password": "barad-dur",
"new_password2": "barad-dur",
"old_password": "incorrectoldpassword",
},
)
assert response.status_code == status.HTTP_400_BAD_REQUEST
def test_login_then_change_password_mismatch_password(self):
response = self.client.post('/api/v1/auth/login/', {
'username': self.user.username,
'password': self.password,
})
response = self.client.post(
"/api/v1/auth/login/",
{
"username": self.user.username,
"password": self.password,
},
)
assert response.status_code == status.HTTP_200_OK
jwt_token = response.data.get('access')
self.client.credentials(HTTP_AUTHORIZATION=f'JWT {jwt_token}')
response = self.client.put('/api/v1/auth/change-password/', {
'new_password': 'barad-dur',
'new_password2': 'mountdoom',
'old_password': self.password,
})
jwt_token = response.data.get("access")
self.client.credentials(HTTP_AUTHORIZATION=f"JWT {jwt_token}")
response = self.client.put(
"/api/v1/auth/change-password/",
{
"new_password": "barad-dur",
"new_password2": "mountdoom",
"old_password": self.password,
},
)
assert response.status_code == status.HTTP_400_BAD_REQUEST
def test_login_then_change_password_but_its_the_same(self):
response = self.client.post('/api/v1/auth/login/', {
'username': self.user.username,
'password': self.password,
})
response = self.client.post(
"/api/v1/auth/login/",
{
"username": self.user.username,
"password": self.password,
},
)
assert response.status_code == status.HTTP_200_OK
jwt_token = response.data.get('access')
self.client.credentials(HTTP_AUTHORIZATION=f'JWT {jwt_token}')
response = self.client.put('/api/v1/auth/change-password/', {
'new_password': self.password,
'new_password2': self.password,
'old_password': self.password,
})
jwt_token = response.data.get("access")
self.client.credentials(HTTP_AUTHORIZATION=f"JWT {jwt_token}")
response = self.client.put(
"/api/v1/auth/change-password/",
{
"new_password": self.password,
"new_password2": self.password,
"old_password": self.password,
},
)
assert response.status_code == status.HTTP_400_BAD_REQUEST