2016-06-13 00:00:30 +00:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.contrib.sites.models import Site
|
2016-06-19 23:00:08 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
2016-06-12 21:39:04 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2016-06-14 19:39:04 +00:00
|
|
|
from accounts.models import Participation
|
2016-06-13 00:00:30 +00:00
|
|
|
|
2016-06-19 23:00:08 +00:00
|
|
|
from .models import ConversationWithParticipant, Message
|
2016-06-13 00:00:30 +00:00
|
|
|
|
2016-06-12 23:32:05 +00:00
|
|
|
|
|
|
|
class ConversationTests(TestCase):
|
2016-06-13 00:00:30 +00:00
|
|
|
def setUp(self):
|
2016-06-19 23:00:08 +00:00
|
|
|
a, b, c = (User.objects.create_user(guy, email='%s@example.org' % guy, password=guy) for guy in 'abc')
|
|
|
|
pa, _ = Participation.objects.get_or_create(user=a, site=Site.objects.first())
|
|
|
|
conversation, _ = ConversationWithParticipant.objects.get_or_create(participation=pa)
|
|
|
|
Message.objects.create(content='allo', conversation=conversation, author=b)
|
2016-06-13 00:00:30 +00:00
|
|
|
|
|
|
|
def test_models(self):
|
2016-06-19 23:00:08 +00:00
|
|
|
self.assertEqual(str(ConversationWithParticipant.objects.first()), 'Conversation with a')
|
|
|
|
self.assertEqual(str(Message.objects.first()), 'Message from b')
|
2016-06-13 00:00:30 +00:00
|
|
|
|
|
|
|
def test_views(self):
|
2016-06-19 23:00:08 +00:00
|
|
|
url = ConversationWithParticipant.objects.first().get_absolute_url()
|
|
|
|
self.assertEqual(self.client.get(url).status_code, 302)
|
|
|
|
self.client.login(username='c', password='c')
|
|
|
|
self.assertEqual(self.client.get(url).status_code, 403)
|
|
|
|
self.assertEqual(self.client.get(reverse('correspondents')).status_code, 200)
|
|
|
|
self.assertEqual(self.client.get(reverse('inbox')).status_code, 200)
|
|
|
|
self.client.post(reverse('inbox'), {'content': 'coucou'})
|