2018-07-09 23:22:26 +02:00
|
|
|
from django.urls import reverse
|
2017-09-04 00:25:45 +02:00
|
|
|
from django_redis import get_redis_connection
|
2016-10-17 16:56:19 +02:00
|
|
|
from rest_framework import status
|
2016-09-18 16:00:31 +02:00
|
|
|
from rest_framework.test import APIClient
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
class TestProjectorDBQueries(TestCase):
|
|
|
|
"""
|
|
|
|
Tests that receiving elements only need the required db queries.
|
|
|
|
|
|
|
|
Therefore in setup some objects are created and received with different
|
|
|
|
user accounts.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
|
|
|
config['general_system_enable_anonymous'] = True
|
2017-08-22 14:17:20 +02:00
|
|
|
config.save_default_values()
|
2016-09-18 16:00:31 +02:00
|
|
|
for index in range(10):
|
2016-09-30 21:43:22 +02:00
|
|
|
Projector.objects.create(name="Projector{}".format(index))
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
def test_admin(self):
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
2017-09-04 00:25:45 +02:00
|
|
|
* 7 requests to get the session an the request user with its permissions,
|
|
|
|
* 1 requests to get the list of all projectors,
|
2016-10-01 01:30:55 +02:00
|
|
|
* 1 request to get the list of the projector defaults.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
|
|
|
self.client.force_login(User.objects.get(pk=1))
|
2017-09-04 00:25:45 +02:00
|
|
|
get_redis_connection("default").flushall()
|
|
|
|
with self.assertNumQueries(9):
|
2016-09-18 16:00:31 +02:00
|
|
|
self.client.get(reverse('projector-list'))
|
|
|
|
|
|
|
|
def test_anonymous(self):
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
2016-12-17 09:30:20 +01:00
|
|
|
* 3 requests to get the permission for anonymous,
|
2017-09-04 00:25:45 +02:00
|
|
|
* 1 requests to get the list of all projectors,
|
2016-10-01 01:30:55 +02:00
|
|
|
* 1 request to get the list of the projector defaults and
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
get_redis_connection("default").flushall()
|
|
|
|
with self.assertNumQueries(5):
|
2016-09-18 16:00:31 +02:00
|
|
|
self.client.get(reverse('projector-list'))
|
|
|
|
|
|
|
|
|
|
|
|
class TestCharmessageDBQueries(TestCase):
|
|
|
|
"""
|
|
|
|
Tests that receiving elements only need the required db queries.
|
|
|
|
|
|
|
|
Therefore in setup some objects are created and received with different
|
|
|
|
user accounts.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
|
|
|
config['general_system_enable_anonymous'] = True
|
2017-08-22 14:17:20 +02:00
|
|
|
config.save_default_values()
|
2016-09-18 16:00:31 +02:00
|
|
|
user = User.objects.get(pk=1)
|
|
|
|
for index in range(10):
|
|
|
|
ChatMessage.objects.create(user=user)
|
|
|
|
|
|
|
|
def test_admin(self):
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
2017-09-04 00:25:45 +02:00
|
|
|
* 7 requests to get the session an the request user with its permissions,
|
|
|
|
* 1 requests to get the list of all chatmessages,
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
|
|
|
self.client.force_login(User.objects.get(pk=1))
|
2017-09-04 00:25:45 +02:00
|
|
|
get_redis_connection("default").flushall()
|
|
|
|
with self.assertNumQueries(8):
|
2016-09-18 16:00:31 +02:00
|
|
|
self.client.get(reverse('chatmessage-list'))
|
|
|
|
|
|
|
|
|
|
|
|
class TestTagDBQueries(TestCase):
|
|
|
|
"""
|
|
|
|
Tests that receiving elements only need the required db queries.
|
|
|
|
|
|
|
|
Therefore in setup some objects are created and received with different
|
|
|
|
user accounts.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
|
|
|
config['general_system_enable_anonymous'] = True
|
2017-08-22 14:17:20 +02:00
|
|
|
config.save_default_values()
|
2016-09-18 16:00:31 +02:00
|
|
|
for index in range(10):
|
|
|
|
Tag.objects.create(name='tag{}'.format(index))
|
|
|
|
|
|
|
|
def test_admin(self):
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
2017-09-04 00:25:45 +02:00
|
|
|
* 5 requests to get the session an the request user with its permissions,
|
|
|
|
* 1 requests to get the list of all tags,
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
|
|
|
self.client.force_login(User.objects.get(pk=1))
|
2017-09-04 00:25:45 +02:00
|
|
|
get_redis_connection("default").flushall()
|
|
|
|
with self.assertNumQueries(6):
|
2016-09-18 16:00:31 +02:00
|
|
|
self.client.get(reverse('tag-list'))
|
|
|
|
|
|
|
|
def test_anonymous(self):
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
2017-01-26 15:34:24 +01:00
|
|
|
* 1 requests to see if anonyomus is enabled
|
2017-09-04 00:25:45 +02:00
|
|
|
* 1 requests to get the list of all projectors,
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
get_redis_connection("default").flushall()
|
|
|
|
with self.assertNumQueries(2):
|
2016-09-18 16:00:31 +02:00
|
|
|
self.client.get(reverse('tag-list'))
|
|
|
|
|
|
|
|
|
|
|
|
class TestConfigDBQueries(TestCase):
|
|
|
|
"""
|
|
|
|
Tests that receiving elements only need the required db queries.
|
|
|
|
|
|
|
|
Therefore in setup some objects are created and received with different
|
|
|
|
user accounts.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
|
|
|
config['general_system_enable_anonymous'] = True
|
2017-08-22 14:17:20 +02:00
|
|
|
config.save_default_values()
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
def test_admin(self):
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
2017-09-04 00:25:45 +02:00
|
|
|
* 5 requests to get the session an the request user with its permissions and
|
2016-09-18 16:00:31 +02:00
|
|
|
* 1 requests to get the list of all config values
|
|
|
|
"""
|
|
|
|
self.client.force_login(User.objects.get(pk=1))
|
2017-09-04 00:25:45 +02:00
|
|
|
get_redis_connection("default").flushall()
|
|
|
|
with self.assertNumQueries(6):
|
2016-09-18 16:00:31 +02:00
|
|
|
self.client.get(reverse('config-list'))
|
|
|
|
|
|
|
|
def test_anonymous(self):
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries are done:
|
2017-09-04 00:25:45 +02:00
|
|
|
* 1 requests to see if anonymous is enabled and get all config values
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2017-09-04 00:25:45 +02:00
|
|
|
get_redis_connection("default").flushall()
|
|
|
|
with self.assertNumQueries(1):
|
2016-09-18 16:00:31 +02:00
|
|
|
self.client.get(reverse('config-list'))
|
2016-10-17 16:56:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ChatMessageViewSet(TestCase):
|
|
|
|
"""
|
|
|
|
Tests requests to deal with chat messages.
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
|
|
|
admin = User.objects.get(pk=1)
|
|
|
|
self.client.force_login(admin)
|
|
|
|
ChatMessage.objects.create(message='test_message_peechiel8IeZoohaem9e', user=admin)
|
|
|
|
|
|
|
|
def test_clear_chat(self):
|
|
|
|
response = self.client.post(reverse('chatmessage-clear'))
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
self.assertEqual(ChatMessage.objects.all().count(), 0)
|