2019-04-23 16:57:35 +02:00
|
|
|
from openslides.agenda.models import ListOfSpeakers, Speaker
|
2016-09-18 22:14:24 +02:00
|
|
|
from openslides.topics.models import Topic
|
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
|
2019-10-18 14:18:49 +02:00
|
|
|
from tests.test_case import TestCase
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ListOfSpeakerModelTests(TestCase):
|
|
|
|
def setUp(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
self.list_of_speakers_1 = Topic.objects.create(
|
|
|
|
title="list_of_speakers_1"
|
|
|
|
).list_of_speakers
|
|
|
|
self.list_of_speakers_2 = Topic.objects.create(
|
|
|
|
title="list_of_speakers_2"
|
|
|
|
).list_of_speakers
|
2019-01-06 16:22:33 +01:00
|
|
|
self.speaker1 = User.objects.create(username="user1")
|
|
|
|
self.speaker2 = User.objects.create(username="user2")
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
def test_append_speaker(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
# Append speaker1 to the list of list_of_speakers_1
|
|
|
|
speaker1_los1 = Speaker.objects.add(self.speaker1, self.list_of_speakers_1)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue(
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.filter(
|
|
|
|
user=self.speaker1, list_of_speakers=self.list_of_speakers_1
|
|
|
|
).exists()
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
# Append speaker1 to the list of list_of_speakers_2
|
|
|
|
speaker1_los2 = Speaker.objects.add(self.speaker1, self.list_of_speakers_2)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue(
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.filter(
|
|
|
|
user=self.speaker1, list_of_speakers=self.list_of_speakers_2
|
|
|
|
).exists()
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
# Append speaker2 to the list of list_of_speakers_1
|
|
|
|
speaker2_los1 = Speaker.objects.add(self.speaker2, self.list_of_speakers_1)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue(
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.filter(
|
|
|
|
user=self.speaker2, list_of_speakers=self.list_of_speakers_1
|
|
|
|
).exists()
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
# Try to append speaker 1 again to the list of list_of_speakers_1
|
2013-03-18 12:34:47 +01:00
|
|
|
with self.assertRaises(OpenSlidesError):
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.add(self.speaker1, self.list_of_speakers_1)
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
# Check time and weight
|
2019-04-23 16:57:35 +02:00
|
|
|
for object in (speaker1_los1, speaker2_los1, speaker1_los2):
|
2013-04-25 16:18:16 +02:00
|
|
|
self.assertIsNone(object.begin_time)
|
|
|
|
self.assertIsNone(object.end_time)
|
2019-04-23 16:57:35 +02:00
|
|
|
self.assertEqual(speaker1_los1.weight, 1)
|
|
|
|
self.assertEqual(speaker1_los2.weight, 1)
|
|
|
|
self.assertEqual(speaker2_los1.weight, 2)
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
def test_open_close_list_of_speaker(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
self.assertFalse(
|
|
|
|
ListOfSpeakers.objects.get(pk=self.list_of_speakers_1.pk).closed
|
|
|
|
)
|
|
|
|
self.list_of_speakers_1.closed = True
|
|
|
|
self.list_of_speakers_1.save()
|
|
|
|
self.assertTrue(
|
|
|
|
ListOfSpeakers.objects.get(pk=self.list_of_speakers_1.pk).closed
|
|
|
|
)
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2013-04-25 16:18:16 +02:00
|
|
|
def test_speak_and_finish(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
speaker1_los1 = Speaker.objects.add(self.speaker1, self.list_of_speakers_1)
|
|
|
|
self.assertIsNone(speaker1_los1.begin_time)
|
|
|
|
self.assertIsNone(speaker1_los1.end_time)
|
|
|
|
speaker1_los1.begin_speech()
|
|
|
|
self.assertIsNotNone(Speaker.objects.get(pk=speaker1_los1.pk).begin_time)
|
|
|
|
self.assertIsNone(Speaker.objects.get(pk=speaker1_los1.pk).weight)
|
|
|
|
speaker1_los1.end_speech()
|
|
|
|
self.assertIsNotNone(Speaker.objects.get(pk=speaker1_los1.pk).end_time)
|
2013-04-25 16:18:16 +02:00
|
|
|
|
|
|
|
def test_finish_when_other_speaker_begins(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
speaker1_los1 = Speaker.objects.add(self.speaker1, self.list_of_speakers_1)
|
|
|
|
speaker2_los1 = Speaker.objects.add(self.speaker2, self.list_of_speakers_1)
|
|
|
|
speaker1_los1.begin_speech()
|
|
|
|
self.assertIsNone(speaker1_los1.end_time)
|
|
|
|
self.assertIsNone(speaker2_los1.begin_time)
|
|
|
|
speaker2_los1.begin_speech()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertIsNotNone(
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.get(
|
|
|
|
user=self.speaker1, list_of_speakers=self.list_of_speakers_1
|
|
|
|
).end_time
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2019-04-23 16:57:35 +02:00
|
|
|
self.assertIsNotNone(speaker2_los1.begin_time)
|