2018-07-09 23:22:26 +02:00
|
|
|
import pytest
|
2018-07-09 23:22:26 +02:00
|
|
|
from django.urls import reverse
|
2016-10-17 16:56:19 +02:00
|
|
|
from rest_framework import status
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
from openslides.core.config import config
|
|
|
|
from openslides.core.models import ChatMessage, Projector, Tag
|
|
|
|
from openslides.users.models import User
|
2017-09-04 00:25:45 +02:00
|
|
|
from openslides.utils.test import TestCase
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
from ..helpers import count_queries
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_projector_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 projectors,
|
|
|
|
* 1 request to get the list of the projector defaults.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2018-07-09 23:22:26 +02:00
|
|
|
for index in range(10):
|
|
|
|
Projector.objects.create(name="Projector{}".format(index))
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
assert count_queries(Projector.get_elements) == 2
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_chat_message_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 chatmessages.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
user = User.objects.get(username="admin")
|
2018-07-09 23:22:26 +02:00
|
|
|
for index in range(10):
|
|
|
|
ChatMessage.objects.create(user=user)
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
assert count_queries(ChatMessage.get_elements) == 1
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_tag_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 tags.
|
|
|
|
"""
|
|
|
|
for index in range(10):
|
2019-01-06 16:22:33 +01:00
|
|
|
Tag.objects.create(name="tag{}".format(index))
|
2018-07-09 23:22:26 +02:00
|
|
|
|
|
|
|
assert count_queries(Tag.get_elements) == 1
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
|
|
|
|
@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
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2018-07-09 23:22:26 +02:00
|
|
|
config.save_default_values()
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
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)
|