2018-07-09 23:22:26 +02:00
|
|
|
import pytest
|
2018-07-09 23:22:26 +02:00
|
|
|
from django.urls import reverse
|
2017-04-03 11:05:54 +02:00
|
|
|
from rest_framework import status
|
|
|
|
|
|
|
|
from openslides.agenda.models import Item
|
|
|
|
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
|
2017-04-03 11:05:54 +02:00
|
|
|
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_topic_item_db_queries():
|
2017-04-03 11:05:54 +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 topics,
|
|
|
|
* 1 request to get attachments,
|
|
|
|
* 1 request to get the agenda item
|
2019-04-23 16:57:35 +02:00
|
|
|
* 1 request to get the list of speakers
|
2018-07-09 23:22:26 +02:00
|
|
|
"""
|
|
|
|
for index in range(10):
|
2019-01-12 23:01:42 +01:00
|
|
|
Topic.objects.create(title=f"topic-{index}")
|
2017-04-03 11:05:54 +02:00
|
|
|
|
2019-11-04 14:56:01 +01:00
|
|
|
assert count_queries(Topic.get_elements)() == 4
|
2017-04-03 11:05:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TopicCreate(TestCase):
|
|
|
|
"""
|
|
|
|
Tests creation of new topics.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2017-04-03 11:05:54 +02:00
|
|
|
def setUp(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
2017-04-03 11:05:54 +02:00
|
|
|
|
|
|
|
def test_simple_create(self):
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("topic-list"),
|
|
|
|
{
|
|
|
|
"title": "test_title_ahyo1uifoo9Aiph2av5a",
|
|
|
|
"text": "test_text_chu9Uevoo5choo0Xithe",
|
|
|
|
},
|
|
|
|
)
|
2017-04-03 11:05:54 +02:00
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
topic = Topic.objects.get()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(topic.title, "test_title_ahyo1uifoo9Aiph2av5a")
|
|
|
|
self.assertEqual(topic.text, "test_text_chu9Uevoo5choo0Xithe")
|
2017-04-03 11:05:54 +02:00
|
|
|
self.assertEqual(Item.objects.get(), topic.agenda_item)
|