-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ks 2022 11 support phase tests #4655
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
from datetime import timedelta | ||
|
||
import pytest | ||
import rules | ||
from freezegun import freeze_time | ||
|
||
from adhocracy4.projects.enums import Access | ||
from adhocracy4.test.helpers import freeze_phase | ||
from adhocracy4.test.helpers import freeze_post_phase | ||
from adhocracy4.test.helpers import freeze_pre_phase | ||
from adhocracy4.test.helpers import setup_phase | ||
from adhocracy4.test.helpers import setup_users | ||
from meinberlin.apps.budgeting import phases | ||
|
||
perm_name = 'meinberlin_budgeting.support_proposal' | ||
|
||
|
||
def test_perm_exists(): | ||
assert rules.perm_exists(perm_name) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_pre_phase(phase_factory, proposal_factory, user, admin): | ||
phase, module, project, item = setup_phase(phase_factory, proposal_factory, | ||
phases.RequestPhase) | ||
anonymous, moderator, initiator = setup_users(project) | ||
|
||
assert project.access == Access.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 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_support_phase_active(phase_factory, proposal_factory, user, admin): | ||
phase, module, project, item = setup_phase(phase_factory, proposal_factory, | ||
phases.SupportPhase) | ||
anonymous, moderator, initiator = setup_users(project) | ||
|
||
assert project.access == Access.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, moderator, item) | ||
assert rules.has_perm(perm_name, initiator, item) | ||
assert rules.has_perm(perm_name, admin, item) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_between_support_and_voting_phase(phase_factory, proposal_factory, | ||
user, admin): | ||
support_phase, module, project, item = setup_phase(phase_factory, | ||
proposal_factory, | ||
phases.SupportPhase) | ||
phase_factory( | ||
phase_content=phases.VotingPhase, | ||
module=module, | ||
start_date=support_phase.end_date + timedelta(hours=2), | ||
end_date=support_phase.end_date + timedelta(hours=3), | ||
type='meinberlin_budgeting:voting' | ||
) | ||
between_phases = support_phase.end_date + timedelta(hours=1) | ||
|
||
anonymous, moderator, initiator = setup_users(project) | ||
|
||
assert project.access == Access.PUBLIC | ||
with freeze_time(between_phases): | ||
assert not rules.has_perm(perm_name, anonymous, item) | ||
assert not rules.has_perm(perm_name, user, 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_voting_phase_active(phase_factory, proposal_factory, user, admin): | ||
phase, module, project, item = setup_phase(phase_factory, proposal_factory, | ||
phases.VotingPhase) | ||
anonymous, moderator, initiator = setup_users(project) | ||
|
||
assert project.access == Access.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, moderator, item) | ||
assert rules.has_perm(perm_name, initiator, item) | ||
assert rules.has_perm(perm_name, admin, item) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_rating_phase_active(phase_factory, proposal_factory, user, admin): | ||
phase, module, project, item = setup_phase(phase_factory, proposal_factory, | ||
phases.RatingPhase) | ||
anonymous, moderator, initiator = setup_users(project) | ||
|
||
assert project.access == Access.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, 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, admin): | ||
phase, _, project, item = setup_phase( | ||
phase_factory, proposal_factory, phases.SupportPhase, | ||
module__project__access=Access.PRIVATE) | ||
anonymous, moderator, initiator = setup_users(project) | ||
|
||
participant = user2 | ||
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 rules.has_perm(perm_name, participant, 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, admin): | ||
phase, _, project, item = setup_phase( | ||
phase_factory, proposal_factory, phases.SupportPhase, | ||
module__project__access=Access.SEMIPUBLIC) | ||
anonymous, moderator, initiator = setup_users(project) | ||
|
||
participant = user2 | ||
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 rules.has_perm(perm_name, participant, 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, admin): | ||
phase, _, project, item = setup_phase(phase_factory, proposal_factory, | ||
phases.SupportPhase, | ||
module__project__is_draft=True) | ||
anonymous, moderator, initiator = setup_users(project) | ||
|
||
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 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, admin): | ||
phase, _, project, item = setup_phase(phase_factory, proposal_factory, | ||
phases.SupportPhase, | ||
module__project__is_archived=True) | ||
anonymous, moderator, initiator = setup_users(project) | ||
|
||
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 rules.has_perm(perm_name, moderator, item) | ||
assert rules.has_perm(perm_name, initiator, item) | ||
assert rules.has_perm(perm_name, admin, item) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think this was missing, right? Now moderators, initiators, group members should have more permissions...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!