2013-03-18 12:34:47 +01:00
|
|
|
from openslides.agenda.models import Item, Speaker
|
2014-10-11 14:34:49 +02:00
|
|
|
from openslides.users.models import User
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.utils.exceptions import OpenSlidesError
|
|
|
|
from openslides.utils.test import TestCase
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ListOfSpeakerModelTests(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.item1 = Item.objects.create(title='item1')
|
|
|
|
self.item2 = Item.objects.create(title='item2')
|
|
|
|
self.speaker1 = User.objects.create(username='user1')
|
|
|
|
self.speaker2 = User.objects.create(username='user2')
|
|
|
|
|
|
|
|
def test_append_speaker(self):
|
|
|
|
# Append speaker1 to the list of item1
|
|
|
|
speaker1_item1 = Speaker.objects.add(self.speaker1, self.item1)
|
2014-10-11 14:34:49 +02:00
|
|
|
self.assertTrue(Speaker.objects.filter(user=self.speaker1, item=self.item1).exists())
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
# Append speaker1 to the list of item2
|
|
|
|
speaker1_item2 = Speaker.objects.add(self.speaker1, self.item2)
|
2014-10-11 14:34:49 +02:00
|
|
|
self.assertTrue(Speaker.objects.filter(user=self.speaker1, item=self.item2).exists())
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
# Append speaker2 to the list of item1
|
|
|
|
speaker2_item1 = Speaker.objects.add(self.speaker2, self.item1)
|
2014-10-11 14:34:49 +02:00
|
|
|
self.assertTrue(Speaker.objects.filter(user=self.speaker2, item=self.item1).exists())
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
# Try to append speaker 1 again to the list of item1
|
|
|
|
with self.assertRaises(OpenSlidesError):
|
|
|
|
Speaker.objects.add(self.speaker1, self.item1)
|
|
|
|
|
|
|
|
# Check time and weight
|
|
|
|
for object in (speaker1_item1, speaker2_item1, speaker1_item2):
|
2013-04-25 16:18:16 +02:00
|
|
|
self.assertIsNone(object.begin_time)
|
|
|
|
self.assertIsNone(object.end_time)
|
2013-03-18 12:34:47 +01:00
|
|
|
self.assertEqual(speaker1_item1.weight, 1)
|
|
|
|
self.assertEqual(speaker1_item2.weight, 1)
|
|
|
|
self.assertEqual(speaker2_item1.weight, 2)
|
|
|
|
|
|
|
|
def test_open_close_list_of_speaker(self):
|
|
|
|
self.assertFalse(Item.objects.get(pk=self.item1.pk).speaker_list_closed)
|
|
|
|
self.item1.speaker_list_closed = True
|
|
|
|
self.item1.save()
|
|
|
|
self.assertTrue(Item.objects.get(pk=self.item1.pk).speaker_list_closed)
|
|
|
|
|
2013-04-25 16:18:16 +02:00
|
|
|
def test_speak_and_finish(self):
|
2013-03-18 12:34:47 +01:00
|
|
|
speaker1_item1 = Speaker.objects.add(self.speaker1, self.item1)
|
2013-04-25 16:18:16 +02:00
|
|
|
self.assertIsNone(speaker1_item1.begin_time)
|
|
|
|
self.assertIsNone(speaker1_item1.end_time)
|
|
|
|
speaker1_item1.begin_speach()
|
|
|
|
self.assertIsNotNone(Speaker.objects.get(pk=speaker1_item1.pk).begin_time)
|
2013-03-18 12:34:47 +01:00
|
|
|
self.assertIsNone(Speaker.objects.get(pk=speaker1_item1.pk).weight)
|
2013-04-25 16:18:16 +02:00
|
|
|
speaker1_item1.end_speach()
|
|
|
|
self.assertIsNotNone(Speaker.objects.get(pk=speaker1_item1.pk).end_time)
|
|
|
|
|
|
|
|
def test_finish_when_other_speaker_begins(self):
|
|
|
|
speaker1_item1 = Speaker.objects.add(self.speaker1, self.item1)
|
|
|
|
speaker2_item1 = Speaker.objects.add(self.speaker2, self.item1)
|
|
|
|
speaker1_item1.begin_speach()
|
|
|
|
self.assertIsNone(speaker1_item1.end_time)
|
|
|
|
self.assertIsNone(speaker2_item1.begin_time)
|
|
|
|
speaker2_item1.begin_speach()
|
2014-10-11 14:34:49 +02:00
|
|
|
self.assertIsNotNone(Speaker.objects.get(user=self.speaker1, item=self.item1).end_time)
|
2013-04-25 16:18:16 +02:00
|
|
|
self.assertIsNotNone(speaker2_item1.begin_time)
|