-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/moderation: add tests for budgeting moderation form
- Loading branch information
1 parent
1701030
commit 4a2367d
Showing
2 changed files
with
39 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
from pytest_factoryboy import register | ||
|
||
from meinberlin.test.factories.budgeting import ProposalFactory | ||
|
||
from .factories import ModerationTaskFactory | ||
|
||
register(ModerationTaskFactory) | ||
register(ProposalFactory) |
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,36 @@ | ||
import pytest | ||
from django import forms | ||
|
||
from meinberlin.apps.budgeting.models import Proposal | ||
from meinberlin.apps.moderationtasks.mixins import TasksAddableFieldMixin | ||
|
||
|
||
class TaskForm(TasksAddableFieldMixin, forms.ModelForm): | ||
|
||
class Meta: | ||
model = Proposal | ||
fields = ['completed_tasks'] | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_choice(module, moderation_task_factory, proposal_factory): | ||
task1 = moderation_task_factory(module=module) | ||
task2 = moderation_task_factory() | ||
proposal = proposal_factory(module=module) | ||
|
||
form = TaskForm(instance=proposal) | ||
choice = form.fields['completed_tasks'].queryset.all() | ||
assert task1 in choice | ||
assert task2 not in choice | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_show_labels(module, moderation_task_factory, proposal_factory): | ||
proposal = proposal_factory(module=module) | ||
moderation_task_factory() | ||
form = TaskForm(instance=proposal) | ||
assert not form.show_tasks() | ||
|
||
moderation_task_factory(module=module) | ||
form = TaskForm(instance=proposal) | ||
assert form.show_tasks() |