ft_transcendence/accounts/tests/delete.py

32 lines
1.1 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 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 07:41:31 -05:00
response: HttpResponse = self.client.delete(self.url)
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
def test_no_logged(self):
self.client.logout()
response: HttpResponse = self.client.post(self.url)
2023-11-11 13:50:14 -05:00
errors: dict = eval(response.content)
self.assertDictEqual(errors, {"detail":"Authentication credentials were not provided."})