core: use rest_framework in accounts

This commit is contained in:
2023-11-11 19:50:14 +01:00
parent eb8789aa1d
commit a7d9471d59
23 changed files with 155 additions and 245 deletions

View File

@ -7,13 +7,11 @@ from django.contrib.auth.models import User
import uuid
from ..status_code import *
class ChangePasswordTest(TestCase):
def setUp(self):
self.client = Client()
self.url = "/api/accounts/change_password"
self.url = "/accounts/change_password"
self.username: str = str(uuid.uuid4())
self.password: str = str(uuid.uuid4())
@ -23,11 +21,11 @@ class ChangePasswordTest(TestCase):
def test_normal(self):
self.client.login(username = self.username, password = self.password)
response: HttpResponse = self.client.post(self.url, {"new_password": self.new_password})
response: HttpResponse = self.client.post(self.url, {"current_password": self.password, "new_password": self.new_password})
response_text: str = response.content.decode('utf-8')
self.assertEqual(response_text, USER_PASSWORD_UPDATED)
self.assertEqual(response_text, '"password changed"')
def test_nologged(self):
response: HttpResponse = self.client.post(self.url, {"new_password": self.new_password})
response_text: str = response.content.decode('utf-8')
self.assertEqual(response_text, '')
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.'})