2018-07-09 23:22:26 +02:00
|
|
|
import pytest
|
2015-04-30 19:13:28 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
2018-07-09 23:22:26 +02:00
|
|
|
from django.urls import reverse
|
2015-04-30 19:13:28 +02:00
|
|
|
from rest_framework import status
|
|
|
|
from rest_framework.test import APIClient
|
|
|
|
|
2015-06-29 12:08:15 +02:00
|
|
|
from openslides.core.config import config
|
2017-12-15 13:01:25 +01:00
|
|
|
from openslides.motions.models import (
|
|
|
|
Category,
|
|
|
|
Motion,
|
|
|
|
MotionBlock,
|
2018-10-25 15:11:38 +02:00
|
|
|
MotionChangeRecommendation,
|
2018-08-31 15:33:41 +02:00
|
|
|
MotionComment,
|
|
|
|
MotionCommentSection,
|
2017-12-15 13:01:25 +01:00
|
|
|
State,
|
2018-09-24 10:28:31 +02:00
|
|
|
StatuteParagraph,
|
2017-12-15 13:01:25 +01:00
|
|
|
Workflow,
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
from openslides.utils.auth import get_group_model
|
2018-09-01 08:00:00 +02:00
|
|
|
from openslides.utils.autoupdate import inform_changed_data
|
2019-10-18 14:18:49 +02:00
|
|
|
from tests.common_groups import GROUP_ADMIN_PK, GROUP_DELEGATE_PK, GROUP_STAFF_PK
|
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-04-30 19:13:28 +02:00
|
|
|
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_category_db_queries():
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2018-07-09 23:22:26 +02:00
|
|
|
Tests that only the following db queries are done:
|
|
|
|
* 1 requests to get the list of all categories.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2018-07-09 23:22:26 +02:00
|
|
|
for index in range(10):
|
2019-01-12 23:01:42 +01:00
|
|
|
Category.objects.create(name=f"category{index}")
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
assert count_queries(Category.get_elements) == 1
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
|
2018-09-24 10:28:31 +02:00
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_statute_paragraph_db_queries():
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
|
|
|
* 1 requests to get the list of all statute paragraphs.
|
|
|
|
"""
|
|
|
|
for index in range(10):
|
|
|
|
StatuteParagraph.objects.create(
|
2019-01-12 23:01:42 +01:00
|
|
|
title=f"statute_paragraph{index}", text=f"text{index}"
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
|
|
|
|
assert count_queries(StatuteParagraph.get_elements) == 1
|
|
|
|
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_workflow_db_queries():
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2018-07-09 23:22:26 +02:00
|
|
|
Tests that only the following db queries are done:
|
|
|
|
* 1 requests to get the list of all workflows,
|
|
|
|
* 1 request to get all states and
|
|
|
|
* 1 request to get the next states of all states.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
assert count_queries(Workflow.get_elements) == 3
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
|
2018-09-24 10:28:31 +02:00
|
|
|
class TestStatuteParagraphs(TestCase):
|
|
|
|
"""
|
|
|
|
Tests all CRUD operations of statute paragraphs.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-09-24 10:28:31 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2018-09-24 10:28:31 +02:00
|
|
|
|
|
|
|
def create_statute_paragraph(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
self.title = "test_title_fiWs82D0D)2kje3KDm2s"
|
|
|
|
self.text = "test_text_3jfjoDqm,S;cmor3DJwk"
|
|
|
|
self.cp = StatuteParagraph.objects.create(title=self.title, text=self.text)
|
2018-09-24 10:28:31 +02:00
|
|
|
|
|
|
|
def test_create_simple(self):
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("statuteparagraph-list"),
|
|
|
|
{
|
|
|
|
"title": "test_title_f3FM328cq)tzdU238df2",
|
|
|
|
"text": "test_text_2fb)BEjwdI38=kfemiRkcOW",
|
|
|
|
},
|
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
cp = StatuteParagraph.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(cp.title, "test_title_f3FM328cq)tzdU238df2")
|
|
|
|
self.assertEqual(cp.text, "test_text_2fb)BEjwdI38=kfemiRkcOW")
|
2018-09-24 10:28:31 +02:00
|
|
|
|
|
|
|
def test_create_without_data(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(reverse("statuteparagraph-list"), {})
|
2018-09-24 10:28:31 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(
|
|
|
|
response.data,
|
|
|
|
{"title": ["This field is required."], "text": ["This field is required."]},
|
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
|
|
|
|
def test_create_non_admin(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
self.admin = get_user_model().objects.get(username="admin")
|
2018-10-09 13:44:38 +02:00
|
|
|
self.admin.groups.add(GROUP_DELEGATE_PK)
|
|
|
|
self.admin.groups.remove(GROUP_ADMIN_PK)
|
2018-09-24 10:28:31 +02:00
|
|
|
inform_changed_data(self.admin)
|
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("statuteparagraph-list"),
|
|
|
|
{
|
|
|
|
"title": "test_title_f3(Dj2jdP39fjW2kdcwe",
|
|
|
|
"text": "test_text_vlC)=fwWmcwcpWMvnuw(",
|
|
|
|
},
|
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
|
|
|
|
def test_retrieve_simple(self):
|
|
|
|
self.create_statute_paragraph()
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.get(
|
|
|
|
reverse("statuteparagraph-detail", args=[self.cp.pk])
|
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(
|
|
|
|
sorted(response.data.keys()), sorted(("id", "title", "text", "weight"))
|
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
|
|
|
|
def test_update_simple(self):
|
|
|
|
self.create_statute_paragraph()
|
|
|
|
response = self.client.patch(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("statuteparagraph-detail", args=[self.cp.pk]),
|
|
|
|
{"text": "test_text_ke(czr/cwk1Sl2seeFwE"},
|
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
cp = StatuteParagraph.objects.get()
|
|
|
|
self.assertEqual(cp.title, self.title)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(cp.text, "test_text_ke(czr/cwk1Sl2seeFwE")
|
2018-09-24 10:28:31 +02:00
|
|
|
|
|
|
|
def test_update_non_admin(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
self.admin = get_user_model().objects.get(username="admin")
|
2018-10-09 13:44:38 +02:00
|
|
|
self.admin.groups.add(GROUP_DELEGATE_PK)
|
|
|
|
self.admin.groups.remove(GROUP_ADMIN_PK)
|
2018-09-24 10:28:31 +02:00
|
|
|
inform_changed_data(self.admin)
|
|
|
|
|
|
|
|
self.create_statute_paragraph()
|
|
|
|
response = self.client.patch(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("statuteparagraph-detail", args=[self.cp.pk]),
|
|
|
|
{"text": "test_text_ke(czr/cwk1Sl2seeFwE"},
|
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
cp = StatuteParagraph.objects.get()
|
|
|
|
self.assertEqual(cp.text, self.text)
|
|
|
|
|
|
|
|
def test_delete_simple(self):
|
|
|
|
self.create_statute_paragraph()
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("statuteparagraph-detail", args=[self.cp.pk])
|
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
|
|
|
self.assertEqual(StatuteParagraph.objects.count(), 0)
|
|
|
|
|
|
|
|
def test_delete_non_admin(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
self.admin = get_user_model().objects.get(username="admin")
|
2018-10-09 13:44:38 +02:00
|
|
|
self.admin.groups.add(GROUP_DELEGATE_PK)
|
|
|
|
self.admin.groups.remove(GROUP_ADMIN_PK)
|
2018-09-24 10:28:31 +02:00
|
|
|
inform_changed_data(self.admin)
|
|
|
|
|
|
|
|
self.create_statute_paragraph()
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("statuteparagraph-detail", args=[self.cp.pk])
|
|
|
|
)
|
2018-09-24 10:28:31 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
self.assertEqual(StatuteParagraph.objects.count(), 1)
|
|
|
|
|
|
|
|
|
2018-08-31 15:33:41 +02:00
|
|
|
class ManageComments(TestCase):
|
|
|
|
"""
|
|
|
|
Tests the manage_comment view.
|
|
|
|
|
|
|
|
Tests creation/updating and deletion of motion comments.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-08-31 15:33:41 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
self.admin = get_user_model().objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.group_out = get_group_model().objects.get(
|
|
|
|
pk=GROUP_DELEGATE_PK
|
|
|
|
) # The admin should not be in this group
|
2018-10-09 13:44:38 +02:00
|
|
|
|
|
|
|
# Put the admin into the staff group, becaust in the admin group, he has all permissions for
|
|
|
|
# every single comment section.
|
|
|
|
self.admin.groups.add(GROUP_STAFF_PK)
|
|
|
|
self.admin.groups.remove(GROUP_ADMIN_PK)
|
|
|
|
inform_changed_data(self.admin)
|
|
|
|
self.group_in = get_group_model().objects.get(pk=GROUP_STAFF_PK)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
self.motion = Motion(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_SlqfMw(waso0saWMPqcZ",
|
|
|
|
text="test_text_f30skclqS9wWF=xdfaSL",
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.motion.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
self.section_no_groups = MotionCommentSection(
|
|
|
|
name='test_name_gj4F§(fj"(edm"§F3f3fs'
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.section_no_groups.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
self.section_read = MotionCommentSection(name="test_name_2wv30(d2S&kvelkakl39")
|
2018-08-31 15:33:41 +02:00
|
|
|
self.section_read.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.section_read.read_groups.add(
|
|
|
|
self.group_in, self.group_out
|
|
|
|
) # Group out for testing multiple groups
|
2018-08-31 15:33:41 +02:00
|
|
|
self.section_read.write_groups.add(self.group_out)
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
self.section_read_write = MotionCommentSection(
|
|
|
|
name="test_name_a3m9sd0(Mw2%slkrv30,"
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.section_read_write.save()
|
|
|
|
self.section_read_write.read_groups.add(self.group_in)
|
|
|
|
self.section_read_write.write_groups.add(self.group_in)
|
|
|
|
|
|
|
|
def test_retrieve_comment(self):
|
|
|
|
comment = MotionComment(
|
|
|
|
motion=self.motion,
|
|
|
|
section=self.section_read_write,
|
2019-01-06 16:22:33 +01:00
|
|
|
comment="test_comment_gwic37Csc&3lf3eo2",
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
comment.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.get(reverse("motion-detail", args=[self.motion.pk]))
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue("comments" in response.data)
|
|
|
|
comments = response.data["comments"]
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertTrue(isinstance(comments, list))
|
|
|
|
self.assertEqual(len(comments), 1)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(comments[0]["comment"], "test_comment_gwic37Csc&3lf3eo2")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_retrieve_comment_no_read_permission(self):
|
|
|
|
comment = MotionComment(
|
|
|
|
motion=self.motion,
|
|
|
|
section=self.section_no_groups,
|
2019-01-06 16:22:33 +01:00
|
|
|
comment="test_comment_fgkj3C7veo3ijWE(j2DJ",
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
comment.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.get(reverse("motion-detail", args=[self.motion.pk]))
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue("comments" in response.data)
|
|
|
|
comments = response.data["comments"]
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertTrue(isinstance(comments, list))
|
|
|
|
self.assertEqual(len(comments), 0)
|
|
|
|
|
|
|
|
def test_wrong_data_type(self):
|
|
|
|
response = self.client.post(
|
2019-10-18 14:18:49 +02:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]), None
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertEqual(
|
2019-01-06 16:22:33 +01:00
|
|
|
response.data["detail"], "You have to provide a section_id of type int."
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_wrong_comment_data_type(self):
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]),
|
2018-08-31 15:33:41 +02:00
|
|
|
{
|
2019-01-06 16:22:33 +01:00
|
|
|
"section_id": self.section_read_write.id,
|
|
|
|
"comment": [32, "no_correct_data"],
|
2018-08-31 15:33:41 +02:00
|
|
|
},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(response.data["detail"], "The comment should be a string.")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_non_existing_section(self):
|
|
|
|
response = self.client.post(
|
2019-10-18 14:18:49 +02:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]), {"section_id": 42}
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertEqual(
|
2019-09-02 11:09:03 +02:00
|
|
|
response.data["detail"], "A comment section with id {0} does not exist."
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2019-09-02 11:09:03 +02:00
|
|
|
self.assertEqual(response.data["args"][0], "42")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_create_comment(self):
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]),
|
2018-08-31 15:33:41 +02:00
|
|
|
{
|
2019-01-06 16:22:33 +01:00
|
|
|
"section_id": self.section_read_write.pk,
|
|
|
|
"comment": "test_comment_fk3jrnfwsdg%fj=feijf",
|
2018-08-31 15:33:41 +02:00
|
|
|
},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(MotionComment.objects.count(), 1)
|
|
|
|
comment = MotionComment.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(comment.comment, "test_comment_fk3jrnfwsdg%fj=feijf")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_update_comment(self):
|
|
|
|
comment = MotionComment(
|
|
|
|
motion=self.motion,
|
|
|
|
section=self.section_read_write,
|
2019-01-06 16:22:33 +01:00
|
|
|
comment="test_comment_fji387fqwdf&ff=)Fe3j",
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
comment.save()
|
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]),
|
2018-08-31 15:33:41 +02:00
|
|
|
{
|
2019-01-06 16:22:33 +01:00
|
|
|
"section_id": self.section_read_write.pk,
|
|
|
|
"comment": "test_comment_fk3jrnfwsdg%fj=feijf",
|
2018-08-31 15:33:41 +02:00
|
|
|
},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
comment = MotionComment.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(comment.comment, "test_comment_fk3jrnfwsdg%fj=feijf")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_delete_comment(self):
|
|
|
|
comment = MotionComment(
|
|
|
|
motion=self.motion,
|
|
|
|
section=self.section_read_write,
|
2019-01-06 16:22:33 +01:00
|
|
|
comment='test_comment_5CJ"8f23jd3j2,r93keZ',
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
comment.save()
|
|
|
|
|
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]),
|
|
|
|
{"section_id": self.section_read_write.pk},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(MotionComment.objects.count(), 0)
|
|
|
|
|
|
|
|
def test_delete_not_existing_comment(self):
|
|
|
|
"""
|
|
|
|
This should fail silently; no error, if the user wants to delete
|
|
|
|
a not existing comment.
|
|
|
|
"""
|
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]),
|
|
|
|
{"section_id": self.section_read_write.pk},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(MotionComment.objects.count(), 0)
|
|
|
|
|
|
|
|
def test_create_comment_no_write_permission(self):
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]),
|
2018-08-31 15:33:41 +02:00
|
|
|
{
|
2019-01-06 16:22:33 +01:00
|
|
|
"section_id": self.section_read.pk,
|
|
|
|
"comment": "test_comment_f38jfwqfj830fj4j(FU3",
|
2018-08-31 15:33:41 +02:00
|
|
|
},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertEqual(MotionComment.objects.count(), 0)
|
|
|
|
self.assertEqual(
|
2019-01-06 16:22:33 +01:00
|
|
|
response.data["detail"],
|
|
|
|
"You are not allowed to see or write to the comment section.",
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_update_comment_no_write_permission(self):
|
|
|
|
comment = MotionComment(
|
|
|
|
motion=self.motion,
|
|
|
|
section=self.section_read,
|
2019-01-06 16:22:33 +01:00
|
|
|
comment="test_comment_jg38dwiej2D832(D§dk)",
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
comment.save()
|
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]),
|
2018-08-31 15:33:41 +02:00
|
|
|
{
|
2019-01-06 16:22:33 +01:00
|
|
|
"section_id": self.section_read.pk,
|
|
|
|
"comment": "test_comment_fk3jrnfwsdg%fj=feijf",
|
2018-08-31 15:33:41 +02:00
|
|
|
},
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
comment = MotionComment.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(comment.comment, "test_comment_jg38dwiej2D832(D§dk)")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_delete_comment_no_write_permission(self):
|
|
|
|
comment = MotionComment(
|
|
|
|
motion=self.motion,
|
|
|
|
section=self.section_read,
|
2019-01-06 16:22:33 +01:00
|
|
|
comment="test_comment_fej(NF§kfePOF383o8DN",
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
comment.save()
|
|
|
|
|
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-manage-comments", args=[self.motion.pk]),
|
|
|
|
{"section_id": self.section_read.pk},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertEqual(MotionComment.objects.count(), 1)
|
|
|
|
comment = MotionComment.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(comment.comment, "test_comment_fej(NF§kfePOF383o8DN")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestMotionCommentSection(TestCase):
|
|
|
|
"""
|
|
|
|
Tests creating, updating and deletion of comment sections.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-08-31 15:33:41 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
self.admin = get_user_model().objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.admin.groups.add(
|
|
|
|
GROUP_STAFF_PK
|
|
|
|
) # Put the admin in a groiup with limited permissions for testing.
|
2018-10-09 13:44:38 +02:00
|
|
|
self.admin.groups.remove(GROUP_ADMIN_PK)
|
|
|
|
inform_changed_data(self.admin)
|
|
|
|
self.group_in = get_group_model().objects.get(pk=GROUP_STAFF_PK)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.group_out = get_group_model().objects.get(
|
|
|
|
pk=GROUP_DELEGATE_PK
|
|
|
|
) # The admin should not be in this group
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_retrieve(self):
|
|
|
|
"""
|
|
|
|
Checks, if the sections can be seen by a manager.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
section = MotionCommentSection(name="test_name_f3jOF3m8fp.<qiqmf32=")
|
2018-08-31 15:33:41 +02:00
|
|
|
section.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.get(reverse("motioncommentsection-list"))
|
2018-11-01 17:30:18 +01:00
|
|
|
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertTrue(isinstance(response.data, list))
|
|
|
|
self.assertEqual(len(response.data), 1)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(response.data[0]["name"], "test_name_f3jOF3m8fp.<qiqmf32=")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_retrieve_non_manager_with_read_permission(self):
|
|
|
|
"""
|
|
|
|
Checks, if the sections can be seen by a non manager, but he is in
|
|
|
|
one of the read_groups.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
self.admin.groups.remove(
|
|
|
|
self.group_in
|
|
|
|
) # group_in has motions.can_manage permission
|
2018-08-31 15:33:41 +02:00
|
|
|
self.admin.groups.add(self.group_out) # group_out does not.
|
2018-11-01 17:30:18 +01:00
|
|
|
inform_changed_data(self.admin)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
section = MotionCommentSection(name="test_name_f3mMD28LMcm29Coelwcm")
|
2018-08-31 15:33:41 +02:00
|
|
|
section.save()
|
|
|
|
section.read_groups.add(self.group_out, self.group_in)
|
2018-11-01 17:30:18 +01:00
|
|
|
inform_changed_data(section)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.get(reverse("motioncommentsection-list"))
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(len(response.data), 1)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(response.data[0]["name"], "test_name_f3mMD28LMcm29Coelwcm")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_retrieve_non_manager_no_read_permission(self):
|
|
|
|
"""
|
|
|
|
Checks, if sections are removed, if the user is a non manager and is in
|
|
|
|
any of the read_groups.
|
|
|
|
"""
|
|
|
|
self.admin.groups.remove(self.group_in)
|
2018-09-01 08:00:00 +02:00
|
|
|
inform_changed_data(self.admin)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
section = MotionCommentSection(name="test_name_f3jOF3m8fp.<qiqmf32=")
|
2018-08-31 15:33:41 +02:00
|
|
|
section.save()
|
|
|
|
section.read_groups.add(self.group_out)
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.get(reverse("motioncommentsection-list"))
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertTrue(isinstance(response.data, list))
|
|
|
|
self.assertEqual(len(response.data), 0)
|
|
|
|
|
|
|
|
def test_create(self):
|
|
|
|
"""
|
|
|
|
Create a section just with a name.
|
|
|
|
"""
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motioncommentsection-list"),
|
|
|
|
{"name": "test_name_ekjfen3n)F§zn83f§Fge"},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 1)
|
|
|
|
self.assertEqual(
|
2019-01-06 16:22:33 +01:00
|
|
|
MotionCommentSection.objects.get().name, "test_name_ekjfen3n)F§zn83f§Fge"
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_create_no_permission(self):
|
|
|
|
"""
|
|
|
|
Try to create a section without can_manage permissions.
|
|
|
|
"""
|
|
|
|
self.admin.groups.remove(self.group_in)
|
2018-09-01 08:00:00 +02:00
|
|
|
inform_changed_data(self.admin)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motioncommentsection-list"),
|
|
|
|
{"name": "test_name_wfl3jlkcmlq23ucn7eiq"},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 0)
|
|
|
|
|
|
|
|
def test_create_no_name(self):
|
|
|
|
"""
|
|
|
|
Create a section without a name. This should fail, because a name is required.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(reverse("motioncommentsection-list"), {})
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 0)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(response.data["name"][0], "This field is required.")
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_create_with_groups(self):
|
|
|
|
"""
|
|
|
|
Create a section with name and both groups.
|
|
|
|
"""
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motioncommentsection-list"),
|
2018-08-31 15:33:41 +02:00
|
|
|
{
|
2019-01-06 16:22:33 +01:00
|
|
|
"name": "test_name_fg4kmFn73FhFk327f/3h",
|
|
|
|
"read_groups_id": [2, 3],
|
|
|
|
"write_groups_id": [3, 4],
|
|
|
|
},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 1)
|
|
|
|
comment = MotionCommentSection.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(comment.name, "test_name_fg4kmFn73FhFk327f/3h")
|
|
|
|
self.assertEqual(list(comment.read_groups.values_list("pk", flat=True)), [2, 3])
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(
|
2019-01-06 16:22:33 +01:00
|
|
|
list(comment.write_groups.values_list("pk", flat=True)), [3, 4]
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_create_with_one_group(self):
|
|
|
|
"""
|
|
|
|
Create a section with a name and write_groups.
|
|
|
|
"""
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motioncommentsection-list"),
|
|
|
|
{"name": "test_name_ekjfen3n)F§zn83f§Fge", "write_groups_id": [1, 3]},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 1)
|
|
|
|
comment = MotionCommentSection.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(comment.name, "test_name_ekjfen3n)F§zn83f§Fge")
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(comment.read_groups.count(), 0)
|
|
|
|
self.assertEqual(
|
2019-01-06 16:22:33 +01:00
|
|
|
list(comment.write_groups.values_list("pk", flat=True)), [1, 3]
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_create_with_non_existing_group(self):
|
|
|
|
"""
|
|
|
|
Create a section with some non existing groups. This should fail.
|
|
|
|
"""
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motioncommentsection-list"),
|
|
|
|
{"name": "test_name_4gnUVnF§29FnH3287fhG", "write_groups_id": [42, 1, 8]},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 0)
|
|
|
|
self.assertEqual(
|
2019-01-06 16:22:33 +01:00
|
|
|
response.data["write_groups_id"][0],
|
|
|
|
'Invalid pk "42" - object does not exist.',
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_update(self):
|
|
|
|
"""
|
|
|
|
Update a section name.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
section = MotionCommentSection(name="test_name_dlfgNDf37ND(g3fNf43g")
|
2018-08-31 15:33:41 +02:00
|
|
|
section.save()
|
|
|
|
|
|
|
|
response = self.client.put(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motioncommentsection-detail", args=[section.pk]),
|
|
|
|
{"name": "test_name_ekjfen3n)F§zn83f§Fge"},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 1)
|
|
|
|
self.assertEqual(
|
2019-01-06 16:22:33 +01:00
|
|
|
MotionCommentSection.objects.get().name, "test_name_ekjfen3n)F§zn83f§Fge"
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_update_groups(self):
|
|
|
|
"""
|
|
|
|
Update one of the groups.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
section = MotionCommentSection(name="test_name_f3jFq3hShf/(fh2qlPOp")
|
2018-08-31 15:33:41 +02:00
|
|
|
section.save()
|
|
|
|
section.read_groups.add(2)
|
|
|
|
section.write_groups.add(3)
|
|
|
|
|
|
|
|
response = self.client.patch(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motioncommentsection-detail", args=[section.pk]),
|
|
|
|
{"name": "test_name_gkk3FhfhpmQMhC,Y378c", "read_groups_id": [2, 4]},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 1)
|
|
|
|
comment = MotionCommentSection.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(comment.name, "test_name_gkk3FhfhpmQMhC,Y378c")
|
|
|
|
self.assertEqual(list(comment.read_groups.values_list("pk", flat=True)), [2, 4])
|
|
|
|
self.assertEqual(list(comment.write_groups.values_list("pk", flat=True)), [3])
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_update_no_permission(self):
|
|
|
|
"""
|
|
|
|
Try to update a section without can_manage permissions.
|
|
|
|
"""
|
|
|
|
self.admin.groups.remove(self.group_in)
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
section = MotionCommentSection(name="test_name_wl2oxmmhe/2kd92lwPSi")
|
2018-08-31 15:33:41 +02:00
|
|
|
section.save()
|
|
|
|
|
|
|
|
response = self.client.patch(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motioncommentsection-list"),
|
|
|
|
{"name": "test_name_2slmDMwmqqcmC92mcklw"},
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 1)
|
|
|
|
self.assertEqual(
|
2019-01-06 16:22:33 +01:00
|
|
|
MotionCommentSection.objects.get().name, "test_name_wl2oxmmhe/2kd92lwPSi"
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
|
|
|
def test_delete(self):
|
|
|
|
"""
|
|
|
|
Delete a section.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
section = MotionCommentSection(name="test_name_ecMCq;ymwuZZ723kD)2k")
|
2018-08-31 15:33:41 +02:00
|
|
|
section.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("motioncommentsection-detail", args=[section.pk])
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 0)
|
|
|
|
|
|
|
|
def test_delete_non_existing_section(self):
|
|
|
|
"""
|
|
|
|
Delete a non existing section.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(reverse("motioncommentsection-detail", args=[2]))
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 0)
|
|
|
|
|
|
|
|
def test_delete_with_existing_comments(self):
|
|
|
|
"""
|
|
|
|
Delete a section with existing comments. This should fail, because sections
|
|
|
|
are protected.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
section = MotionCommentSection(name="test_name_ecMCq;ymwuZZ723kD)2k")
|
2018-08-31 15:33:41 +02:00
|
|
|
section.save()
|
|
|
|
|
|
|
|
motion = Motion(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_SlqfMw(waso0saWMPqcZ",
|
|
|
|
text="test_text_f30skclqS9wWF=xdfaSL",
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
motion.save()
|
|
|
|
|
|
|
|
comment = MotionComment(
|
2019-01-06 16:22:33 +01:00
|
|
|
comment="test_comment_dlkMD23m)(D9020m0/Zd", motion=motion, section=section
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
comment.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("motioncommentsection-detail", args=[section.pk])
|
|
|
|
)
|
2019-09-02 11:09:03 +02:00
|
|
|
self.assertEqual(response.data["args"][0], '"test_title_SlqfMw(waso0saWMPqcZ"')
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 1)
|
|
|
|
|
|
|
|
def test_delete_no_permission(self):
|
|
|
|
"""
|
|
|
|
Try to delete a section without can_manage permissions
|
|
|
|
"""
|
|
|
|
self.admin.groups.remove(self.group_in)
|
2018-09-01 08:00:00 +02:00
|
|
|
inform_changed_data(self.admin)
|
2018-08-31 15:33:41 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
section = MotionCommentSection(name="test_name_wl2oxmmhe/2kd92lwPSi")
|
2018-08-31 15:33:41 +02:00
|
|
|
section.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("motioncommentsection-detail", args=[section.pk])
|
|
|
|
)
|
2018-08-31 15:33:41 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
self.assertEqual(MotionCommentSection.objects.count(), 1)
|
|
|
|
|
|
|
|
|
2019-07-19 13:43:33 +02:00
|
|
|
class TestMotionCommentSectionSorting(TestCase):
|
|
|
|
"""
|
|
|
|
Tests sorting of comment sections.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
|
|
|
self.client.login(username="admin", password="admin")
|
|
|
|
self.section1 = MotionCommentSection(name="test_name_hponzp<zp7NUJKLAykbX")
|
|
|
|
self.section1.save()
|
|
|
|
self.section2 = MotionCommentSection(name="test_name_eix,b<bojbP'JO;<kVKL")
|
|
|
|
self.section2.save()
|
|
|
|
self.section3 = MotionCommentSection(name="test_name_ojMOeigSIOfhmpouweqc")
|
|
|
|
self.section3.save()
|
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
response = self.client.post(
|
2019-10-18 14:18:49 +02:00
|
|
|
reverse("motioncommentsection-sort"), {"ids": [3, 2, 1]}
|
2019-07-19 13:43:33 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
|
|
|
|
section1 = MotionCommentSection.objects.get(pk=1)
|
|
|
|
self.assertEqual(section1.weight, 3)
|
|
|
|
section2 = MotionCommentSection.objects.get(pk=2)
|
|
|
|
self.assertEqual(section2.weight, 2)
|
|
|
|
section3 = MotionCommentSection.objects.get(pk=3)
|
|
|
|
self.assertEqual(section3.weight, 1)
|
|
|
|
|
|
|
|
def test_wrong_data(self):
|
|
|
|
response = self.client.post(
|
2019-10-18 14:18:49 +02:00
|
|
|
reverse("motioncommentsection-sort"), {"ids": "some_string"}
|
2019-07-19 13:43:33 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assert_not_changed()
|
|
|
|
|
|
|
|
def test_wrong_id_type(self):
|
|
|
|
response = self.client.post(
|
2019-10-18 14:18:49 +02:00
|
|
|
reverse("motioncommentsection-sort"), {"ids": [1, 2, "some_string"]}
|
2019-07-19 13:43:33 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assert_not_changed()
|
|
|
|
|
|
|
|
def test_missing_id(self):
|
|
|
|
response = self.client.post(
|
2019-10-18 14:18:49 +02:00
|
|
|
reverse("motioncommentsection-sort"), {"ids": [3, 1]}
|
2019-07-19 13:43:33 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assert_not_changed()
|
|
|
|
|
|
|
|
def test_duplicate_id(self):
|
|
|
|
response = self.client.post(
|
2019-10-18 14:18:49 +02:00
|
|
|
reverse("motioncommentsection-sort"), {"ids": [3, 2, 1, 1]}
|
2019-07-19 13:43:33 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assert_not_changed()
|
|
|
|
|
|
|
|
def test_wrong_id(self):
|
|
|
|
response = self.client.post(
|
2019-10-18 14:18:49 +02:00
|
|
|
reverse("motioncommentsection-sort"), {"ids": [3, 4, 1]}
|
2019-07-19 13:43:33 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assert_not_changed()
|
|
|
|
|
|
|
|
def assert_not_changed(self):
|
|
|
|
""" Asserts, that every comment section has the default weight of 10000. """
|
|
|
|
for section in MotionCommentSection.objects.all():
|
|
|
|
self.assertEqual(section.weight, 10000)
|
|
|
|
|
|
|
|
|
2018-10-25 15:11:38 +02:00
|
|
|
class RetrieveMotionChangeRecommendation(TestCase):
|
|
|
|
"""
|
|
|
|
Tests retrieving motion change recommendations.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-10-25 15:11:38 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2018-10-25 15:11:38 +02:00
|
|
|
|
|
|
|
motion = Motion(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_3kd)K23,c9239mdj2wcG",
|
|
|
|
text="test_text_f8FLP,gvprC;wovVEwlQ",
|
|
|
|
)
|
2018-10-25 15:11:38 +02:00
|
|
|
motion.save()
|
|
|
|
|
|
|
|
self.public_cr = MotionChangeRecommendation(
|
2019-01-06 16:22:33 +01:00
|
|
|
motion=motion, internal=False, line_from=1, line_to=1
|
|
|
|
)
|
2018-10-25 15:11:38 +02:00
|
|
|
self.public_cr.save()
|
|
|
|
|
|
|
|
self.internal_cr = MotionChangeRecommendation(
|
2019-01-06 16:22:33 +01:00
|
|
|
motion=motion, internal=True, line_from=2, line_to=2
|
|
|
|
)
|
2018-10-25 15:11:38 +02:00
|
|
|
self.internal_cr.save()
|
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
"""
|
|
|
|
Test retrieving all change recommendations.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.get(reverse("motionchangerecommendation-list"))
|
2018-10-25 15:11:38 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(len(response.data), 2)
|
|
|
|
|
|
|
|
def test_non_admin(self):
|
|
|
|
"""
|
|
|
|
Test retrieving of all change recommendations that are public, if the user
|
|
|
|
has no manage perms.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
self.admin = get_user_model().objects.get(username="admin")
|
2018-10-25 15:11:38 +02:00
|
|
|
self.admin.groups.add(GROUP_DELEGATE_PK)
|
|
|
|
self.admin.groups.remove(GROUP_ADMIN_PK)
|
|
|
|
inform_changed_data(self.admin)
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.get(reverse("motionchangerecommendation-list"))
|
2018-10-25 15:11:38 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(len(response.data), 1)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(response.data[0]["id"], self.public_cr.id)
|
2018-10-25 15:11:38 +02:00
|
|
|
|
|
|
|
|
2017-06-18 20:20:44 +02:00
|
|
|
class CreateMotionChangeRecommendation(TestCase):
|
|
|
|
"""
|
|
|
|
Tests motion change recommendation creation.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2017-06-18 20:20:44 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2017-06-18 20:20:44 +02:00
|
|
|
|
|
|
|
self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-list"),
|
|
|
|
{
|
|
|
|
"title": "test_title_OoCoo3MeiT9li5Iengu9",
|
|
|
|
"text": "test_text_thuoz0iecheiheereiCi",
|
|
|
|
},
|
|
|
|
)
|
2017-06-18 20:20:44 +02:00
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
"""
|
|
|
|
Creating a change plain, simple change recommendation
|
|
|
|
"""
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motionchangerecommendation-list"),
|
|
|
|
{
|
|
|
|
"line_from": "5",
|
|
|
|
"line_to": "7",
|
|
|
|
"motion_id": "1",
|
|
|
|
"text": "<p>New test</p>",
|
|
|
|
"type": "0",
|
|
|
|
},
|
|
|
|
)
|
2017-06-18 20:20:44 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
|
|
|
|
def test_collission(self):
|
|
|
|
"""
|
|
|
|
Two change recommendations with overlapping lines should lead to a Bad Request
|
|
|
|
"""
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motionchangerecommendation-list"),
|
|
|
|
{
|
|
|
|
"line_from": "5",
|
|
|
|
"line_to": "7",
|
|
|
|
"motion_id": "1",
|
|
|
|
"text": "<p>New test</p>",
|
|
|
|
"type": "0",
|
|
|
|
},
|
|
|
|
)
|
2017-06-18 20:20:44 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motionchangerecommendation-list"),
|
|
|
|
{
|
|
|
|
"line_from": "3",
|
|
|
|
"line_to": "6",
|
|
|
|
"motion_id": "1",
|
|
|
|
"text": "<p>New test</p>",
|
|
|
|
"type": "0",
|
|
|
|
},
|
|
|
|
)
|
2017-06-18 20:20:44 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
2019-09-02 11:09:03 +02:00
|
|
|
self.assertEqual(response.data["args"][0], "3")
|
|
|
|
self.assertEqual(response.data["args"][1], "6")
|
2017-06-18 20:20:44 +02:00
|
|
|
|
|
|
|
def test_no_collission_different_motions(self):
|
|
|
|
"""
|
|
|
|
Two change recommendations with overlapping lines, but affecting different motions, should not interfere
|
|
|
|
"""
|
|
|
|
self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motion-list"),
|
|
|
|
{
|
|
|
|
"title": "test_title_OoCoo3MeiT9li5Iengu9",
|
|
|
|
"text": "test_text_thuoz0iecheiheereiCi",
|
|
|
|
},
|
|
|
|
)
|
2017-06-18 20:20:44 +02:00
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motionchangerecommendation-list"),
|
|
|
|
{
|
|
|
|
"line_from": "5",
|
|
|
|
"line_to": "7",
|
|
|
|
"motion_id": "1",
|
|
|
|
"text": "<p>New test</p>",
|
|
|
|
"type": "0",
|
|
|
|
},
|
|
|
|
)
|
2017-06-18 20:20:44 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("motionchangerecommendation-list"),
|
|
|
|
{
|
|
|
|
"line_from": "3",
|
|
|
|
"line_to": "6",
|
|
|
|
"motion_id": "2",
|
|
|
|
"text": "<p>New test</p>",
|
|
|
|
"type": "0",
|
|
|
|
},
|
|
|
|
)
|
2017-06-18 20:20:44 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
|
|
|
|
|
2019-06-03 14:17:42 +02:00
|
|
|
class NumberMotionsInCategories(TestCase):
|
2016-07-13 01:39:28 +02:00
|
|
|
"""
|
2019-06-03 14:17:42 +02:00
|
|
|
Tests numbering motions in categories.
|
|
|
|
|
2019-09-02 11:09:03 +02:00
|
|
|
Default test environment:
|
|
|
|
- *without* blanks
|
|
|
|
- 1 min digit
|
|
|
|
|
2019-06-03 14:17:42 +02:00
|
|
|
Testdata. All names (and prefixes) are prefixed with "test_". The
|
|
|
|
ordering is ensured with "category_weight".
|
|
|
|
Category tree (with motions M and amendments A):
|
|
|
|
A-A
|
|
|
|
<M1>
|
|
|
|
<M2-A2>
|
|
|
|
B
|
|
|
|
<M2-A1>
|
|
|
|
<M3>
|
|
|
|
C-C
|
|
|
|
<M2>
|
|
|
|
<M2-A1-A1>
|
2016-07-13 01:39:28 +02:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2016-07-13 01:39:28 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2019-06-03 14:17:42 +02:00
|
|
|
self.A = Category.objects.create(name="test_A", prefix="test_A")
|
|
|
|
self.B = Category.objects.create(name="test_B", parent=self.A)
|
|
|
|
self.C = Category.objects.create(name="test_C", prefix="test_C", parent=self.A)
|
|
|
|
|
|
|
|
self.M1 = Motion(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_Eeha8Haf6peulu8ooc0z",
|
|
|
|
text="test_text_faghaZoov9ooV4Acaquk",
|
2019-06-03 14:17:42 +02:00
|
|
|
category=self.A,
|
|
|
|
category_weight=1,
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2019-06-03 14:17:42 +02:00
|
|
|
self.M1.save()
|
|
|
|
self.M1.identifier = ""
|
|
|
|
self.M1.save()
|
|
|
|
|
|
|
|
self.M2 = Motion(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_kuheih2eja2Saeshusha",
|
|
|
|
text="test_text_Ha5ShaeraeSuthooP2Bu",
|
2019-06-03 14:17:42 +02:00
|
|
|
category=self.C,
|
|
|
|
category_weight=1,
|
|
|
|
)
|
|
|
|
self.M2.save()
|
|
|
|
self.M2.identifier = ""
|
|
|
|
self.M2.save()
|
|
|
|
|
|
|
|
self.M2_A1 = Motion(
|
|
|
|
title="test_title_av3ejIJvwon3jvnNVaie",
|
|
|
|
text="test_text_FJPiejfwdcoiwjvijao1",
|
|
|
|
category=self.B,
|
|
|
|
category_weight=1,
|
|
|
|
parent=self.M2,
|
|
|
|
)
|
|
|
|
self.M2_A1.save()
|
|
|
|
self.M2_A1.identifier = ""
|
|
|
|
self.M2_A1.save()
|
|
|
|
|
|
|
|
self.M2_A1_A1 = Motion(
|
|
|
|
title="test_title_ejvhwoxngixoqkxy.qfi",
|
|
|
|
text="test_text_euh2gfaiaqfu3.f(3hgf",
|
|
|
|
category=self.C,
|
|
|
|
category_weight=2,
|
|
|
|
parent=self.M2_A1,
|
|
|
|
)
|
|
|
|
self.M2_A1_A1.save()
|
|
|
|
self.M2_A1_A1.identifier = ""
|
|
|
|
self.M2_A1_A1.save()
|
|
|
|
|
|
|
|
self.M2_A2 = Motion(
|
|
|
|
title="test_title_xoerFiwebbpiUEeuvxMa",
|
|
|
|
text="test_text_zbwZWPefiisdISfwLKqN",
|
|
|
|
category=self.A,
|
|
|
|
category_weight=2,
|
|
|
|
parent=self.M2,
|
|
|
|
)
|
|
|
|
self.M2_A2.save()
|
|
|
|
self.M2_A2.identifier = ""
|
|
|
|
self.M2_A2.save()
|
|
|
|
|
|
|
|
self.M3 = Motion(
|
|
|
|
title="test_title_VWIVeiNVenudn(23J92§",
|
|
|
|
text="test_text_VEDno328hn8/TBbScVEb",
|
|
|
|
category=self.B,
|
|
|
|
category_weight=2,
|
|
|
|
)
|
|
|
|
self.M3.save()
|
|
|
|
self.M3.identifier = ""
|
|
|
|
self.M3.save()
|
2016-07-13 01:39:28 +02:00
|
|
|
|
|
|
|
def test_numbering(self):
|
2019-06-03 14:17:42 +02:00
|
|
|
response = self.client.post(reverse("category-numbering", args=[self.A.pk]))
|
2016-07-13 01:39:28 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
2019-09-02 11:09:03 +02:00
|
|
|
self.assertEqual(Motion.objects.get(pk=self.M1.pk).identifier, "test_A1")
|
|
|
|
self.assertEqual(Motion.objects.get(pk=self.M3.pk).identifier, "test_A2")
|
|
|
|
self.assertEqual(Motion.objects.get(pk=self.M2.pk).identifier, "test_C3")
|
|
|
|
self.assertEqual(Motion.objects.get(pk=self.M2_A1.pk).identifier, "test_C3-2")
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(
|
2019-09-02 11:09:03 +02:00
|
|
|
Motion.objects.get(pk=self.M2_A1_A1.pk).identifier, "test_C3-2-1"
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2019-09-02 11:09:03 +02:00
|
|
|
self.assertEqual(Motion.objects.get(pk=self.M2_A2.pk).identifier, "test_C3-1")
|
2016-07-13 01:39:28 +02:00
|
|
|
|
2019-09-02 11:09:03 +02:00
|
|
|
def test_with_blanks_and_leading_zeros(self):
|
2019-06-03 14:17:42 +02:00
|
|
|
config["motions_amendments_prefix"] = "-X"
|
2019-09-02 11:09:03 +02:00
|
|
|
config["motions_identifier_with_blank"] = True
|
2019-08-14 21:53:42 +02:00
|
|
|
config["motions_identifier_min_digits"] = 3
|
2019-06-03 14:17:42 +02:00
|
|
|
response = self.client.post(reverse("category-numbering", args=[self.A.pk]))
|
2019-09-02 11:09:03 +02:00
|
|
|
config["motions_identifier_with_blank"] = False
|
2019-08-14 21:53:42 +02:00
|
|
|
config["motions_identifier_min_digits"] = 1
|
2019-06-03 14:17:42 +02:00
|
|
|
|
2016-07-13 01:39:28 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
2019-08-14 21:53:42 +02:00
|
|
|
self.assertEqual(Motion.objects.get(pk=self.M1.pk).identifier, "test_A 001")
|
|
|
|
self.assertEqual(Motion.objects.get(pk=self.M3.pk).identifier, "test_A 002")
|
|
|
|
self.assertEqual(Motion.objects.get(pk=self.M2.pk).identifier, "test_C 003")
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(
|
2019-08-14 21:53:42 +02:00
|
|
|
Motion.objects.get(pk=self.M2_A1.pk).identifier, "test_C 003 -X 002"
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2019-08-14 21:53:42 +02:00
|
|
|
Motion.objects.get(pk=self.M2_A1_A1.pk).identifier,
|
|
|
|
"test_C 003 -X 002 -X 001",
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2019-08-14 21:53:42 +02:00
|
|
|
Motion.objects.get(pk=self.M2_A2.pk).identifier, "test_C 003 -X 001"
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2016-08-15 23:53:21 +02:00
|
|
|
|
2019-06-03 14:17:42 +02:00
|
|
|
def test_existing_identifier_no_category(self):
|
2019-09-02 11:09:03 +02:00
|
|
|
# config["motions_identifier_with_blank"] = True
|
2019-06-03 14:17:42 +02:00
|
|
|
conflicting_motion = Motion(
|
|
|
|
title="test_title_al2=2k21fjv1lsck3ehlWExg",
|
|
|
|
text="test_text_3omvpEhnfg082ejplk1m",
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2019-06-03 14:17:42 +02:00
|
|
|
conflicting_motion.save()
|
2019-09-02 11:09:03 +02:00
|
|
|
conflicting_motion.identifier = "test_C3-2-1"
|
2019-06-03 14:17:42 +02:00
|
|
|
conflicting_motion.save()
|
|
|
|
response = self.client.post(reverse("category-numbering", args=[self.A.pk]))
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
2019-09-02 11:09:03 +02:00
|
|
|
self.assertEqual("test_C3-2-1", response.data["args"][0])
|
2019-06-03 14:17:42 +02:00
|
|
|
|
|
|
|
def test_existing_identifier_with_category(self):
|
|
|
|
conflicting_category = Category.objects.create(
|
|
|
|
name="test_name_hpsodhakvjdbvkblwfjr"
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2019-06-03 14:17:42 +02:00
|
|
|
conflicting_motion = Motion(
|
|
|
|
title="test_title_al2=2k21fjv1lsck3ehlWExg",
|
|
|
|
text="test_text_3omvpEhnfg082ejplk1m",
|
|
|
|
category=conflicting_category,
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2019-06-03 14:17:42 +02:00
|
|
|
conflicting_motion.save()
|
2019-09-02 11:09:03 +02:00
|
|
|
conflicting_motion.identifier = "test_C3-2-1"
|
2019-06-03 14:17:42 +02:00
|
|
|
conflicting_motion.save()
|
|
|
|
response = self.client.post(reverse("category-numbering", args=[self.A.pk]))
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
2019-09-02 11:09:03 +02:00
|
|
|
self.assertEqual("test_C3-2-1", response.data["args"][0])
|
|
|
|
self.assertEqual(conflicting_category.name, response.data["args"][1])
|
2019-06-03 14:17:42 +02:00
|
|
|
|
|
|
|
def test_incomplete_amendment_tree(self):
|
|
|
|
self.M2_A1.category = None
|
|
|
|
self.M2_A1.save()
|
|
|
|
response = self.client.post(reverse("category-numbering", args=[self.A.pk]))
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
2019-09-02 11:09:03 +02:00
|
|
|
self.assertEqual(self.M2_A1_A1.title, response.data["args"][0])
|
|
|
|
self.assertEqual(self.M2_A1.title, response.data["args"][1])
|
2016-10-14 21:48:02 +02:00
|
|
|
|
|
|
|
|
2019-05-21 13:52:10 +02:00
|
|
|
class TestMotionBlock(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
|
|
|
self.client.login(username="admin", password="admin")
|
|
|
|
|
|
|
|
def make_admin_delegate(self):
|
|
|
|
admin = get_user_model().objects.get(username="admin")
|
|
|
|
admin.groups.add(GROUP_DELEGATE_PK)
|
|
|
|
admin.groups.remove(GROUP_ADMIN_PK)
|
|
|
|
inform_changed_data(admin)
|
|
|
|
|
|
|
|
def test_creation(self):
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("motionblock-list"), {"title": "test_title_r23098OMFwoqof3if3kO"}
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
self.assertTrue(MotionBlock.objects.exists())
|
|
|
|
self.assertEqual(
|
|
|
|
MotionBlock.objects.get().title, "test_title_r23098OMFwoqof3if3kO"
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_creation_no_data(self):
|
|
|
|
response = self.client.post(reverse("motionblock-list"), {})
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertFalse(MotionBlock.objects.exists())
|
|
|
|
|
|
|
|
def test_creation_not_authenticated(self):
|
|
|
|
self.make_admin_delegate()
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("motionblock-list"), {"title": "test_title_2PFjpf39ap,38fuMPO§8"}
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
self.assertFalse(MotionBlock.objects.exists())
|
|
|
|
|
|
|
|
def test_retrieve_simple(self):
|
|
|
|
motion_block = MotionBlock(title="test_title")
|
|
|
|
motion_block.save()
|
|
|
|
|
|
|
|
response = self.client.get(
|
|
|
|
reverse("motionblock-detail", args=[motion_block.pk])
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(
|
|
|
|
sorted(response.data.keys()),
|
|
|
|
sorted(
|
|
|
|
("agenda_item_id", "id", "internal", "list_of_speakers_id", "title")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_retrieve_internal_non_admin(self):
|
|
|
|
self.make_admin_delegate()
|
|
|
|
motion_block = MotionBlock(title="test_title", internal=True)
|
|
|
|
motion_block.save()
|
|
|
|
|
|
|
|
response = self.client.get(
|
|
|
|
reverse("motionblock-detail", args=[motion_block.pk])
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
|
|
|
|
|
|
|
2016-10-14 21:48:02 +02:00
|
|
|
class FollowRecommendationsForMotionBlock(TestCase):
|
|
|
|
"""
|
|
|
|
Tests following the recommendations of motions in an motion block.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2016-10-14 21:48:02 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.state_id_accepted = 2 # This should be the id of the state 'accepted'.
|
|
|
|
self.state_id_rejected = 3 # This should be the id of the state 'rejected'.
|
|
|
|
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2016-10-14 21:48:02 +02:00
|
|
|
|
|
|
|
self.motion_block = MotionBlock.objects.create(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_motion_block_name_Ufoopiub7quaezaepeic"
|
|
|
|
)
|
2016-10-14 21:48:02 +02:00
|
|
|
|
|
|
|
self.motion = Motion(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_yo8ohy5eifeiyied2AeD",
|
|
|
|
text="test_text_chi1aeth5faPhueQu8oh",
|
|
|
|
motion_block=self.motion_block,
|
|
|
|
)
|
2016-10-14 21:48:02 +02:00
|
|
|
self.motion.save()
|
|
|
|
self.motion.set_recommendation(self.state_id_accepted)
|
|
|
|
self.motion.save()
|
|
|
|
|
|
|
|
self.motion_2 = Motion(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_eith0EemaW8ahZa9Piej",
|
|
|
|
text="test_text_haeho1ohk3ou7pau2Jee",
|
|
|
|
motion_block=self.motion_block,
|
|
|
|
)
|
2016-10-14 21:48:02 +02:00
|
|
|
self.motion_2.save()
|
|
|
|
self.motion_2.set_recommendation(self.state_id_rejected)
|
|
|
|
self.motion_2.save()
|
|
|
|
|
|
|
|
def test_follow_recommendations_for_motion_block(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("motionblock-follow-recommendations", args=[self.motion_block.pk])
|
|
|
|
)
|
2016-10-14 21:48:02 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(
|
|
|
|
Motion.objects.get(pk=self.motion.pk).state.id, self.state_id_accepted
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
Motion.objects.get(pk=self.motion_2.pk).state.id, self.state_id_rejected
|
|
|
|
)
|
2018-06-26 15:59:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CreateWorkflow(TestCase):
|
|
|
|
"""
|
|
|
|
Tests the creating of workflows.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-06-26 15:59:05 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2018-06-26 15:59:05 +02:00
|
|
|
|
|
|
|
def test_creation(self):
|
|
|
|
Workflow.objects.all().delete()
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("workflow-list"), {"name": "test_name_OoCoo3MeiT9li5Iengu9"}
|
|
|
|
)
|
2018-06-26 15:59:05 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
workflow = Workflow.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(workflow.name, "test_name_OoCoo3MeiT9li5Iengu9")
|
2018-06-26 15:59:05 +02:00
|
|
|
first_state = workflow.first_state
|
|
|
|
self.assertEqual(type(first_state), State)
|
|
|
|
|
|
|
|
|
|
|
|
class UpdateWorkflow(TestCase):
|
|
|
|
"""
|
|
|
|
Tests the updating of workflows.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-06-26 15:59:05 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2018-06-26 15:59:05 +02:00
|
|
|
self.workflow = Workflow.objects.first()
|
|
|
|
|
|
|
|
def test_rename_workflow(self):
|
|
|
|
response = self.client.patch(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("workflow-detail", args=[self.workflow.pk]),
|
|
|
|
{"name": 'test_name_wofi38DiWLT"8d3lwfo3'},
|
|
|
|
)
|
2018-06-26 15:59:05 +02:00
|
|
|
|
|
|
|
workflow = Workflow.objects.get(pk=self.workflow.id)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(workflow.name, 'test_name_wofi38DiWLT"8d3lwfo3')
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteWorkflow(TestCase):
|
|
|
|
"""
|
|
|
|
Tests the deletion of workflows.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-06-26 15:59:05 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2018-06-26 15:59:05 +02:00
|
|
|
self.workflow = Workflow.objects.first()
|
|
|
|
|
|
|
|
def test_simple_delete(self):
|
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("workflow-detail", args=[self.workflow.pk])
|
|
|
|
)
|
2018-06-26 15:59:05 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
|
|
|
self.assertEqual(Workflow.objects.count(), 1) # Just the other default one
|
|
|
|
|
|
|
|
def test_delete_with_assigned_motions(self):
|
|
|
|
self.motion = Motion(
|
2019-01-06 16:22:33 +01:00
|
|
|
title="test_title_chee7ahCha6bingaew4e",
|
|
|
|
text="test_text_birah1theL9ooseeFaip",
|
|
|
|
)
|
2018-06-26 15:59:05 +02:00
|
|
|
self.motion.reset_state(self.workflow)
|
|
|
|
self.motion.save()
|
|
|
|
|
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("workflow-detail", args=[self.workflow.pk])
|
|
|
|
)
|
2018-06-26 15:59:05 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertEqual(Workflow.objects.count(), 2)
|
2019-03-01 20:51:42 +01:00
|
|
|
|
2019-05-20 12:53:02 +02:00
|
|
|
def test_delete_last_workflow(self):
|
|
|
|
self.workflow.delete()
|
|
|
|
other_workflow_pk = Workflow.objects.get().pk
|
|
|
|
response = self.client.delete(
|
|
|
|
reverse("workflow-detail", args=[other_workflow_pk])
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
self.assertEqual(Workflow.objects.count(), 1) # Just the other default one
|
|
|
|
|
2019-03-01 20:51:42 +01:00
|
|
|
|
|
|
|
class DeleteCategory(TestCase):
|
|
|
|
"""
|
|
|
|
Tests the deletion of categories.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
|
|
|
self.client.login(username="admin", password="admin")
|
|
|
|
self.category = Category.objects.create(
|
|
|
|
name="test_name_dacei2iiTh", prefix="test_prefix_lahngoaW9L"
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_simple_delete_category_with_two_motions(self):
|
|
|
|
self.motion1 = Motion.objects.create(
|
|
|
|
title="test_title_fieB5ko4ahGeex5ohsh7",
|
|
|
|
text="test_text_EFoh6Ahtho9eihei1xua",
|
|
|
|
category=self.category,
|
|
|
|
)
|
|
|
|
self.motion2 = Motion.objects.create(
|
|
|
|
title="test_title_ahboo8eerohchuoD7sut",
|
|
|
|
text="test_text_pahghah9iuM9moo8Ohve",
|
|
|
|
category=self.category,
|
|
|
|
)
|
|
|
|
response = self.client.delete(
|
|
|
|
reverse("category-detail", args=[self.category.pk])
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
|
|
|
self.assertFalse(Category.objects.exists())
|