コード例 #1
0
def test_motion_db_queries():
    """
    Tests that only the following db queries for chat groups are done:
    * 1 request to get all chat groups
    * 1 request to get all read groups
    * 1 request to get all write groups

    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
    * 1 request to get all read groups
    * 1 request to get all write groups
    """
    group1 = get_group_model().objects.create(name="group1")
    group2 = get_group_model().objects.create(name="group2")
    group3 = get_group_model().objects.create(name="group3")
    group4 = get_group_model().objects.create(name="group4")

    for i1 in range(5):
        chatgroup = ChatGroup.objects.create(name=f"motion{i1}")
        chatgroup.read_groups.add(group1, group2)
        chatgroup.write_groups.add(group3, group4)

        for i2 in range(10):
            ChatMessage.objects.create(
                text=f"text-{i1}-{i2}",
                username=f"user-{i1}-{i2}",
                user_id=i1 * 1000 + i2,
                chatgroup=chatgroup,
            )

    assert count_queries(ChatGroup.get_elements)() == 3
    assert count_queries(ChatMessage.get_elements)() == 4
コード例 #2
0
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
コード例 #3
0
ファイル: test_viewset.py プロジェクト: funakura/OpenSlides
def test_workflow_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 request to get the list of all workflows and
    * 1 request to get all states.
    """

    assert count_queries(Workflow.get_elements)() == 2
コード例 #4
0
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):
        Tag.objects.create(name=f"tag{index}")

    assert count_queries(Tag.get_elements)() == 1
コード例 #5
0
ファイル: test_viewset.py プロジェクト: funakura/OpenSlides
def test_category_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 requests to get the list of all categories.
    """
    for index in range(10):
        Category.objects.create(name=f"category{index}")

    assert count_queries(Category.get_elements)() == 1
コード例 #6
0
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):
        Projector.objects.create(name=f"Projector{index}")

    assert count_queries(Projector.get_elements)() == 2
コード例 #7
0
def test_group_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 request to get the list of all groups.
    * 1 request to get the permissions
    """
    for index in range(10):
        Group.objects.create(name=f"group{index}")

    assert count_queries(Group.get_elements)() == 2
コード例 #8
0
def test_user_db_queries():
    """
    Tests that only the following db queries are done:
    * 2 requests to get the list of all users and
    * 1 requests to get the list of all groups.
    """
    for index in range(10):
        User.objects.create(username=f"user{index}")

    assert count_queries(User.get_elements)() == 3
コード例 #9
0
ファイル: test_viewset.py プロジェクト: funakura/OpenSlides
def test_statute_paragraph_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 requests to get the list of all statute paragraphs.
    """
    for index in range(10):
        StatuteParagraph.objects.create(title=f"statute_paragraph{index}",
                                        text=f"text{index}")

    assert count_queries(StatuteParagraph.get_elements)() == 1
コード例 #10
0
ファイル: test_viewset.py プロジェクト: topelrapha/OpenSlides
def test_topic_item_db_queries():
    """
    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
    * 1 request to get the list of speakers
    """
    for index in range(10):
        Topic.objects.create(title=f"topic-{index}")

    assert count_queries(Topic.get_elements)() == 4
コード例 #11
0
ファイル: test_viewset.py プロジェクト: funakura/OpenSlides
def test_motion_block_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 request to get all motion blocks
    * 1 request to get all agenda items
    * 1 request to get all lists of speakers
    * 1 request to get all motions
    """
    for i in range(5):
        motion_block = MotionBlock.objects.create(title=f"block{i}")
        for j in range(3):
            Motion.objects.create(title=f"motion{i}_{j}",
                                  text="text",
                                  motion_block=motion_block)

    assert count_queries(MotionBlock.get_elements)() == 4
コード例 #12
0
ファイル: test_viewset.py プロジェクト: td00/OpenSlides
def test_mediafiles_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 requests to get the list of all files
    * 1 request to get all lists of speakers.
    * 1 request to get all groups
    * 1 request to prefetch parents
    """
    for index in range(10):
        Mediafile.objects.create(
            title=f"some_file{index}",
            original_filename=f"some_file{index}",
            mediafile=SimpleUploadedFile(f"some_file{index}", b"some content."),
        )

    assert count_queries(Mediafile.get_elements)() == 4
コード例 #13
0
ファイル: test_viewset.py プロジェクト: dlrgjugend/OpenSlides
def test_list_of_speakers_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 requests to get the list of all lists of speakers
    * 1 request to get all speakers
    * 4 requests to get the assignments, motions, topics and mediafiles and
    """
    for index in range(10):
        Topic.objects.create(title=f"topic{index}")
    parent = Topic.objects.create(title="parent").agenda_item
    child = Topic.objects.create(title="child").agenda_item
    child.parent = parent
    child.save()
    Motion.objects.create(title="motion1")
    Motion.objects.create(title="motion2")
    Assignment.objects.create(title="assignment", open_posts=5)
    Mediafile.objects.create(title="mediafile",
                             mediafile=SimpleUploadedFile(
                                 "some_file", b"some content."))

    assert count_queries(ListOfSpeakers.get_elements)() == 6
コード例 #14
0
def test_assignment_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 requests to get the list of all assignments,
    * 1 request to get all related users,
    * 1 request to get the agenda item,
    * 1 request to get the list of speakers,
    * 1 request to get the tags,
    * 1 request to get the attachments and
    * 1 Request to get the polls of the assignment
    * 1 Request to get the options of these polls
    """
    for index in range(10):
        assignment = Assignment.objects.create(title=f"assignment{index}", open_posts=1)
        for i in range(2):
            AssignmentPoll.objects.create(
                assignment=assignment,
                title="test_title_nah5Ahh6IkeeM8rah3ai",
                pollmethod=AssignmentPoll.POLLMETHOD_YN,
                type=AssignmentPoll.TYPE_NAMED,
            )

    assert count_queries(Assignment.get_elements)() == 8
コード例 #15
0
def test_agenda_item_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 request to get the list of all agenda items,
    * 1 request to get all assignments,
    * 1 request to get all motions,
    * 1 request to get all topics,
    * 1 request to get all motion blocks and
    * 1 request to get all parents
    """
    parent = Topic.objects.create(title="parent").agenda_item
    for index in range(10):
        item = Topic.objects.create(title=f"topic{index}").agenda_item
        item.parent = parent
        item.save()
    Motion.objects.create(title="motion1")
    Motion.objects.create(title="motion2")
    Assignment.objects.create(title="assignment1", open_posts=5)
    Assignment.objects.create(title="assignment2", open_posts=5)
    MotionBlock.objects.create(title="block1")
    MotionBlock.objects.create(title="block1")

    assert count_queries(Item.get_elements)() == 6
コード例 #16
0
def test_motion_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 requests to get the list of all motions,
    * 1 request to get the associated workflow
    * 1 request for all motion comments
    * 1 request for all motion comment sections required for the comments
    * 1 request for all users required for the read_groups of the sections
    * 1 request to get all amendments of all motions
    * 1 request to get the agenda item,
    * 1 request to get the list of speakers,
    * 1 request to get the attachments,
    * 1 request to get the tags,
    * 2 requests to get the submitters and supporters,
    * 1 request for change_recommendations.

    Two comment sections are created and for each motions two comments.
    """
    section1 = MotionCommentSection.objects.create(name="test_section")
    section2 = MotionCommentSection.objects.create(name="test_section")

    user1 = get_user_model().objects.create_user(
        username="******",
        password="******",
    )
    user2 = get_user_model().objects.create_user(
        username="******",
        password="******",
    )
    user3 = get_user_model().objects.create_user(
        username="******",
        password="******",
    )

    for index in range(10):
        motion = Motion.objects.create(title=f"motion{index}")

        motion.supporters.add(user1, user2)
        Submitter.objects.add(user2, motion)
        Submitter.objects.add(user3, motion)

        MotionComment.objects.create(
            comment="test_comment", motion=motion, section=section1
        )
        MotionComment.objects.create(
            comment="test_comment2", motion=motion, section=section2
        )

        block = MotionBlock.objects.create(title=f"block_{index}")
        motion.motion_block = block
        category = Category.objects.create(name=f"category_{index}")
        motion.category = category
        motion.save()

        # Create a poll:
        poll = MotionPoll.objects.create(
            motion=motion,
            title="test_title_XeejaeFez3chahpei9qu",
            pollmethod="YNA",
            type=BasePoll.TYPE_NAMED,
        )
        poll.create_options()

    assert count_queries(Motion.get_elements)() == 13