From 790c16a3e845d56ed7882a28848532f72c037be4 Mon Sep 17 00:00:00 2001 From: fuzzylogic2000 Date: Tue, 22 Nov 2022 16:44:08 +0100 Subject: [PATCH] tests/rules: add group members to all rule tests --- .../rules/test_rules_comment_chapter.py | 12 +++ .../rules/test_rules_comment_paragraph.py | 12 +++ .../rules/test_rules_view_chapter.py | 12 +++ .../rules/test_rules_view_paragraph.py | 12 +++ tests/ideas/rules/test_rules_add.py | 59 +++++++++++-- tests/ideas/rules/test_rules_change.py | 67 ++++++++++++--- tests/ideas/rules/test_rules_comment.py | 79 ++++++++++++++--- tests/ideas/rules/test_rules_moderate.py | 67 ++++++++++++--- tests/ideas/rules/test_rules_view.py | 81 +++++++++++++++--- tests/kiezkasse/rules/test_rules_add.py | 59 +++++++++++-- tests/kiezkasse/rules/test_rules_change.py | 67 ++++++++++++--- tests/kiezkasse/rules/test_rules_comment.py | 79 ++++++++++++++--- tests/kiezkasse/rules/test_rules_moderate.py | 67 ++++++++++++--- tests/kiezkasse/rules/test_rules_rate.py | 79 ++++++++++++++--- tests/kiezkasse/rules/test_rules_view.py | 79 ++++++++++++++--- tests/livequestions/rules/test_rules_add.py | 50 +++++++++-- .../livequestions/rules/test_rules_change.py | 85 +++++++++++++++---- .../rules/test_rules_moderate.py | 85 +++++++++++++++---- tests/livequestions/rules/test_rules_view.py | 69 ++++++++++++--- tests/mapideas/rules/test_rules_add.py | 59 +++++++++++-- tests/mapideas/rules/test_rules_change.py | 67 ++++++++++++--- tests/mapideas/rules/test_rules_comment.py | 79 ++++++++++++++--- tests/mapideas/rules/test_rules_moderate.py | 73 +++++++++++++--- tests/mapideas/rules/test_rules_rate.py | 79 ++++++++++++++--- tests/mapideas/rules/test_rules_view.py | 79 ++++++++++++++--- tests/maptopicprio/rules/test_rules_add.py | 59 +++++++++++-- tests/maptopicprio/rules/test_rules_change.py | 67 ++++++++++++--- .../maptopicprio/rules/test_rules_comment.py | 79 ++++++++++++++--- tests/maptopicprio/rules/test_rules_rate.py | 79 ++++++++++++++--- tests/maptopicprio/rules/test_rules_view.py | 81 +++++++++++++++--- tests/topicprio/rules/test_rules_add.py | 59 +++++++++++-- tests/topicprio/rules/test_rules_change.py | 69 ++++++++++++--- tests/topicprio/rules/test_rules_comment.py | 79 ++++++++++++++--- tests/topicprio/rules/test_rules_rate.py | 79 ++++++++++++++--- tests/topicprio/rules/test_rules_view.py | 79 ++++++++++++++--- 35 files changed, 1976 insertions(+), 310 deletions(-) diff --git a/tests/documents/rules/test_rules_comment_chapter.py b/tests/documents/rules/test_rules_comment_chapter.py index efa6226bc1..5a55e6d365 100644 --- a/tests/documents/rules/test_rules_comment_chapter.py +++ b/tests/documents/rules/test_rules_comment_chapter.py @@ -26,11 +26,13 @@ def test_pre_phase(phase_factory, chapter_factory, user_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, group_member_in_org, item) assert not rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -47,11 +49,13 @@ def test_phase_active(phase_factory, chapter_factory, user_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) assert rules.has_perm(perm_name, group_member_in_org, item) assert rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -72,11 +76,13 @@ def test_phase_active_project_private(phase_factory, chapter_factory, project.participants.add(participant) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.access == Access.PRIVATE with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, group_member_in_org, item) assert not rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -98,11 +104,13 @@ def test_phase_active_project_semipublic(phase_factory, chapter_factory, project.participants.add(participant) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.access == Access.SEMIPUBLIC with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, group_member_in_org, item) assert not rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -122,11 +130,13 @@ def test_phase_active_project_draft(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, group_member_in_org, item) assert not rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -146,11 +156,13 @@ def test_post_phase_project_archived(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, group_member_in_org, item) assert not rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) diff --git a/tests/documents/rules/test_rules_comment_paragraph.py b/tests/documents/rules/test_rules_comment_paragraph.py index ad51a02a6c..424b72903e 100644 --- a/tests/documents/rules/test_rules_comment_paragraph.py +++ b/tests/documents/rules/test_rules_comment_paragraph.py @@ -26,6 +26,7 @@ def test_pre_phase(phase_factory, chapter_factory, paragraph_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -33,6 +34,7 @@ def test_pre_phase(phase_factory, chapter_factory, paragraph_factory, with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, paragraph) assert not rules.has_perm(perm_name, user, paragraph) + assert not rules.has_perm(perm_name, creator, paragraph) assert not rules.has_perm(perm_name, group_member_in_org, paragraph) assert not rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -49,6 +51,7 @@ def test_phase_active(phase_factory, chapter_factory, paragraph_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -56,6 +59,7 @@ def test_phase_active(phase_factory, chapter_factory, paragraph_factory, with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, paragraph) assert rules.has_perm(perm_name, user, paragraph) + assert rules.has_perm(perm_name, creator, paragraph) assert rules.has_perm(perm_name, group_member_in_org, paragraph) assert rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -76,6 +80,7 @@ def test_phase_active_project_private(phase_factory, chapter_factory, project.participants.add(participant) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -83,6 +88,7 @@ def test_phase_active_project_private(phase_factory, chapter_factory, with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, paragraph) assert not rules.has_perm(perm_name, user, paragraph) + assert not rules.has_perm(perm_name, creator, paragraph) assert not rules.has_perm(perm_name, group_member_in_org, paragraph) assert not rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -104,6 +110,7 @@ def test_phase_active_project_semipublic(phase_factory, chapter_factory, project.participants.add(participant) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -111,6 +118,7 @@ def test_phase_active_project_semipublic(phase_factory, chapter_factory, with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, paragraph) assert not rules.has_perm(perm_name, user, paragraph) + assert not rules.has_perm(perm_name, creator, paragraph) assert not rules.has_perm(perm_name, group_member_in_org, paragraph) assert not rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -130,6 +138,7 @@ def test_phase_active_project_draft(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -137,6 +146,7 @@ def test_phase_active_project_draft(phase_factory, chapter_factory, with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, paragraph) assert not rules.has_perm(perm_name, user, paragraph) + assert not rules.has_perm(perm_name, creator, paragraph) assert not rules.has_perm(perm_name, group_member_in_org, paragraph) assert not rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -155,6 +165,7 @@ def test_post_phase_project_archived(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -162,6 +173,7 @@ def test_post_phase_project_archived(phase_factory, chapter_factory, with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, paragraph) assert not rules.has_perm(perm_name, user, paragraph) + assert not rules.has_perm(perm_name, creator, paragraph) assert not rules.has_perm(perm_name, group_member_in_org, paragraph) assert not rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) diff --git a/tests/documents/rules/test_rules_view_chapter.py b/tests/documents/rules/test_rules_view_chapter.py index 5615e164a9..6bdc12397a 100644 --- a/tests/documents/rules/test_rules_view_chapter.py +++ b/tests/documents/rules/test_rules_view_chapter.py @@ -27,11 +27,13 @@ def test_pre_phase(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) assert rules.has_perm(perm_name, group_member_in_org, item) assert rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -48,11 +50,13 @@ def test_phase_active(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.access == Access.PUBLIC with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) assert rules.has_perm(perm_name, group_member_in_org, item) assert rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -73,11 +77,13 @@ def test_phase_active_project_private(phase_factory, chapter_factory, project.participants.add(participant) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.access == Access.PRIVATE with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, group_member_in_org, item) assert not rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -99,11 +105,13 @@ def test_phase_active_project_semipublic(phase_factory, chapter_factory, project.participants.add(participant) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.access == Access.SEMIPUBLIC with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) assert rules.has_perm(perm_name, group_member_in_org, item) assert rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -123,11 +131,13 @@ def test_phase_active_project_draft(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, group_member_in_org, item) assert not rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) @@ -146,11 +156,13 @@ def test_post_phase_project_archived(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_archived with freeze_post_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) assert rules.has_perm(perm_name, group_member_in_org, item) assert rules.has_perm(perm_name, group_member_out, item) assert rules.has_perm(perm_name, group_member_in_pro, item) diff --git a/tests/documents/rules/test_rules_view_paragraph.py b/tests/documents/rules/test_rules_view_paragraph.py index b0914120d3..f0b678be56 100644 --- a/tests/documents/rules/test_rules_view_paragraph.py +++ b/tests/documents/rules/test_rules_view_paragraph.py @@ -27,6 +27,7 @@ def test_pre_phase(phase_factory, chapter_factory, paragraph_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -34,6 +35,7 @@ def test_pre_phase(phase_factory, chapter_factory, paragraph_factory, with freeze_pre_phase(phase): assert rules.has_perm(perm_name, anonymous, paragraph) assert rules.has_perm(perm_name, user, paragraph) + assert rules.has_perm(perm_name, creator, paragraph) assert rules.has_perm(perm_name, group_member_in_org, paragraph) assert rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -51,6 +53,7 @@ def test_phase_active(phase_factory, chapter_factory, paragraph_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -58,6 +61,7 @@ def test_phase_active(phase_factory, chapter_factory, paragraph_factory, with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, paragraph) assert rules.has_perm(perm_name, user, paragraph) + assert rules.has_perm(perm_name, creator, paragraph) assert rules.has_perm(perm_name, group_member_in_org, paragraph) assert rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -79,6 +83,7 @@ def test_phase_active_project_private(phase_factory, chapter_factory, project.participants.add(participant) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -86,6 +91,7 @@ def test_phase_active_project_private(phase_factory, chapter_factory, with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, paragraph) assert not rules.has_perm(perm_name, user, paragraph) + assert not rules.has_perm(perm_name, creator, paragraph) assert not rules.has_perm(perm_name, group_member_in_org, paragraph) assert not rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -108,6 +114,7 @@ def test_phase_active_project_semipublic(phase_factory, chapter_factory, project.participants.add(participant) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -115,6 +122,7 @@ def test_phase_active_project_semipublic(phase_factory, chapter_factory, with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, paragraph) assert rules.has_perm(perm_name, user, paragraph) + assert rules.has_perm(perm_name, creator, paragraph) assert rules.has_perm(perm_name, group_member_in_org, paragraph) assert rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -135,6 +143,7 @@ def test_phase_active_project_draft(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -142,6 +151,7 @@ def test_phase_active_project_draft(phase_factory, chapter_factory, with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, paragraph) assert not rules.has_perm(perm_name, user, paragraph) + assert not rules.has_perm(perm_name, creator, paragraph) assert not rules.has_perm(perm_name, group_member_in_org, paragraph) assert not rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) @@ -161,6 +171,7 @@ def test_post_phase_project_archived(phase_factory, chapter_factory, anonymous, moderator, initiator = setup_users(project) project, group_member_in_org, group_member_in_pro, group_member_out = \ setup_group_members(project, group_factory, user_factory) + creator = item.creator paragraph = paragraph_factory(chapter=item) @@ -168,6 +179,7 @@ def test_post_phase_project_archived(phase_factory, chapter_factory, with freeze_post_phase(phase): assert rules.has_perm(perm_name, anonymous, paragraph) assert rules.has_perm(perm_name, user, paragraph) + assert rules.has_perm(perm_name, creator, paragraph) assert rules.has_perm(perm_name, group_member_in_org, paragraph) assert rules.has_perm(perm_name, group_member_out, paragraph) assert rules.has_perm(perm_name, group_member_in_pro, paragraph) diff --git a/tests/ideas/rules/test_rules_add.py b/tests/ideas/rules/test_rules_add.py index 09ea0d846a..717eb8e336 100644 --- a/tests/ideas/rules/test_rules_add.py +++ b/tests/ideas/rules/test_rules_add.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.ideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_ideas.add_idea' @@ -17,41 +18,58 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, user): +def test_pre_phase( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active(phase_factory, user): +def test_phase_active( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert rules.has_perm(perm_name, user, module) + assert rules.has_perm(perm_name, group_member_out, module) + assert rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, user, user2): +def test_phase_active_project_private( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +77,25 @@ def test_phase_active_project_private(phase_factory, user, user2): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) assert rules.has_perm(perm_name, participant, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, user, user2): +def test_phase_active_project_semipublic( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +103,53 @@ def test_phase_active_project_semipublic(phase_factory, user, user2): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) assert rules.has_perm(perm_name, participant, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, user): +def test_phase_active_project_draft( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, user): +def test_post_phase_project_archived( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) diff --git a/tests/ideas/rules/test_rules_change.py b/tests/ideas/rules/test_rules_change.py index 7e5c57afc0..0d1967121a 100644 --- a/tests/ideas/rules/test_rules_change.py +++ b/tests/ideas/rules/test_rules_change.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.ideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_ideas.change_idea' @@ -17,47 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, idea_factory, user): +def test_pre_phase( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, idea_factory, user): +def test_phase_active( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, idea_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, idea_factory, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -66,20 +86,27 @@ def test_phase_active_project_private(phase_factory, idea_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, idea_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, idea_factory, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -88,39 +115,59 @@ def test_phase_active_project_semipublic(phase_factory, idea_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, idea_factory, user): +def test_phase_active_project_draft( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, idea_factory, user): +def test_post_phase_project_archived( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/ideas/rules/test_rules_comment.py b/tests/ideas/rules/test_rules_comment.py index b9b77a02cd..09aae1ce52 100644 --- a/tests/ideas/rules/test_rules_comment.py +++ b/tests/ideas/rules/test_rules_comment.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.ideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_ideas.comment_idea' @@ -17,42 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, idea_factory, user): +def test_pre_phase( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, idea_factory, user): +def test_phase_active( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, idea_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, idea_factory, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -60,19 +85,28 @@ def test_phase_active_project_private(phase_factory, idea_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, idea_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, idea_factory, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -80,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, idea_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, idea_factory, user): +def test_phase_active_project_draft( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, idea_factory, user): +def test_post_phase_project_archived( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/ideas/rules/test_rules_moderate.py b/tests/ideas/rules/test_rules_moderate.py index 5df72b8c55..bd1366dc68 100644 --- a/tests/ideas/rules/test_rules_moderate.py +++ b/tests/ideas/rules/test_rules_moderate.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.ideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_ideas.moderate_idea' @@ -17,47 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, idea_factory, user): +def test_pre_phase( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, idea_factory, user): +def test_phase_active( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, idea_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, idea_factory, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -66,20 +86,27 @@ def test_phase_active_project_private(phase_factory, idea_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, idea_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, idea_factory, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -88,39 +115,59 @@ def test_phase_active_project_semipublic(phase_factory, idea_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, idea_factory, user): +def test_phase_active_project_draft( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, idea_factory, user): +def test_post_phase_project_archived( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) diff --git a/tests/ideas/rules/test_rules_view.py b/tests/ideas/rules/test_rules_view.py index 161c025c97..df31f756fb 100644 --- a/tests/ideas/rules/test_rules_view.py +++ b/tests/ideas/rules/test_rules_view.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.ideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_ideas.view_idea' @@ -17,41 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, idea_factory, user): +def test_pre_phase( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, idea_factory, user): +def test_phase_active( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, idea_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, idea_factory, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +85,28 @@ def test_phase_active_project_private(phase_factory, idea_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, idea_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, idea_factory, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, idea_factory, assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, idea_factory, user): +def test_phase_active_project_draft( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, idea_factory, user): +def test_post_phase_project_archived( + phase_factory, idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/kiezkasse/rules/test_rules_add.py b/tests/kiezkasse/rules/test_rules_add.py index 0c5a7abc1c..5dbbd380b2 100644 --- a/tests/kiezkasse/rules/test_rules_add.py +++ b/tests/kiezkasse/rules/test_rules_add.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.kiezkasse import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_kiezkasse.add_proposal' @@ -17,60 +18,84 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, user): +def test_pre_phase( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active(phase_factory, user): +def test_phase_active( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert rules.has_perm(perm_name, user, module) + assert rules.has_perm(perm_name, group_member_out, module) + assert rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, user, user2): +def test_phase_active_project_private( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.RequestPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, participant, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, user, user2): +def test_phase_active_project_semipublic( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.RequestPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +103,53 @@ def test_phase_active_project_semipublic(phase_factory, user, user2): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) assert rules.has_perm(perm_name, participant, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, user): +def test_phase_active_project_draft( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.RequestPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, user): +def test_post_phase_project_archived( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.RequestPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) diff --git a/tests/kiezkasse/rules/test_rules_change.py b/tests/kiezkasse/rules/test_rules_change.py index 98fb1f16db..2b4ed0dc24 100644 --- a/tests/kiezkasse/rules/test_rules_change.py +++ b/tests/kiezkasse/rules/test_rules_change.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.kiezkasse import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_kiezkasse.change_proposal' @@ -17,47 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, proposal_factory, user): +def test_pre_phase( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, proposal_factory, user): +def test_phase_active( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -66,20 +86,27 @@ def test_phase_active_project_private(phase_factory, proposal_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -88,39 +115,59 @@ def test_phase_active_project_semipublic(phase_factory, proposal_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, proposal_factory, user): +def test_phase_active_project_draft( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, proposal_factory, user): +def test_post_phase_project_archived( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/kiezkasse/rules/test_rules_comment.py b/tests/kiezkasse/rules/test_rules_comment.py index 26fcfdcd29..cc5e5b7f30 100644 --- a/tests/kiezkasse/rules/test_rules_comment.py +++ b/tests/kiezkasse/rules/test_rules_comment.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.kiezkasse import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_kiezkasse.comment_proposal' @@ -17,42 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, proposal_factory, user): +def test_pre_phase( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, proposal_factory, user): +def test_phase_active( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -60,19 +85,28 @@ def test_phase_active_project_private(phase_factory, proposal_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -80,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, proposal_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, proposal_factory, user): +def test_phase_active_project_draft( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, proposal_factory, user): +def test_post_phase_project_archived( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/kiezkasse/rules/test_rules_moderate.py b/tests/kiezkasse/rules/test_rules_moderate.py index 9e77b4dc5c..acdf68e5c0 100644 --- a/tests/kiezkasse/rules/test_rules_moderate.py +++ b/tests/kiezkasse/rules/test_rules_moderate.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.kiezkasse import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_kiezkasse.moderate_proposal' @@ -17,47 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, proposal_factory, user): +def test_pre_phase( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, proposal_factory, user): +def test_phase_active( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -66,20 +86,27 @@ def test_phase_active_project_private(phase_factory, proposal_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -88,39 +115,59 @@ def test_phase_active_project_semipublic(phase_factory, proposal_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, proposal_factory, user): +def test_phase_active_project_draft( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, proposal_factory, user): +def test_post_phase_project_archived( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) diff --git a/tests/kiezkasse/rules/test_rules_rate.py b/tests/kiezkasse/rules/test_rules_rate.py index ee5b0ca61e..edeb7ce0b3 100644 --- a/tests/kiezkasse/rules/test_rules_rate.py +++ b/tests/kiezkasse/rules/test_rules_rate.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.kiezkasse import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_kiezkasse.rate_proposal' @@ -17,42 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, proposal_factory, user): +def test_pre_phase( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.FeedbackPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, proposal_factory, user): +def test_phase_active( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.FeedbackPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.FeedbackPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -60,19 +85,28 @@ def test_phase_active_project_private(phase_factory, proposal_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.FeedbackPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -80,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, proposal_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, proposal_factory, user): +def test_phase_active_project_draft( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.FeedbackPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, proposal_factory, user): +def test_post_phase_project_archived( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.FeedbackPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/kiezkasse/rules/test_rules_view.py b/tests/kiezkasse/rules/test_rules_view.py index fa9372340f..ad6f2b1122 100644 --- a/tests/kiezkasse/rules/test_rules_view.py +++ b/tests/kiezkasse/rules/test_rules_view.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.kiezkasse import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_kiezkasse.view_proposal' @@ -17,41 +18,65 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, proposal_factory, user): +def test_pre_phase( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, proposal_factory, user): +def test_phase_active( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +84,27 @@ def test_phase_active_project_private(phase_factory, proposal_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, proposal_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +112,60 @@ def test_phase_active_project_semipublic(phase_factory, proposal_factory, assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, proposal_factory, user): +def test_phase_active_project_draft( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, proposal_factory, user): +def test_post_phase_project_archived( + phase_factory, proposal_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/livequestions/rules/test_rules_add.py b/tests/livequestions/rules/test_rules_add.py index 9fba3c30a6..1aaa9051d0 100644 --- a/tests/livequestions/rules/test_rules_add.py +++ b/tests/livequestions/rules/test_rules_add.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.livequestions import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_livequestions.add_livequestion' @@ -17,41 +18,58 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, user): +def test_pre_phase( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.IssuePhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert not rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert not rules.has_perm(perm_name, initiator, module) + assert not rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active(phase_factory, user): +def test_phase_active( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.IssuePhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, module) assert rules.has_perm(perm_name, user, module) + assert rules.has_perm(perm_name, group_member_out, module) + assert rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, user, user2): +def test_phase_active_project_private( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.IssuePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +77,25 @@ def test_phase_active_project_private(phase_factory, user, user2): assert rules.has_perm(perm_name, anonymous, module) assert rules.has_perm(perm_name, user, module) assert rules.has_perm(perm_name, participant, module) + assert rules.has_perm(perm_name, group_member_out, module) + assert rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, user, user2): +def test_phase_active_project_semipublic( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.IssuePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,20 +103,31 @@ def test_phase_active_project_semipublic(phase_factory, user, user2): assert rules.has_perm(perm_name, anonymous, module) assert rules.has_perm(perm_name, user, module) assert rules.has_perm(perm_name, participant, module) + assert rules.has_perm(perm_name, group_member_out, module) + assert rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, user): +def test_post_phase_project_archived( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.IssuePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert not rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert not rules.has_perm(perm_name, initiator, module) + assert not rules.has_perm(perm_name, admin, module) diff --git a/tests/livequestions/rules/test_rules_change.py b/tests/livequestions/rules/test_rules_change.py index ab1cc538ad..d0137a8fad 100644 --- a/tests/livequestions/rules/test_rules_change.py +++ b/tests/livequestions/rules/test_rules_change.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.livequestions import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_livequestions.change_livequestion' @@ -17,100 +18,152 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, live_question_factory, user): +def test_pre_phase( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, live_question_factory, user): +def test_phase_active( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, - live_question_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, live_question_factory, phases.IssuePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, - live_question_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, live_question_factory, phases.IssuePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, - live_question_factory, - user): +def test_phase_active_project_draft( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, - live_question_factory, - user): +def test_post_phase_project_archived( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/livequestions/rules/test_rules_moderate.py b/tests/livequestions/rules/test_rules_moderate.py index a54acaee45..a6688797af 100644 --- a/tests/livequestions/rules/test_rules_moderate.py +++ b/tests/livequestions/rules/test_rules_moderate.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.livequestions import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_livequestions.moderate_livequestions' @@ -17,42 +18,65 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, live_question_factory, user): +def test_pre_phase( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, live_question_factory, user): +def test_phase_active( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, - live_question_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, live_question_factory, phases.IssuePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -60,19 +84,27 @@ def test_phase_active_project_private(phase_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, - live_question_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, live_question_factory, phases.IssuePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -80,39 +112,60 @@ def test_phase_active_project_semipublic(phase_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, - live_question_factory, - user): +def test_phase_active_project_draft( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, - live_question_factory, - user): +def test_post_phase_project_archived( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/livequestions/rules/test_rules_view.py b/tests/livequestions/rules/test_rules_view.py index 1e6922bac1..c571e03f21 100644 --- a/tests/livequestions/rules/test_rules_view.py +++ b/tests/livequestions/rules/test_rules_view.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.livequestions import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_livequestions.view_livequestion' @@ -17,41 +18,65 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, live_question_factory, user): +def test_pre_phase( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, live_question_factory, user): +def test_phase_active( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, live_question_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, live_question_factory, phases.IssuePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +84,27 @@ def test_phase_active_project_private(phase_factory, live_question_factory, assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, live_question_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, live_question_factory, phases.IssuePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,22 +112,35 @@ def test_phase_active_project_semipublic(phase_factory, live_question_factory, assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, - live_question_factory, - user): +def test_post_phase_project_archived( + phase_factory, live_question_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, live_question_factory, phases.IssuePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/mapideas/rules/test_rules_add.py b/tests/mapideas/rules/test_rules_add.py index fbc6fd0a1e..fa23bb29ed 100644 --- a/tests/mapideas/rules/test_rules_add.py +++ b/tests/mapideas/rules/test_rules_add.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.mapideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_mapideas.add_mapidea' @@ -17,41 +18,58 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, user): +def test_pre_phase( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active(phase_factory, user): +def test_phase_active( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert rules.has_perm(perm_name, user, module) + assert rules.has_perm(perm_name, group_member_out, module) + assert rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, user, user2): +def test_phase_active_project_private( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +77,25 @@ def test_phase_active_project_private(phase_factory, user, user2): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) assert rules.has_perm(perm_name, participant, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, user, user2): +def test_phase_active_project_semipublic( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +103,53 @@ def test_phase_active_project_semipublic(phase_factory, user, user2): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) assert rules.has_perm(perm_name, participant, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, user): +def test_phase_active_project_draft( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, user): +def test_post_phase_project_archived( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) diff --git a/tests/mapideas/rules/test_rules_change.py b/tests/mapideas/rules/test_rules_change.py index 324f679f33..72d51ef641 100644 --- a/tests/mapideas/rules/test_rules_change.py +++ b/tests/mapideas/rules/test_rules_change.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.mapideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_mapideas.change_mapidea' @@ -17,47 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, map_idea_factory, user): +def test_pre_phase( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, map_idea_factory, user): +def test_phase_active( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -66,20 +86,27 @@ def test_phase_active_project_private(phase_factory, map_idea_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -88,39 +115,59 @@ def test_phase_active_project_semipublic(phase_factory, map_idea_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, map_idea_factory, user): +def test_phase_active_project_draft( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, map_idea_factory, user): +def test_post_phase_project_archived( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/mapideas/rules/test_rules_comment.py b/tests/mapideas/rules/test_rules_comment.py index 388641e968..827c84bd81 100644 --- a/tests/mapideas/rules/test_rules_comment.py +++ b/tests/mapideas/rules/test_rules_comment.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.mapideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_mapideas.comment_mapidea' @@ -17,42 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, map_idea_factory, user): +def test_pre_phase( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, map_idea_factory, user): +def test_phase_active( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -60,19 +85,28 @@ def test_phase_active_project_private(phase_factory, map_idea_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -80,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, map_idea_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, map_idea_factory, user): +def test_phase_active_project_draft( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, map_idea_factory, user): +def test_post_phase_project_archived( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/mapideas/rules/test_rules_moderate.py b/tests/mapideas/rules/test_rules_moderate.py index cc5096ac16..811b65e68e 100644 --- a/tests/mapideas/rules/test_rules_moderate.py +++ b/tests/mapideas/rules/test_rules_moderate.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.mapideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_mapideas.moderate_mapidea' @@ -17,47 +18,69 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, map_idea_factory, user): +def test_pre_phase( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, map_idea_factory, user): +def test_phase_active( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + creator = item.creator - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -66,20 +89,28 @@ def test_phase_active_project_private(phase_factory, map_idea_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + creator = item.creator - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -88,39 +119,61 @@ def test_phase_active_project_semipublic(phase_factory, map_idea_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, map_idea_factory, user): +def test_phase_active_project_draft( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, map_idea_factory, user): +def test_post_phase_project_archived( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + creator = item.creator assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert not rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert not rules.has_perm(perm_name, admin, item) diff --git a/tests/mapideas/rules/test_rules_rate.py b/tests/mapideas/rules/test_rules_rate.py index 9e6ae84ef2..35f1be7d0b 100644 --- a/tests/mapideas/rules/test_rules_rate.py +++ b/tests/mapideas/rules/test_rules_rate.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.mapideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_mapideas.rate_mapidea' @@ -17,42 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, map_idea_factory, user): +def test_pre_phase( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.RatingPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, map_idea_factory, user): +def test_phase_active( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.RatingPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.RatingPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -60,19 +85,28 @@ def test_phase_active_project_private(phase_factory, map_idea_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.RatingPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -80,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, map_idea_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, map_idea_factory, user): +def test_phase_active_project_draft( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.RatingPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, map_idea_factory, user): +def test_post_phase_project_archived( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.RatingPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/mapideas/rules/test_rules_view.py b/tests/mapideas/rules/test_rules_view.py index d5f066216f..e1f1c0ea59 100644 --- a/tests/mapideas/rules/test_rules_view.py +++ b/tests/mapideas/rules/test_rules_view.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.mapideas import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_mapideas.view_mapidea' @@ -17,41 +18,65 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, map_idea_factory, user): +def test_pre_phase( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, map_idea_factory, user): +def test_phase_active( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.CollectPhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +84,27 @@ def test_phase_active_project_private(phase_factory, map_idea_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, map_idea_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, map_idea_factory, phases.CollectPhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +112,60 @@ def test_phase_active_project_semipublic(phase_factory, map_idea_factory, assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, map_idea_factory, user): +def test_phase_active_project_draft( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, map_idea_factory, user): +def test_post_phase_project_archived( + phase_factory, map_idea_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/maptopicprio/rules/test_rules_add.py b/tests/maptopicprio/rules/test_rules_add.py index f19259a1a3..63dab93c0f 100644 --- a/tests/maptopicprio/rules/test_rules_add.py +++ b/tests/maptopicprio/rules/test_rules_add.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.maptopicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_maptopicprio.add_maptopic' @@ -17,41 +18,58 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, user): +def test_pre_phase( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active(phase_factory, user): +def test_phase_active( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, user, user2): +def test_phase_active_project_private( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.PrioritizePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +77,25 @@ def test_phase_active_project_private(phase_factory, user, user2): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) assert not rules.has_perm(perm_name, participant, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, user, user2): +def test_phase_active_project_semipublic( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +103,53 @@ def test_phase_active_project_semipublic(phase_factory, user, user2): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) assert not rules.has_perm(perm_name, participant, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, user): +def test_phase_active_project_draft( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, user): +def test_post_phase_project_archived( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) diff --git a/tests/maptopicprio/rules/test_rules_change.py b/tests/maptopicprio/rules/test_rules_change.py index ae704fba00..26499cc8c9 100644 --- a/tests/maptopicprio/rules/test_rules_change.py +++ b/tests/maptopicprio/rules/test_rules_change.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.maptopicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_maptopicprio.change_maptopic' @@ -17,46 +18,65 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, maptopic_factory, user): +def test_pre_phase( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, maptopic_factory, user): +def test_phase_active( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, maptopic_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) creator = item.creator - participant = user2 + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -65,19 +85,26 @@ def test_phase_active_project_private(phase_factory, maptopic_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, maptopic_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) creator = item.creator - participant = user2 + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -86,39 +113,59 @@ def test_phase_active_project_semipublic(phase_factory, maptopic_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, maptopic_factory, user): +def test_phase_active_project_draft( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, maptopic_factory, user): +def test_post_phase_project_archived( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/maptopicprio/rules/test_rules_comment.py b/tests/maptopicprio/rules/test_rules_comment.py index d5ca03b81d..ceb796c14d 100644 --- a/tests/maptopicprio/rules/test_rules_comment.py +++ b/tests/maptopicprio/rules/test_rules_comment.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.maptopicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_maptopicprio.comment_maptopic' @@ -17,41 +18,65 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, maptopic_factory, user): +def test_pre_phase( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, maptopic_factory, user): +def test_phase_active( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, maptopic_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +84,27 @@ def test_phase_active_project_private(phase_factory, maptopic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, maptopic_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +112,60 @@ def test_phase_active_project_semipublic(phase_factory, maptopic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, maptopic_factory, user): +def test_phase_active_project_draft( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, maptopic_factory, user): +def test_post_phase_project_archived( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/maptopicprio/rules/test_rules_rate.py b/tests/maptopicprio/rules/test_rules_rate.py index 4ce517c2e5..f16febfe65 100644 --- a/tests/maptopicprio/rules/test_rules_rate.py +++ b/tests/maptopicprio/rules/test_rules_rate.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.maptopicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_maptopicprio.rate_maptopic' @@ -17,41 +18,65 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, maptopic_factory, user): +def test_pre_phase( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, maptopic_factory, user): +def test_phase_active( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, maptopic_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +84,27 @@ def test_phase_active_project_private(phase_factory, maptopic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, maptopic_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +112,60 @@ def test_phase_active_project_semipublic(phase_factory, maptopic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, maptopic_factory, user): +def test_phase_active_project_draft( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, maptopic_factory, user): +def test_post_phase_project_archived( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/maptopicprio/rules/test_rules_view.py b/tests/maptopicprio/rules/test_rules_view.py index d49ccbc7d6..9ff66a5a00 100644 --- a/tests/maptopicprio/rules/test_rules_view.py +++ b/tests/maptopicprio/rules/test_rules_view.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.maptopicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_maptopicprio.view_maptopic' @@ -17,41 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, maptopic_factory, user): +def test_pre_phase( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, maptopic_factory, user): +def test_phase_active( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, maptopic_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -59,18 +85,28 @@ def test_phase_active_project_private(phase_factory, maptopic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, maptopic_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -78,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, maptopic_factory, assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, maptopic_factory, user): +def test_phase_active_project_draft( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, maptopic_factory, user): +def test_post_phase_project_archived( + phase_factory, maptopic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/topicprio/rules/test_rules_add.py b/tests/topicprio/rules/test_rules_add.py index ab0933557d..6df053105f 100644 --- a/tests/topicprio/rules/test_rules_add.py +++ b/tests/topicprio/rules/test_rules_add.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.topicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_topicprio.add_topic' @@ -17,96 +18,138 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, user): +def test_pre_phase( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active(phase_factory, user): +def test_phase_active( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, user, user2): +def test_phase_active_project_private( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.PrioritizePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, participant, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, user, user2): +def test_phase_active_project_semipublic( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase( phase_factory, None, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, participant, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, user): +def test_phase_active_project_draft( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, user): +def test_post_phase_project_archived( + phase_factory, user, admin, user_factory, group_factory): phase, module, project, _ = setup_phase(phase_factory, None, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, module) assert not rules.has_perm(perm_name, user, module) + assert not rules.has_perm(perm_name, group_member_out, module) + assert not rules.has_perm(perm_name, group_member_in_org, module) + assert rules.has_perm(perm_name, group_member_in_pro, module) assert not rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module) + assert rules.has_perm(perm_name, admin, module) diff --git a/tests/topicprio/rules/test_rules_change.py b/tests/topicprio/rules/test_rules_change.py index 29443412c4..75311e6242 100644 --- a/tests/topicprio/rules/test_rules_change.py +++ b/tests/topicprio/rules/test_rules_change.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.topicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_topicprio.change_topic' @@ -17,47 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, topic_factory, user): +def test_pre_phase( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, topic_factory, user): +def test_phase_active( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, topic_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, topic_factory, phases.PrioritizePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -66,20 +86,28 @@ def test_phase_active_project_private(phase_factory, topic_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, topic_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, topic_factory, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -88,39 +116,60 @@ def test_phase_active_project_semipublic(phase_factory, topic_factory, assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) assert not rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, topic_factory, user): +def test_phase_active_project_draft( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, topic_factory, user): +def test_post_phase_project_archived( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert not rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/topicprio/rules/test_rules_comment.py b/tests/topicprio/rules/test_rules_comment.py index a387bcd426..2104d4ba0f 100644 --- a/tests/topicprio/rules/test_rules_comment.py +++ b/tests/topicprio/rules/test_rules_comment.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.topicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_topicprio.comment_topic' @@ -17,42 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, topic_factory, user): +def test_pre_phase( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, topic_factory, user): +def test_phase_active( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, topic_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, topic_factory, phases.PrioritizePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -60,19 +85,28 @@ def test_phase_active_project_private(phase_factory, topic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, topic_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, topic_factory, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -80,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, topic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, topic_factory, user): +def test_phase_active_project_draft( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, topic_factory, user): +def test_post_phase_project_archived( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/topicprio/rules/test_rules_rate.py b/tests/topicprio/rules/test_rules_rate.py index 02caa0d823..d5ec874850 100644 --- a/tests/topicprio/rules/test_rules_rate.py +++ b/tests/topicprio/rules/test_rules_rate.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.topicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_topicprio.rate_topic' @@ -17,42 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, topic_factory, user): +def test_pre_phase( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_pre_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, topic_factory, user): +def test_phase_active( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, topic_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, topic_factory, phases.PrioritizePhase, module__project__access=Access.PRIVATE) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -60,19 +85,28 @@ def test_phase_active_project_private(phase_factory, topic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, topic_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, topic_factory, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) - participant = user2 + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -80,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, topic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, topic_factory, user): +def test_phase_active_project_draft( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, topic_factory, user): +def test_post_phase_project_archived( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) diff --git a/tests/topicprio/rules/test_rules_view.py b/tests/topicprio/rules/test_rules_view.py index c699747a5d..e55e4a364b 100644 --- a/tests/topicprio/rules/test_rules_view.py +++ b/tests/topicprio/rules/test_rules_view.py @@ -8,6 +8,7 @@ from adhocracy4.test.helpers import setup_phase from adhocracy4.test.helpers import setup_users from meinberlin.apps.topicprio import phases +from meinberlin.test.helpers import setup_group_members perm_name = 'meinberlin_topicprio.view_topic' @@ -17,42 +18,66 @@ def test_perm_exists(): @pytest.mark.django_db -def test_pre_phase(phase_factory, topic_factory, user): +def test_pre_phase( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_pre_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active(phase_factory, topic_factory, user): +def test_phase_active( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.access == Access.PUBLIC with freeze_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_private(phase_factory, topic_factory, - user, user2): +def test_phase_active_project_private( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, topic_factory, phases.PrioritizePhase, module__project__access=Access.PRIVATE ) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.PRIVATE @@ -60,19 +85,28 @@ def test_phase_active_project_private(phase_factory, topic_factory, assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_semipublic(phase_factory, topic_factory, - user, user2): +def test_phase_active_project_semipublic( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase( phase_factory, topic_factory, phases.PrioritizePhase, module__project__access=Access.SEMIPUBLIC ) anonymous, moderator, initiator = setup_users(project) - participant = user2 + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) + participant = user_factory() project.participants.add(participant) assert project.access == Access.SEMIPUBLIC @@ -80,35 +114,60 @@ def test_phase_active_project_semipublic(phase_factory, topic_factory, assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) assert rules.has_perm(perm_name, participant, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_phase_active_project_draft(phase_factory, topic_factory, user): +def test_phase_active_project_draft( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase, module__project__is_draft=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_draft with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, item) assert not rules.has_perm(perm_name, user, item) + assert not rules.has_perm(perm_name, creator, item) + assert not rules.has_perm(perm_name, group_member_out, item) + assert not rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item) @pytest.mark.django_db -def test_post_phase_project_archived(phase_factory, topic_factory, user): +def test_post_phase_project_archived( + phase_factory, topic_factory, user, admin, user_factory, + group_factory): phase, _, project, item = setup_phase(phase_factory, topic_factory, phases.PrioritizePhase, module__project__is_archived=True) anonymous, moderator, initiator = setup_users(project) + creator = item.creator + project, group_member_in_org, group_member_in_pro, group_member_out = \ + setup_group_members(project, group_factory, user_factory) assert project.is_archived with freeze_post_phase(phase): assert rules.has_perm(perm_name, anonymous, item) assert rules.has_perm(perm_name, user, item) + assert rules.has_perm(perm_name, creator, item) + assert rules.has_perm(perm_name, group_member_out, item) + assert rules.has_perm(perm_name, group_member_in_org, item) + assert rules.has_perm(perm_name, group_member_in_pro, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item) + assert rules.has_perm(perm_name, admin, item)