ft_transcendence/accounts/tests/change_password.py

31 lines
1.2 KiB
Python
Raw Normal View History

2023-10-25 10:17:55 -04:00
from django.test import TestCase
# Create your tests here.
from django.test.client import Client
from django.http import HttpResponse
from django.contrib.auth.models import User
2023-10-25 10:17:55 -04:00
import uuid
class ChangePasswordTest(TestCase):
def setUp(self):
self.client = Client()
2023-11-11 13:50:14 -05:00
self.url = "/accounts/change_password"
2023-10-25 10:17:55 -04:00
self.username: str = str(uuid.uuid4())
self.password: str = str(uuid.uuid4())
self.new_password: str = str(uuid.uuid4())
2023-10-25 10:17:55 -04:00
User.objects.create_user(username = self.username, password = self.password)
def test_normal(self):
self.client.login(username = self.username, password = self.password)
2023-11-11 13:50:14 -05:00
response: HttpResponse = self.client.post(self.url, {"current_password": self.password, "new_password": self.new_password})
response_text: str = response.content.decode('utf-8')
2023-11-11 13:50:14 -05:00
self.assertEqual(response_text, '"password changed"')
2023-10-25 10:17:55 -04:00
def test_nologged(self):
2023-11-11 13:50:14 -05:00
response: HttpResponse = self.client.post(self.url, {"current_password": self.password, "new_password": self.new_password})
errors: dict = eval(response.content)
self.assertDictEqual(errors, {'detail': 'Authentication credentials were not provided.'})