OpenSlides/tests/integration/core/test_viewset.py

78 lines
2.2 KiB
Python
Raw Normal View History

import pytest
from django.urls import reverse
2016-10-17 16:56:19 +02:00
from rest_framework import status
from openslides.core.config import config
from openslides.core.models import ChatMessage, Projector, Tag
from openslides.users.models import User
from openslides.utils.test import TestCase
from ..helpers import count_queries
@pytest.mark.django_db(transaction=False)
def test_projector_db_queries():
"""
Tests that only the following db queries are done:
* 1 requests to get the list of all projectors,
* 1 request to get the list of the projector defaults.
"""
for index in range(10):
2019-01-12 23:01:42 +01:00
Projector.objects.create(name=f"Projector{index}")
assert count_queries(Projector.get_elements) == 2
@pytest.mark.django_db(transaction=False)
def test_chat_message_db_queries():
"""
Tests that only the following db queries are done:
* 1 requests to get the list of all chatmessages.
"""
2019-01-06 16:22:33 +01:00
user = User.objects.get(username="admin")
for index in range(10):
ChatMessage.objects.create(user=user)
assert count_queries(ChatMessage.get_elements) == 1
@pytest.mark.django_db(transaction=False)
def test_tag_db_queries():
"""
Tests that only the following db queries are done:
* 1 requests to get the list of all tags.
"""
for index in range(10):
2019-01-12 23:01:42 +01:00
Tag.objects.create(name=f"tag{index}")
assert count_queries(Tag.get_elements) == 1
@pytest.mark.django_db(transaction=False)
def test_config_db_queries():
"""
Tests that only the following db queries are done:
* 1 requests to get the list of all config values
"""
config.save_default_values()
assert count_queries(Tag.get_elements) == 1
2016-10-17 16:56:19 +02:00
class ChatMessageViewSet(TestCase):
"""
Tests requests to deal with chat messages.
"""
2019-01-06 16:22:33 +01:00
2016-10-17 16:56:19 +02:00
def setUp(self):
2019-01-06 16:22:33 +01:00
admin = User.objects.get(username="admin")
2016-10-17 16:56:19 +02:00
self.client.force_login(admin)
2019-01-06 16:22:33 +01:00
ChatMessage.objects.create(
message="test_message_peechiel8IeZoohaem9e", user=admin
)
2016-10-17 16:56:19 +02:00
def test_clear_chat(self):
2019-01-06 16:22:33 +01:00
response = self.client.post(reverse("chatmessage-clear"))
2016-10-17 16:56:19 +02:00
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(ChatMessage.objects.all().count(), 0)