2018-07-09 23:22:26 +02:00
|
|
|
import pytest
|
2015-05-26 18:21:30 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
2019-04-23 16:57:35 +02:00
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
2018-07-09 23:22:26 +02:00
|
|
|
from django.urls import reverse
|
2019-10-07 17:34:19 +02:00
|
|
|
from django.utils import timezone
|
2016-03-04 11:24:22 +01:00
|
|
|
from rest_framework import status
|
2015-05-26 18:21:30 +02:00
|
|
|
from rest_framework.test import APIClient
|
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
from openslides.agenda.models import Item, ListOfSpeakers, Speaker
|
2016-09-18 16:00:31 +02:00
|
|
|
from openslides.assignments.models import Assignment
|
2015-09-05 14:58:10 +02:00
|
|
|
from openslides.core.config import config
|
2016-10-21 11:05:24 +02:00
|
|
|
from openslides.core.models import Countdown
|
2019-04-23 16:57:35 +02:00
|
|
|
from openslides.mediafiles.models import Mediafile
|
2019-11-04 14:56:01 +01:00
|
|
|
from openslides.motions.models import Motion, MotionBlock
|
2016-09-18 22:14:24 +02:00
|
|
|
from openslides.topics.models import Topic
|
2019-11-01 09:11:12 +01:00
|
|
|
from tests.count_queries import count_queries
|
2019-10-18 14:18:49 +02:00
|
|
|
from tests.test_case import TestCase
|
2015-05-26 18:21:30 +02:00
|
|
|
|
|
|
|
|
2019-11-04 14:56:01 +01:00
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_agenda_item_db_queries():
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
|
|
|
* 1 request to get the list of all agenda items,
|
|
|
|
* 1 request to get all assignments,
|
|
|
|
* 1 request to get all motions,
|
|
|
|
* 1 request to get all topics,
|
|
|
|
* 1 request to get all motion blocks and
|
|
|
|
* 1 request to get all parents
|
2020-05-14 15:07:59 +02:00
|
|
|
* 1 request to get all tags
|
2019-11-04 14:56:01 +01:00
|
|
|
"""
|
|
|
|
parent = Topic.objects.create(title="parent").agenda_item
|
|
|
|
for index in range(10):
|
|
|
|
item = Topic.objects.create(title=f"topic{index}").agenda_item
|
|
|
|
item.parent = parent
|
|
|
|
item.save()
|
|
|
|
Motion.objects.create(title="motion1")
|
|
|
|
Motion.objects.create(title="motion2")
|
|
|
|
Assignment.objects.create(title="assignment1", open_posts=5)
|
|
|
|
Assignment.objects.create(title="assignment2", open_posts=5)
|
|
|
|
MotionBlock.objects.create(title="block1")
|
|
|
|
MotionBlock.objects.create(title="block1")
|
|
|
|
|
2020-05-14 15:07:59 +02:00
|
|
|
assert count_queries(Item.get_elements)() == 7
|
2019-11-04 14:56:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_list_of_speakers_db_queries():
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
|
|
|
* 1 requests to get the list of all lists of speakers
|
|
|
|
* 1 request to get all speakers
|
|
|
|
* 4 requests to get the assignments, motions, topics and mediafiles and
|
|
|
|
"""
|
|
|
|
for index in range(10):
|
|
|
|
Topic.objects.create(title=f"topic{index}")
|
|
|
|
parent = Topic.objects.create(title="parent").agenda_item
|
|
|
|
child = Topic.objects.create(title="child").agenda_item
|
|
|
|
child.parent = parent
|
|
|
|
child.save()
|
|
|
|
Motion.objects.create(title="motion1")
|
|
|
|
Motion.objects.create(title="motion2")
|
|
|
|
Assignment.objects.create(title="assignment", open_posts=5)
|
|
|
|
Mediafile.objects.create(
|
2020-05-13 16:16:03 +02:00
|
|
|
title="mediafile", mediafile=SimpleUploadedFile("some_file", b"some content.")
|
2019-11-04 14:56:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
assert count_queries(ListOfSpeakers.get_elements)() == 6
|
|
|
|
|
|
|
|
|
2019-02-25 11:12:58 +01:00
|
|
|
class ContentObjects(TestCase):
|
|
|
|
"""
|
2019-04-23 16:57:35 +02:00
|
|
|
Tests content objects with Topic as a content object of items and
|
|
|
|
lists of speakers. Asserts, that it is recognizes as a content
|
|
|
|
object and tests creation and deletion of it and the related item
|
|
|
|
and list of speaker.
|
2019-06-03 17:04:30 +02:00
|
|
|
Tests optional agenda items with motions, e.g. motion as a content
|
|
|
|
object without an item.
|
2019-02-25 11:12:58 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
|
|
|
self.client.login(username="admin", password="admin")
|
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
def test_topic_is_agenda_item_content_object(self):
|
2019-02-25 11:12:58 +01:00
|
|
|
assert hasattr(Topic(), "get_agenda_title_information")
|
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
def test_topic_is_list_of_speakers_content_object(self):
|
|
|
|
assert hasattr(Topic(), "get_list_of_speakers_title_information")
|
|
|
|
|
2019-06-03 17:04:30 +02:00
|
|
|
def test_motion_is_agenda_item_content_object(self):
|
|
|
|
assert hasattr(Motion(), "get_agenda_title_information")
|
|
|
|
|
|
|
|
def test_motion_is_list_of_speakers_content_object(self):
|
|
|
|
assert hasattr(Motion(), "get_list_of_speakers_title_information")
|
|
|
|
|
|
|
|
def test_create_topic(self):
|
|
|
|
# Disable autocreation. Topics should create agenda items anyways.
|
|
|
|
config["agenda_item_creation"] = "never"
|
2019-02-25 11:12:58 +01:00
|
|
|
topic = Topic.objects.create(title="test_title_fk3Oc209JDiunw2!wwoH")
|
|
|
|
|
|
|
|
assert topic.agenda_item is not None
|
2019-04-23 16:57:35 +02:00
|
|
|
assert topic.list_of_speakers is not None
|
2019-02-25 11:12:58 +01:00
|
|
|
|
2019-06-03 17:04:30 +02:00
|
|
|
def test_delete_topic(self):
|
2019-02-25 11:12:58 +01:00
|
|
|
topic = Topic.objects.create(title="test_title_lwOCK32jZGFb37DpmoP(")
|
2019-04-23 16:57:35 +02:00
|
|
|
item_id = topic.agenda_item_id
|
|
|
|
list_of_speakers_id = topic.list_of_speakers_id
|
2019-02-25 11:12:58 +01:00
|
|
|
topic.delete()
|
2021-03-04 16:15:57 +01:00
|
|
|
self.assertFalse(Item.objects.filter(pk=item_id).exists())
|
|
|
|
self.assertFalse(ListOfSpeakers.objects.filter(pk=list_of_speakers_id).exists())
|
2019-02-25 11:12:58 +01:00
|
|
|
|
2019-06-03 17:04:30 +02:00
|
|
|
def test_prevent_removing_topic_from_agenda(self):
|
|
|
|
topic = Topic.objects.create(title="test_title_lwOCK32jZGFb37DpmoP(")
|
|
|
|
item_id = topic.agenda_item_id
|
|
|
|
response = self.client.delete(reverse("item-detail", args=[item_id]))
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
|
|
def test_adding_topic_twice(self):
|
|
|
|
topic = Topic.objects.create(title="test_title_lwOCK32jZGFb37DpmoP(")
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("item-list"),
|
|
|
|
{"collection": topic.get_collection_string(), "id": topic.id},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
|
|
def test_enabled_auto_adding_item_for_motion(self):
|
|
|
|
config["agenda_item_creation"] = "always"
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("motion-list"),
|
|
|
|
{
|
|
|
|
"title": "test_title_F3pApc3em9zIGCie2iwf",
|
|
|
|
"text": "test_text_wcnLVzezeLcnqlqlC(31",
|
|
|
|
"agenda_create": False,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
motion = Motion.objects.get()
|
|
|
|
self.assertTrue(motion.agenda_item is not None)
|
|
|
|
self.assertEqual(motion.agenda_item_id, motion.agenda_item.id)
|
|
|
|
|
|
|
|
def test_disabled_auto_adding_item_for_motion(self):
|
|
|
|
config["agenda_item_creation"] = "never"
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("motion-list"),
|
|
|
|
{
|
|
|
|
"title": "test_title_OoCoo3MeiT9li5Iengu9",
|
|
|
|
"text": "test_text_thuoz0iecheiheereiCi",
|
|
|
|
"agenda_create": True,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
motion = Motion.objects.get()
|
|
|
|
self.assertTrue(motion.agenda_item is None)
|
|
|
|
self.assertTrue(motion.agenda_item_id is None)
|
|
|
|
|
|
|
|
def test_ask_auto_adding_item_for_motion(self):
|
|
|
|
config["agenda_item_creation"] = "default_no"
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("motion-list"),
|
|
|
|
{
|
|
|
|
"title": "test_title_wvlvowievgbpypoOV332",
|
|
|
|
"text": "test_text_tvewpxxcw9r72qNVV3uq",
|
|
|
|
"agenda_create": True,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
motion = Motion.objects.get()
|
|
|
|
self.assertTrue(motion.agenda_item is not None)
|
|
|
|
self.assertEqual(motion.agenda_item_id, motion.agenda_item.id)
|
|
|
|
|
2019-02-25 11:12:58 +01:00
|
|
|
|
2015-05-26 18:21:30 +02:00
|
|
|
class ManageSpeaker(TestCase):
|
|
|
|
"""
|
|
|
|
Tests managing speakers.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2019-10-18 14:18:49 +02:00
|
|
|
def advancedSetUp(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
self.list_of_speakers = Topic.objects.create(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_aZaedij4gohn5eeQu8fe"
|
2019-04-23 16:57:35 +02:00
|
|
|
).list_of_speakers
|
2019-10-18 14:18:49 +02:00
|
|
|
self.user, _ = self.create_user()
|
2020-10-14 15:08:14 +02:00
|
|
|
self.admin = get_user_model().objects.get(username="admin")
|
2019-10-07 17:34:19 +02:00
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
def test_add_oneself_once(self):
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk])
|
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertTrue(Speaker.objects.all().exists())
|
|
|
|
|
|
|
|
def test_add_oneself_twice(self):
|
2020-10-14 15:08:14 +02:00
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers)
|
2019-04-23 16:57:35 +02:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk])
|
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_add_oneself_when_closed(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
self.list_of_speakers.closed = True
|
|
|
|
self.list_of_speakers.save()
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk])
|
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_remove_oneself(self):
|
2020-10-14 15:08:14 +02:00
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers)
|
|
|
|
response = self.client.delete(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk])
|
2019-04-23 16:57:35 +02:00
|
|
|
)
|
2020-10-14 15:08:14 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertFalse(Speaker.objects.all().exists())
|
|
|
|
|
|
|
|
def test_remove_oneself_if_twice_on_los(self):
|
|
|
|
# This one is a test, if there is malformed speaker data, that
|
|
|
|
# this method still works.
|
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers)
|
|
|
|
s2 = Speaker(user=self.admin, list_of_speakers=self.list_of_speakers, weight=2)
|
|
|
|
s2.save()
|
2015-05-26 18:21:30 +02:00
|
|
|
response = self.client.delete(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk])
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertFalse(Speaker.objects.all().exists())
|
|
|
|
|
|
|
|
def test_remove_self_not_on_list(self):
|
|
|
|
response = self.client.delete(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk])
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_add_someone_else(self):
|
|
|
|
response = self.client.post(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"user": self.user.pk},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-04-23 16:57:35 +02:00
|
|
|
self.assertTrue(
|
|
|
|
Speaker.objects.filter(
|
|
|
|
list_of_speakers=self.list_of_speakers, user=self.user
|
|
|
|
).exists()
|
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
|
2020-11-09 08:54:41 +01:00
|
|
|
def test_add_someone_else_no_id(self):
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"user": ["not valid"]},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
2020-10-14 15:08:14 +02:00
|
|
|
def test_point_of_order_single(self):
|
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 0)
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 1)
|
|
|
|
self.assertTrue(Speaker.objects.get().point_of_order)
|
2021-02-10 15:58:01 +01:00
|
|
|
self.assertEqual(Speaker.objects.get().weight, 1)
|
2020-10-14 15:08:14 +02:00
|
|
|
|
|
|
|
def test_point_of_order_not_enabled(self):
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 0)
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 0)
|
|
|
|
|
2021-02-03 09:15:13 +01:00
|
|
|
def test_point_of_order_before_normal(self):
|
2020-10-14 15:08:14 +02:00
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
normal_speaker = Speaker.objects.add(self.user, self.list_of_speakers)
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 2)
|
|
|
|
poo_speaker = Speaker.objects.get(user=self.admin)
|
|
|
|
self.assertTrue(poo_speaker.point_of_order)
|
|
|
|
self.assertEqual(poo_speaker.weight, normal_speaker.weight - 1)
|
|
|
|
|
2021-02-03 09:15:13 +01:00
|
|
|
def test_point_of_order_with_same_normal_speaker(self):
|
2020-10-14 15:08:14 +02:00
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers)
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 2)
|
2021-02-03 09:15:13 +01:00
|
|
|
self.assertEqual(Speaker.objects.filter(user=self.admin).count(), 2)
|
|
|
|
|
|
|
|
def test_point_of_order_two_poo_speakers(self):
|
2021-02-10 15:58:01 +01:00
|
|
|
"""
|
|
|
|
before (poo):
|
|
|
|
- user (y)
|
|
|
|
- user2 (n)
|
|
|
|
- user3 (n)
|
|
|
|
|
|
|
|
after adding admin as poo speaker:
|
|
|
|
- user (y)
|
|
|
|
- admin (y)
|
|
|
|
- user2 (n)
|
|
|
|
- user3 (n)
|
|
|
|
"""
|
2021-02-03 09:15:13 +01:00
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
# user 2 and user3 are non-poo speakers
|
|
|
|
self.user2, _ = self.create_user()
|
|
|
|
self.user3, _ = self.create_user()
|
|
|
|
Speaker.objects.add(self.user2, self.list_of_speakers)
|
|
|
|
Speaker.objects.add(self.user3, self.list_of_speakers)
|
|
|
|
Speaker.objects.add(self.user, self.list_of_speakers, point_of_order=True)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user).weight, 0)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user2).weight, 1)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user3).weight, 2)
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
2021-02-10 15:58:01 +01:00
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 4)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user).weight, 0)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.admin).weight, 1)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user2).weight, 2)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user3).weight, 3)
|
|
|
|
|
|
|
|
def test_point_of_order_two_poo_speakers_different_ordering(self):
|
|
|
|
"""
|
|
|
|
before (poo):
|
|
|
|
- user (n)
|
|
|
|
- user2 (y)
|
|
|
|
- user3 (n)
|
|
|
|
|
|
|
|
after adding admin as poo speaker (no weight modifications of other speakers!)
|
|
|
|
- admin (y)
|
|
|
|
- user (n)
|
|
|
|
- user2 (y)
|
|
|
|
- user3 (n)
|
|
|
|
"""
|
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
# user 2 and user3 are non-poo speakers
|
|
|
|
self.user2, _ = self.create_user()
|
|
|
|
self.user3, _ = self.create_user()
|
|
|
|
s_user = Speaker.objects.add(self.user, self.list_of_speakers)
|
|
|
|
s_user2 = Speaker.objects.add(
|
|
|
|
self.user2, self.list_of_speakers, point_of_order=True
|
|
|
|
)
|
|
|
|
s_user3 = Speaker.objects.add(self.user3, self.list_of_speakers)
|
|
|
|
|
|
|
|
# set different ordering
|
|
|
|
s_user.weight = 0
|
|
|
|
s_user.save()
|
|
|
|
s_user2.weight = 1
|
|
|
|
s_user2.save()
|
|
|
|
s_user3.weight = 2
|
|
|
|
s_user3.save()
|
|
|
|
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 4)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.admin).weight, -1)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user).weight, 0)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user2).weight, 1)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user3).weight, 2)
|
|
|
|
|
|
|
|
def test_point_of_order_three_poo_speakers(self):
|
|
|
|
"""
|
|
|
|
before (poo):
|
|
|
|
- user (y)
|
|
|
|
- user2 (n)
|
|
|
|
- user3 (y)
|
|
|
|
|
|
|
|
after adding admin as poo speaker (there are weight modifications of other speakers!)
|
|
|
|
- user (y)
|
|
|
|
- admin (y)
|
|
|
|
- user2 (n)
|
|
|
|
- user3 (y)
|
|
|
|
"""
|
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
# user 2 and user3 are non-poo speakers
|
|
|
|
self.user2, _ = self.create_user()
|
|
|
|
self.user3, _ = self.create_user()
|
|
|
|
s_user = Speaker.objects.add(
|
|
|
|
self.user, self.list_of_speakers, point_of_order=True
|
|
|
|
)
|
|
|
|
s_user2 = Speaker.objects.add(self.user2, self.list_of_speakers)
|
|
|
|
s_user3 = Speaker.objects.add(
|
|
|
|
self.user3, self.list_of_speakers, point_of_order=True
|
|
|
|
)
|
|
|
|
|
|
|
|
# set different ordering
|
|
|
|
s_user.weight = 0
|
|
|
|
s_user.save()
|
|
|
|
s_user2.weight = 1
|
|
|
|
s_user2.save()
|
|
|
|
s_user3.weight = 2
|
|
|
|
s_user3.save()
|
|
|
|
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
2021-02-03 09:15:13 +01:00
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 4)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user).weight, 0)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.admin).weight, 1)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user2).weight, 2)
|
|
|
|
self.assertEqual(Speaker.objects.get(user=self.user3).weight, 3)
|
2020-10-14 15:08:14 +02:00
|
|
|
|
|
|
|
def test_point_of_order_twice(self):
|
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers, point_of_order=True)
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 1)
|
|
|
|
|
|
|
|
def test_remove_point_of_order(self):
|
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers, point_of_order=True)
|
|
|
|
response = self.client.delete(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertFalse(Speaker.objects.all().exists())
|
|
|
|
|
|
|
|
def test_remove_point_of_order_with_normal_speaker(self):
|
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers)
|
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers, point_of_order=True)
|
|
|
|
response = self.client.delete(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"point_of_order": True},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 1)
|
|
|
|
self.assertFalse(Speaker.objects.get().point_of_order)
|
|
|
|
|
|
|
|
def test_remove_self_with_point_of_order(self):
|
|
|
|
config["agenda_enable_point_of_order_speakers"] = True
|
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers)
|
|
|
|
Speaker.objects.add(self.admin, self.list_of_speakers, point_of_order=True)
|
|
|
|
response = self.client.delete(
|
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk])
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(Speaker.objects.all().count(), 1)
|
|
|
|
self.assertTrue(Speaker.objects.get().point_of_order)
|
|
|
|
|
2015-05-26 18:21:30 +02:00
|
|
|
def test_invalid_data_string_instead_of_integer(self):
|
|
|
|
response = self.client.post(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
2019-01-06 16:22:33 +01:00
|
|
|
{"user": "string_instead_of_integer"},
|
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_invalid_data_user_does_not_exist(self):
|
|
|
|
# ID of a user that does not exist.
|
|
|
|
# Be careful: Here we do not test that the user does not exist.
|
|
|
|
inexistent_user_pk = self.user.pk + 1000
|
|
|
|
response = self.client.post(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
2019-01-06 16:22:33 +01:00
|
|
|
{"user": inexistent_user_pk},
|
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_add_someone_else_twice(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.add(self.user, self.list_of_speakers)
|
2015-05-26 18:21:30 +02:00
|
|
|
response = self.client.post(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"user": self.user.pk},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_add_someone_else_non_admin(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.make_admin_delegate()
|
2017-09-04 00:25:45 +02:00
|
|
|
|
2015-05-26 18:21:30 +02:00
|
|
|
response = self.client.post(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"user": self.user.pk},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_remove_someone_else(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
speaker = Speaker.objects.add(self.user, self.list_of_speakers)
|
2015-05-26 18:21:30 +02:00
|
|
|
response = self.client.delete(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"speaker": speaker.pk},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertFalse(
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.filter(
|
|
|
|
list_of_speakers=self.list_of_speakers, user=self.user
|
|
|
|
).exists()
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
|
|
|
|
def test_remove_someone_else_not_on_list(self):
|
|
|
|
response = self.client.delete(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"speaker": "1"},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2017-01-15 10:49:48 +01:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-05-26 18:21:30 +02:00
|
|
|
|
2015-05-27 15:42:32 +02:00
|
|
|
def test_remove_someone_else_invalid_data(self):
|
|
|
|
response = self.client.delete(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"speaker": "invalid"},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2017-01-15 10:49:48 +01:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-05-27 15:42:32 +02:00
|
|
|
|
2015-05-26 18:21:30 +02:00
|
|
|
def test_remove_someone_else_non_admin(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.make_admin_delegate()
|
2019-04-23 16:57:35 +02:00
|
|
|
speaker = Speaker.objects.add(self.user, self.list_of_speakers)
|
2017-09-04 00:25:45 +02:00
|
|
|
|
2015-05-26 18:21:30 +02:00
|
|
|
response = self.client.delete(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"speaker": speaker.pk},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-26 18:21:30 +02:00
|
|
|
self.assertEqual(response.status_code, 403)
|
2015-05-27 15:42:32 +02:00
|
|
|
|
2018-02-06 14:52:47 +01:00
|
|
|
def test_mark_speaker(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.add(self.user, self.list_of_speakers)
|
2018-02-06 14:52:47 +01:00
|
|
|
response = self.client.patch(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
2019-01-06 16:22:33 +01:00
|
|
|
{"user": self.user.pk, "marked": True},
|
2018-02-06 14:52:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertTrue(Speaker.objects.get().marked)
|
|
|
|
|
|
|
|
def test_mark_speaker_non_admin(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.make_admin_delegate()
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.add(self.user, self.list_of_speakers)
|
2018-02-06 14:52:47 +01:00
|
|
|
|
|
|
|
response = self.client.patch(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-manage-speaker", args=[self.list_of_speakers.pk]),
|
|
|
|
{"user": self.user.pk},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2018-02-06 14:52:47 +01:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2019-10-07 17:34:19 +02:00
|
|
|
# re-add last speaker
|
|
|
|
def util_add_user_as_last_speaker(self):
|
|
|
|
speaker = Speaker.objects.add(self.user, self.list_of_speakers)
|
|
|
|
speaker.begin_time = timezone.now()
|
|
|
|
speaker.end_time = timezone.now()
|
|
|
|
speaker.weight = None
|
|
|
|
speaker.save()
|
2020-10-14 15:08:14 +02:00
|
|
|
return speaker
|
2019-10-07 17:34:19 +02:00
|
|
|
|
|
|
|
def test_readd_last_speaker_no_speaker(self):
|
|
|
|
response = self.client.post(
|
|
|
|
reverse(
|
|
|
|
"listofspeakers-readd-last-speaker", args=[self.list_of_speakers.pk]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_readd_last_speaker_no_last_speaker(self):
|
|
|
|
Speaker.objects.add(self.user, self.list_of_speakers)
|
|
|
|
response = self.client.post(
|
|
|
|
reverse(
|
|
|
|
"listofspeakers-readd-last-speaker", args=[self.list_of_speakers.pk]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_readd_last_speaker_has_last_speaker_no_next_speaker(self):
|
|
|
|
self.util_add_user_as_last_speaker()
|
|
|
|
|
|
|
|
response = self.client.post(
|
|
|
|
reverse(
|
|
|
|
"listofspeakers-readd-last-speaker", args=[self.list_of_speakers.pk]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
speaker = Speaker.objects.get()
|
|
|
|
self.assertTrue(
|
|
|
|
speaker.begin_time is None
|
|
|
|
and speaker.end_time is None
|
|
|
|
and speaker.weight is not None
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_readd_last_speaker_has_last_speaker_and_next_speaker(self):
|
|
|
|
self.util_add_user_as_last_speaker()
|
|
|
|
user2 = get_user_model().objects.create_user(
|
|
|
|
username="test_user_KLGHjkHJKBhjJHGGJKJn",
|
|
|
|
password="test_password_JHt678VbhjuGhj76hjGA",
|
|
|
|
)
|
2019-10-16 09:40:04 +02:00
|
|
|
speaker2 = Speaker.objects.add(user2, self.list_of_speakers)
|
2019-10-07 17:34:19 +02:00
|
|
|
|
|
|
|
response = self.client.post(
|
|
|
|
reverse(
|
|
|
|
"listofspeakers-readd-last-speaker", args=[self.list_of_speakers.pk]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
speaker = Speaker.objects.get(user__pk=self.user.pk)
|
|
|
|
self.assertTrue(
|
|
|
|
speaker.begin_time is None
|
|
|
|
and speaker.end_time is None
|
|
|
|
and speaker.weight is not None
|
|
|
|
)
|
2019-10-16 09:40:04 +02:00
|
|
|
self.assertTrue(speaker.weight < speaker2.weight)
|
2019-10-07 17:34:19 +02:00
|
|
|
|
|
|
|
def test_readd_last_speaker_no_admin(self):
|
|
|
|
self.util_add_user_as_last_speaker()
|
2019-10-18 14:18:49 +02:00
|
|
|
self.make_admin_delegate()
|
2019-10-07 17:34:19 +02:00
|
|
|
|
|
|
|
response = self.client.post(
|
|
|
|
reverse(
|
|
|
|
"listofspeakers-readd-last-speaker", args=[self.list_of_speakers.pk]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2020-10-14 15:08:14 +02:00
|
|
|
def test_readd_last_speaker_already_waiting(self):
|
|
|
|
self.util_add_user_as_last_speaker()
|
|
|
|
Speaker.objects.add(self.user, self.list_of_speakers)
|
|
|
|
|
|
|
|
response = self.client.post(
|
|
|
|
reverse(
|
|
|
|
"listofspeakers-readd-last-speaker", args=[self.list_of_speakers.pk]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_readd_last_speaker_point_of_order(self):
|
|
|
|
speaker = self.util_add_user_as_last_speaker()
|
|
|
|
speaker.point_of_order = True
|
|
|
|
speaker.save()
|
|
|
|
|
|
|
|
response = self.client.post(
|
|
|
|
reverse(
|
|
|
|
"listofspeakers-readd-last-speaker", args=[self.list_of_speakers.pk]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
2015-05-27 15:42:32 +02:00
|
|
|
|
|
|
|
class Speak(TestCase):
|
|
|
|
"""
|
2015-09-04 18:24:41 +02:00
|
|
|
Tests view to begin or end speech.
|
2015-05-27 15:42:32 +02:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2015-05-27 15:42:32 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2019-04-23 16:57:35 +02:00
|
|
|
self.list_of_speakers = Topic.objects.create(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_KooDueco3zaiGhiraiho"
|
2019-04-23 16:57:35 +02:00
|
|
|
).list_of_speakers
|
2015-05-27 15:42:32 +02:00
|
|
|
self.user = get_user_model().objects.create_user(
|
2019-01-06 16:22:33 +01:00
|
|
|
username="test_user_Aigh4vohb3seecha4aa4",
|
|
|
|
password="test_password_eneupeeVo5deilixoo8j",
|
|
|
|
)
|
2015-05-27 15:42:32 +02:00
|
|
|
|
2015-09-04 18:24:41 +02:00
|
|
|
def test_begin_speech(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.add(self.user, self.list_of_speakers)
|
2019-01-06 16:22:33 +01:00
|
|
|
speaker = Speaker.objects.add(
|
2019-04-23 16:57:35 +02:00
|
|
|
get_user_model().objects.get(username="admin"), self.list_of_speakers
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-27 15:42:32 +02:00
|
|
|
self.assertTrue(Speaker.objects.get(pk=speaker.pk).begin_time is None)
|
|
|
|
response = self.client.put(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-speak", args=[self.list_of_speakers.pk]),
|
|
|
|
{"speaker": speaker.pk},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-27 15:42:32 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertFalse(Speaker.objects.get(pk=speaker.pk).begin_time is None)
|
|
|
|
|
2015-09-04 18:24:41 +02:00
|
|
|
def test_begin_speech_next_speaker(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
speaker = Speaker.objects.add(self.user, self.list_of_speakers)
|
|
|
|
Speaker.objects.add(
|
|
|
|
get_user_model().objects.get(username="admin"), self.list_of_speakers
|
|
|
|
)
|
2015-07-06 09:19:42 +02:00
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
response = self.client.put(
|
|
|
|
reverse("listofspeakers-speak", args=[self.list_of_speakers.pk])
|
|
|
|
)
|
2015-07-06 09:19:42 +02:00
|
|
|
|
2015-05-27 15:42:32 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertFalse(Speaker.objects.get(pk=speaker.pk).begin_time is None)
|
|
|
|
|
2015-09-04 18:24:41 +02:00
|
|
|
def test_begin_speech_invalid_speaker_id(self):
|
2015-05-27 15:42:32 +02:00
|
|
|
response = self.client.put(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-speak", args=[self.list_of_speakers.pk]),
|
|
|
|
{"speaker": "1"},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-27 15:42:32 +02:00
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
2015-09-04 18:24:41 +02:00
|
|
|
def test_begin_speech_invalid_data(self):
|
2015-05-27 15:42:32 +02:00
|
|
|
response = self.client.put(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-speak", args=[self.list_of_speakers.pk]),
|
|
|
|
{"speaker": "invalid"},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-05-27 15:42:32 +02:00
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
2015-09-04 18:24:41 +02:00
|
|
|
def test_end_speech(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
speaker = Speaker.objects.add(
|
2019-04-23 16:57:35 +02:00
|
|
|
get_user_model().objects.get(username="admin"), self.list_of_speakers
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-09-04 18:24:41 +02:00
|
|
|
speaker.begin_speech()
|
2015-05-27 15:42:32 +02:00
|
|
|
self.assertFalse(Speaker.objects.get(pk=speaker.pk).begin_time is None)
|
|
|
|
self.assertTrue(Speaker.objects.get(pk=speaker.pk).end_time is None)
|
2019-04-23 16:57:35 +02:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("listofspeakers-speak", args=[self.list_of_speakers.pk])
|
|
|
|
)
|
2015-05-27 15:42:32 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertFalse(Speaker.objects.get(pk=speaker.pk).end_time is None)
|
|
|
|
|
2015-09-04 18:24:41 +02:00
|
|
|
def test_end_speech_no_current_speaker(self):
|
2019-04-23 16:57:35 +02:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("listofspeakers-speak", args=[self.list_of_speakers.pk])
|
|
|
|
)
|
2015-05-27 15:42:32 +02:00
|
|
|
self.assertEqual(response.status_code, 400)
|
2015-09-05 14:58:10 +02:00
|
|
|
|
|
|
|
def test_begin_speech_with_countdown(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
config["agenda_couple_countdown_and_speakers"] = True
|
2019-04-23 16:57:35 +02:00
|
|
|
Speaker.objects.add(self.user, self.list_of_speakers)
|
2019-01-06 16:22:33 +01:00
|
|
|
speaker = Speaker.objects.add(
|
2019-04-23 16:57:35 +02:00
|
|
|
get_user_model().objects.get(username="admin"), self.list_of_speakers
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-09-05 14:58:10 +02:00
|
|
|
self.client.put(
|
2019-04-23 16:57:35 +02:00
|
|
|
reverse("listofspeakers-speak", args=[self.list_of_speakers.pk]),
|
|
|
|
{"speaker": speaker.pk},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2016-10-21 11:05:24 +02:00
|
|
|
# Countdown should be created with pk=1 and running
|
|
|
|
self.assertEqual(Countdown.objects.all().count(), 1)
|
|
|
|
countdown = Countdown.objects.get(pk=1)
|
|
|
|
self.assertTrue(countdown.running)
|
2015-09-05 14:58:10 +02:00
|
|
|
|
|
|
|
def test_end_speech_with_countdown(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
config["agenda_couple_countdown_and_speakers"] = True
|
|
|
|
speaker = Speaker.objects.add(
|
2019-04-23 16:57:35 +02:00
|
|
|
get_user_model().objects.get(username="admin"), self.list_of_speakers
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2015-09-05 14:58:10 +02:00
|
|
|
speaker.begin_speech()
|
2019-04-23 16:57:35 +02:00
|
|
|
self.client.delete(
|
|
|
|
reverse("listofspeakers-speak", args=[self.list_of_speakers.pk])
|
|
|
|
)
|
2016-10-21 11:05:24 +02:00
|
|
|
# Countdown should be created with pk=1 and stopped
|
|
|
|
self.assertEqual(Countdown.objects.all().count(), 1)
|
|
|
|
countdown = Countdown.objects.get(pk=1)
|
|
|
|
self.assertFalse(countdown.running)
|
2015-11-23 17:21:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Numbering(TestCase):
|
|
|
|
"""
|
|
|
|
Tests view to number the agenda
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2015-11-23 17:21:32 +01:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
|
|
|
self.item_1 = Topic.objects.create(
|
|
|
|
title="test_title_thuha8eef7ohXar3eech"
|
|
|
|
).agenda_item
|
2016-01-22 23:19:41 +01:00
|
|
|
self.item_1.type = Item.AGENDA_ITEM
|
2016-01-27 21:31:06 +01:00
|
|
|
self.item_1.weight = 1
|
2016-01-22 23:19:41 +01:00
|
|
|
self.item_1.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.item_2 = Topic.objects.create(
|
|
|
|
title="test_title_eisah7thuxa1eingaeLo"
|
|
|
|
).agenda_item
|
2016-01-22 23:19:41 +01:00
|
|
|
self.item_2.type = Item.AGENDA_ITEM
|
2015-11-23 17:21:32 +01:00
|
|
|
self.item_2.weight = 2
|
|
|
|
self.item_2.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.item_2_1 = Topic.objects.create(
|
|
|
|
title="test_title_Qui0audoaz5gie1phish"
|
|
|
|
).agenda_item
|
2016-01-22 23:19:41 +01:00
|
|
|
self.item_2_1.type = Item.AGENDA_ITEM
|
2015-11-23 17:21:32 +01:00
|
|
|
self.item_2_1.parent = self.item_2
|
|
|
|
self.item_2_1.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.item_3 = Topic.objects.create(
|
|
|
|
title="test_title_ah7tphisheineisgaeLo"
|
|
|
|
).agenda_item
|
2016-01-22 23:19:41 +01:00
|
|
|
self.item_3.type = Item.AGENDA_ITEM
|
2015-11-23 17:21:32 +01:00
|
|
|
self.item_3.weight = 3
|
|
|
|
self.item_3.save()
|
|
|
|
|
|
|
|
def test_numbering(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(reverse("item-numbering"))
|
2015-11-23 17:21:32 +01:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_1.pk).item_number, "1")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_2.pk).item_number, "2")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_2_1.pk).item_number, "2.1")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_3.pk).item_number, "3")
|
2015-11-23 17:21:32 +01:00
|
|
|
|
2018-04-11 12:35:42 +02:00
|
|
|
def test_deactivated_numbering(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
config["agenda_enable_numbering"] = False
|
2018-04-11 12:35:42 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(reverse("item-numbering"))
|
2018-04-11 12:35:42 +02:00
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
2015-11-23 17:21:32 +01:00
|
|
|
def test_roman_numbering(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
config["agenda_numeral_system"] = "roman"
|
2015-11-23 17:21:32 +01:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(reverse("item-numbering"))
|
2015-11-23 17:21:32 +01:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_1.pk).item_number, "I")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_2.pk).item_number, "II")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_2_1.pk).item_number, "II.1")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_3.pk).item_number, "III")
|
2015-11-23 17:21:32 +01:00
|
|
|
|
2018-08-15 11:15:54 +02:00
|
|
|
def test_with_internal_item(self):
|
|
|
|
self.item_2.type = Item.INTERNAL_ITEM
|
2015-11-23 17:21:32 +01:00
|
|
|
self.item_2.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(reverse("item-numbering"))
|
2015-11-23 17:21:32 +01:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_1.pk).item_number, "1")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_2.pk).item_number, "")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_2_1.pk).item_number, "")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_3.pk).item_number, "2")
|
2016-01-25 22:10:00 +01:00
|
|
|
|
2018-08-15 11:15:54 +02:00
|
|
|
def test_reset_numbering_with_internal_item(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
self.item_2.item_number = "test_number_Cieghae6ied5ool4hiem"
|
2018-08-15 11:15:54 +02:00
|
|
|
self.item_2.type = Item.INTERNAL_ITEM
|
2016-01-25 22:10:00 +01:00
|
|
|
self.item_2.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.item_2_1.item_number = "test_number_roQueTohg7fe1Is7aemu"
|
2016-01-25 22:10:00 +01:00
|
|
|
self.item_2_1.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(reverse("item-numbering"))
|
2016-01-25 22:10:00 +01:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_1.pk).item_number, "1")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_2.pk).item_number, "")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_2_1.pk).item_number, "")
|
|
|
|
self.assertEqual(Item.objects.get(pk=self.item_3.pk).item_number, "2")
|