ft_transcendence/chat/tests.py

31 lines
1.1 KiB
Python
Raw Normal View History

2023-11-27 17:31:31 -05:00
from django.test import TestCase
2023-12-27 10:14:39 -05:00
from django.test.client import Client
from django.http import HttpResponse, HttpRequest
from django.contrib.auth.models import User
2023-11-27 17:31:31 -05:00
# Create your tests here.
2023-12-27 10:14:39 -05:00
class ChatTest(TestCase):
def setUp(self):
self.client = Client()
self.username='bozo1'
self.password='password'
self.user: User = User.objects.create_user(username=self.username, password=self.password)
self.dest: User = User.objects.create_user(username="bozo2", password=self.password)
self.url = "/api/chat/"
def test_create_chat(self):
self.client.login(username=self.username, password=self.password)
response: HttpResponse = self.client.post(self.url + str(self.user.pk), {"members_id": [self.user.pk, self.dest.pk]})
response_dict: dict = eval(response.content)
self.assertDictEqual(response_dict, {})
def test_create_chat_unlogged(self):
response: HttpResponse = self.client.post(self.url + str(self.user.pk), {"members_id": [self.user.pk, self.dest.pk]})
response_dict: dict = eval(response.content)
self.assertDictEqual(response_dict, {'detail': 'Authentication credentials were not provided.'})