2020-12-04 06:51:01 +01:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from openslides.chat.models import ChatGroup, ChatMessage
|
|
|
|
from openslides.utils.auth import get_group_model
|
|
|
|
from tests.count_queries import count_queries
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_motion_db_queries():
|
|
|
|
"""
|
|
|
|
Tests that only the following db queries for chat groups are done:
|
|
|
|
* 1 request to get all chat groups
|
2021-02-18 11:22:41 +01:00
|
|
|
* 1 request to get all read groups
|
|
|
|
* 1 request to get all write groups
|
2020-12-04 06:51:01 +01:00
|
|
|
|
|
|
|
Tests that only the following db queries for chat messages are done:
|
|
|
|
* 1 request to fet all chat messages
|
|
|
|
* 1 request to get all chat groups
|
2021-02-18 11:22:41 +01:00
|
|
|
* 1 request to get all read groups
|
|
|
|
* 1 request to get all write groups
|
2020-12-04 06:51:01 +01:00
|
|
|
"""
|
|
|
|
group1 = get_group_model().objects.create(name="group1")
|
|
|
|
group2 = get_group_model().objects.create(name="group2")
|
2021-02-18 11:22:41 +01:00
|
|
|
group3 = get_group_model().objects.create(name="group3")
|
|
|
|
group4 = get_group_model().objects.create(name="group4")
|
2020-12-04 06:51:01 +01:00
|
|
|
|
|
|
|
for i1 in range(5):
|
|
|
|
chatgroup = ChatGroup.objects.create(name=f"motion{i1}")
|
2021-02-18 11:22:41 +01:00
|
|
|
chatgroup.read_groups.add(group1, group2)
|
|
|
|
chatgroup.write_groups.add(group3, group4)
|
2020-12-04 06:51:01 +01:00
|
|
|
|
|
|
|
for i2 in range(10):
|
|
|
|
ChatMessage.objects.create(
|
2021-02-09 16:06:44 +01:00
|
|
|
text=f"text-{i1}-{i2}",
|
|
|
|
username=f"user-{i1}-{i2}",
|
|
|
|
user_id=i1 * 1000 + i2,
|
|
|
|
chatgroup=chatgroup,
|
2020-12-04 06:51:01 +01:00
|
|
|
)
|
|
|
|
|
2021-02-18 11:22:41 +01:00
|
|
|
assert count_queries(ChatGroup.get_elements)() == 3
|
|
|
|
assert count_queries(ChatMessage.get_elements)() == 4
|