ft_transcendence/accounts/tests/delete.py

37 lines
1.5 KiB
Python
Raw Permalink 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 DeleteTest(TestCase):
def setUp(self):
self.client = Client()
2023-11-30 07:39:22 -05:00
self.url = "/api/accounts/delete"
2023-10-25 10:17:55 -04:00
self.username: str = str(uuid.uuid4())
self.password: str = str(uuid.uuid4())
2023-10-25 10:17:55 -04:00
user: User = User.objects.create_user(username=self.username, password=self.password)
self.client.login(username=self.username, password=self.password)
2023-10-25 10:17:55 -04:00
def test_normal_delete(self):
2023-11-30 19:29:56 -05:00
response: HttpResponse = self.client.delete(self.url, {"password": self.password}, content_type='application/json')
2023-10-25 10:17:55 -04:00
response_text: str = response.content.decode("utf-8")
2023-11-11 13:50:14 -05:00
self.assertEqual(response_text, '"user deleted"')
2023-10-25 10:17:55 -04:00
2023-11-30 19:29:56 -05:00
def test_wrong_pass(self):
response: HttpResponse = self.client.delete(self.url, {"password": "cacaman a frapper"}, content_type='application/json')
errors: dict = eval(response.content)
self.assertDictEqual(errors, {"password": ["Password wrong."]})
def test_no_logged(self):
self.client.logout()
2023-11-30 19:29:56 -05:00
response: HttpResponse = self.client.delete(self.url, {"password": self.password}, content_type='application/json')
2023-11-11 13:50:14 -05:00
errors: dict = eval(response.content)
self.assertDictEqual(errors, {"detail":"Authentication credentials were not provided."})