def test_user_can_create_idea_during_active_phase(client, phase_factory, user, category_factory): phase = phase_factory(phase_content=phases.IssuePhase()) module = phase.module category = category_factory(module=module) url = reverse('meinberlin_ideas:idea-create', kwargs={'module_slug': module.slug}) with freeze_phase(phase): count = models.Idea.objects.all().count() assert count == 0 client.login(username=user.email, password='******') response = client.get(url) assert_template_response(response, 'meinberlin_ideas/idea_create_form.html') assert response.status_code == 200 idea = { 'name': 'Idea', 'description': 'description', 'category': category.pk, } response = client.post(url, idea) assert response.status_code == 302 assert redirect_target(response) == 'idea-detail' count = models.Idea.objects.all().count() assert count == 1
def test_moderator_can_update_during_wrong_phase(client, phase_factory, map_idea_factory, category_factory, area_settings_factory): phase, module, project, mapidea = setup_phase( phase_factory, map_idea_factory, phases.RatingPhase) area_settings_factory(module=module) category = category_factory(module=module) user = mapidea.creator moderator = project.moderators.first() assert moderator is not user url = reverse( 'meinberlin_mapideas:mapidea-update', kwargs={ 'pk': mapidea.pk, 'year': mapidea.created.year }) with freeze_phase(phase): client.login(username=moderator.email, password='******') data = { 'name': 'Another MapIdea', 'description': 'changed description', 'category': category.pk, 'point': (0, 0), 'point_label': 'somewhere else' } response = client.post(url, data) assert redirect_target(response) == 'mapidea-detail' assert response.status_code == 302 updated_mapidea = models.MapIdea.objects.get(id=mapidea.pk) assert updated_mapidea.description == 'changed description'
def test_create_view(client, phase_factory, proposal_factory, user, category_factory, area_settings_factory): phase, module, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase) area_settings_factory(module=module) category = category_factory(module=module) url = reverse('meinberlin_budgeting:proposal-create', kwargs={'module_slug': module.slug}) with freeze_phase(phase): client.login(username=user.email, password='******') response = client.get(url) assert_template_response( response, 'meinberlin_budgeting/proposal_create_form.html') data = { 'name': 'Idea', 'description': 'description', 'category': category.pk, 'budget': 123, 'point': (0, 0), 'point_label': 'somewhere' } response = client.post(url, data) assert redirect_target(response) == 'proposal-detail'
def test_admin_can_create_maptopic(client, phase_factory, category_factory, admin, area_settings_factory): phase = phase_factory(phase_content=phases.PrioritizePhase()) module = phase.module area_settings_factory(module=module) category = category_factory(module=module) url = reverse('a4dashboard:maptopic-create', kwargs={'module_slug': module.slug}) with freeze_phase(phase): client.login(username=admin.email, password='******') response = client.get(url) assert_template_response( response, 'meinberlin_maptopicprio/maptopic_create_form.html') assert response.status_code == 200 maptopic = { 'name': 'MapTopic', 'description': 'description', 'category': category.pk, 'point': (0, 0), 'point_label': 'somewhere' } response = client.post(url, maptopic) assert response.status_code == 302 assert redirect_target(response) == 'maptopic-list' count = models.MapTopic.objects.all().count() assert count == 1
def test_creator_can_update_during_active_phase(client, phase_factory, idea_factory, category_factory): phase, module, project, idea = setup_phase( phase_factory, idea_factory, phases.IssuePhase) category = category_factory(module=module) user = idea.creator url = reverse( 'meinberlin_ideas:idea-update', kwargs={ 'pk': idea.pk, 'year': idea.created.year }) with freeze_phase(phase): client.login(username=user.email, password='******') data = { 'name': 'Another Idea', 'description': 'changed description', 'category': category.pk, } response = client.post(url, data) assert redirect_target(response) == 'idea-detail' assert response.status_code == 302 updated_idea = models.Idea.objects.get(id=idea.pk) assert updated_idea.description == 'changed description'
def test_admin_can_create_mapidea_in_wrong_phase(client, phase_factory, admin, category_factory, area_settings_factory): phase = phase_factory(phase_content=phases.RatingPhase()) module = phase.module area_settings_factory(module=module) category = category_factory(module=module) url = reverse('meinberlin_mapideas:mapidea-create', kwargs={'module_slug': module.slug}) with freeze_phase(phase): client.login(username=admin.email, password='******') response = client.get(url) assert_template_response( response, 'meinberlin_mapideas/mapidea_create_form.html') assert response.status_code == 200 mapidea = { 'name': 'MapIdea', 'description': 'description', 'category': category.pk, 'point': (0, 0), 'point_label': 'somewhere' } response = client.post(url, mapidea) assert response.status_code == 302 assert redirect_target(response) == 'mapidea-detail' count = models.MapIdea.objects.all().count() assert count == 1
def test_detail_view(client, phase_factory, proposal_factory): phase, module, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase) url = item.get_absolute_url() with freeze_phase(phase): response = client.get(url) assert_template_response( response, 'meinberlin_budgeting/proposal_detail.html')
def test_document_detail_view(client, phase_factory, chapter_factory): phase, module, project, item = setup_phase(phase_factory, chapter_factory, phases.CommentPhase) url = project.get_absolute_url() with freeze_phase(phase): response = client.get(url) assert_template_response(response, 'meinberlin_documents/chapter_detail.html')
def test_list_view(client, phase_factory, proposal_factory): phase, module, project, item = setup_phase( phase_factory, proposal_factory, phases.RequestPhase) url = project.get_absolute_url() with freeze_phase(phase): response = client.get(url) assert_template_response( response, 'meinberlin_kiezkasse/proposal_list.html')
def test_detail_view(client, phase_factory, idea_factory): phase, module, project, idea = setup_phase(phase_factory, idea_factory, phases.FeedbackPhase) url = idea.get_absolute_url() with freeze_phase(phase): response = client.get(url) assert_template_response(response, 'meinberlin_ideas/idea_detail.html') assert response.status_code == 200
def test_detail_view(client, phase_factory, topic_factory): phase, module, project, topic = setup_phase( phase_factory, topic_factory, phases.PrioritizePhase) url = topic.get_absolute_url() with freeze_phase(phase): response = client.get(url) assert_template_response( response, 'meinberlin_topicprio/topic_detail.html') assert response.status_code == 200
def test_detail_view(client, phase_factory, poll_factory, question_factory, choice_factory): phase, module, project, item = setup_phase(phase_factory, poll_factory, phases.VotingPhase) question = question_factory(poll=item) choice_factory(question=question) url = project.get_absolute_url() with freeze_phase(phase): response = client.get(url) assert_template_response(response, 'meinberlin_polls/poll_detail.html')
def test_user_cannot_create_idea_in_wrong_phase(client, phase_factory, user): phase = phase_factory(phase_content=phases.RatingPhase()) module = phase.module url = reverse('meinberlin_ideas:idea-create', kwargs={'module_slug': module.slug}) with freeze_phase(phase): response = client.get(url) assert response.status_code == 302 client.login(username=user.email, password='******') response = client.get(url) assert response.status_code == 403
def test_anonymous_cannot_create_idea(client, phase_factory): phase = phase_factory(phase_content=phases.IssuePhase()) module = phase.module url = reverse('meinberlin_ideas:idea-create', kwargs={'module_slug': module.slug}) with freeze_phase(phase): count = models.Idea.objects.all().count() assert count == 0 response = client.get(url) assert response.status_code == 302 assert redirect_target(response) == 'account_login'
def test_phase_active(phase_factory, map_idea_factory, user): phase, _, project, item = setup_phase(phase_factory, map_idea_factory, phases.CollectPhase) anonymous, moderator, initiator = setup_users(project) 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, moderator, item) assert rules.has_perm(perm_name, initiator, item)
def test_anonymous_cannot_create_maptopic(client, phase_factory): phase = phase_factory(phase_content=phases.PrioritizePhase()) module = phase.module url = reverse('a4dashboard:maptopic-create', kwargs={'module_slug': module.slug}) with freeze_phase(phase): count = models.MapTopic.objects.all().count() assert count == 0 response = client.get(url) assert response.status_code == 302 assert redirect_target(response) == 'account_login'
def test_user_cannot_create_maptopic(client, phase_factory, user): phase = phase_factory(phase_content=phases.PrioritizePhase()) module = phase.module url = reverse('a4dashboard:maptopic-create', kwargs={'module_slug': module.slug}) with freeze_phase(phase): response = client.get(url) assert response.status_code == 302 client.login(username=user.email, password='******') response = client.get(url) assert response.status_code == 403
def test_phase_active(phase_factory, user): phase, module, project, _ = setup_phase(phase_factory, None, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) assert project.is_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, moderator, module) assert rules.has_perm(perm_name, initiator, module)
def setup_mapidea_moderation(): phase, module, project, item = setup_phase(PhaseFactory, MapIdeaFactory, phases.FeedbackPhase) anonymous, moderator, initiator = setup_users(project) with freeze_phase(phase): url = reverse('meinberlin_mapideas:mapidea-moderate', kwargs={ 'pk': item.pk, 'year': item.created.year }) return anonymous, moderator, initiator, url
def test_phase_active(phase_factory, chapter_factory, paragraph_factory, user): phase, _, project, item = setup_phase(phase_factory, chapter_factory, phases.CommentPhase) anonymous, moderator, initiator = setup_users(project) paragraph = paragraph_factory(chapter=item) assert project.is_public 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, moderator, paragraph) assert rules.has_perm(perm_name, initiator, paragraph)
def test_phase_active_project_draft(phase_factory, idea_factory, user): phase, _, project, item = setup_phase(phase_factory, idea_factory, phases.RatingPhase, 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)
def test_phase_active_project_draft(phase_factory, user): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase, 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, module) assert not rules.has_perm(perm_name, user, module) assert rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module)
def test_phase_active(phase_factory, poll_factory, question, choice, vote, user): phase, module, project, _ = setup_phase(phase_factory, poll_factory, phases.VotingPhase) anonymous, moderator, initiator = setup_users(project) assert project.is_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, moderator, module) assert rules.has_perm(perm_name, initiator, module)
def test_phase_active(phase_factory, proposal_factory, user): phase, _, project, item = setup_phase(phase_factory, proposal_factory, phases.RequestPhase) anonymous, moderator, initiator = setup_users(project) 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 rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item)
def test_phase_active_project_draft(phase_factory, topic_factory, user): 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 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 rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item)
def test_creator_cannot_delete_in_wrong_phase(client, phase_factory, idea_factory): phase, module, project, idea = setup_phase(phase_factory, idea_factory, phases.RatingPhase) url = reverse('meinberlin_ideas:idea-delete', kwargs={ 'pk': idea.pk, 'year': idea.created.year }) with freeze_phase(phase): count = models.Idea.objects.all().count() assert count == 1 client.login(username=idea.creator.email, password='******') response = client.get(url) assert response.status_code == 403
def test_phase_active_project_private(phase_factory, user, user2): phase, module, project, _ = setup_phase(phase_factory, None, phases.CollectPhase, module__project__is_public=False) anonymous, moderator, initiator = setup_users(project) participant = user2 project.participants.add(participant) assert not project.is_public with freeze_phase(phase): 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 rules.has_perm(perm_name, moderator, module) assert rules.has_perm(perm_name, initiator, module)
def test_phase_active_project_private(phase_factory, maptopic_factory, user, user2): phase, _, project, item = setup_phase(phase_factory, maptopic_factory, phases.PrioritizePhase, module__project__is_public=False) anonymous, moderator, initiator = setup_users(project) participant = user2 project.participants.add(participant) assert not 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, participant, item) assert rules.has_perm(perm_name, moderator, item) assert rules.has_perm(perm_name, initiator, item)
def test_phase_active_project_private(phase_factory, chapter_factory, paragraph_factory, user, user2): phase, _, project, item = setup_phase(phase_factory, chapter_factory, phases.CommentPhase, module__project__is_public=False) anonymous, moderator, initiator = setup_users(project) participant = user2 project.participants.add(participant) paragraph = paragraph_factory(chapter=item) assert not project.is_public with freeze_phase(phase): assert not rules.has_perm(perm_name, anonymous, paragraph) assert not rules.has_perm(perm_name, user, paragraph) assert rules.has_perm(perm_name, participant, paragraph) assert rules.has_perm(perm_name, moderator, paragraph) assert rules.has_perm(perm_name, initiator, paragraph)
def test_list_view(client, phase_factory, idea_factory): phase, module, project, idea = setup_phase(phase_factory, idea_factory, phases.FeedbackPhase) phase_2, module_2, project_2, idea_2 = setup_phase(phase_factory, idea_factory, phases.FeedbackPhase) url = project.get_absolute_url() with freeze_phase(phase): response = client.get(url) assert_template_response(response, 'meinberlin_ideas/idea_list.html') assert response.status_code == 200 assert idea in response.context_data['idea_list'] assert idea_2 not in response.context_data['idea_list'] assert response.context_data['idea_list'][0].comment_count == 0 assert response.context_data['idea_list'][0].positive_rating_count == 0 assert response.context_data['idea_list'][0].negative_rating_count == 0