Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

removed pagination from PollsViaSurveys #103

Merged
merged 8 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion molo/surveys/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class MoloSurveyPage(
introduction = TextField(blank=True)
homepage_introduction = TextField(blank=True)
image = models.ForeignKey(

'wagtailimages.Image',
null=True,
blank=True,
Expand Down Expand Up @@ -388,7 +389,8 @@ def serve(self, request, *args, **kwargs):
self.has_user_submitted_survey(request, self.id)):
return render(request, self.template, self.get_context(request))

if self.has_page_breaks or self.multi_step:
if ((self.has_page_breaks or self.multi_step) and
not self.display_survey_directly):
return self.serve_questions(request)

if request.method == 'POST':
Expand Down
78 changes: 78 additions & 0 deletions molo/surveys/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.core.exceptions import ValidationError
from django.test import TestCase
from molo.core.tests.base import MoloTestCaseMixin
from django.test.client import Client
from molo.core.models import Languages, Main
from molo.surveys.blocks import SkipLogicBlock, SkipState
from molo.surveys.models import (
MoloSurveyFormField,
Expand Down Expand Up @@ -495,3 +497,79 @@ def test_datetime_personalisable_fields_not_clean_with_invalid_default(
field.clean()

self.assertEqual(e.exception.messages, ['Must be a valid date'])


class TestPollsViaSurveys(TestCase, MoloTestCaseMixin):
def setUp(self):
self.mk_main()
self.login()
self.client = Client()
self.main = Main.objects.all().first()
self.language_setting = Languages.objects.create(
site_id=self.main.get_site().pk)

def test_molo_survey_poll(self):
survey = MoloSurveyPage(
title='Molo Survey Poll',
slug="molo-survey-poll",
introduction='Introduction to Test Survey ...',
allow_anonymous_submissions=True,
display_survey_directly=True,
allow_multiple_submissions_per_user=True,
thank_you_text='Thank you for taking the Molo Poll',
)

SurveysIndexPage.objects.first().add_child(instance=survey)
survey.save_revision().publish()
choices = ['next', 'end', 'survey']

drop_down_field = MoloSurveyFormField.objects.create(
page=survey,
sort_order=1,
admin_label="where",
label='Where should we go?',
field_type='dropdown',
skip_logic=skip_logic_data(choices),
required=True,
page_break=True
)
response = self.client.post(
survey.url + '?p=1',
{drop_down_field.clean_name: 'next'},
follow=True,
)
self.assertContains(response, survey.thank_you_text)
self.assertNotContains(response, 'That page number is less than 1')

def test_personalisable_survey_poll(self):
survey = PersonalisableSurvey(
title='Personalisable Survey Poll',
slug="personalisable-survey-poll",
introduction='Introduction to Test Survey ...',
allow_anonymous_submissions=True,
display_survey_directly=True,
allow_multiple_submissions_per_user=True,
thank_you_text='Thank you for taking the Personalisable Poll',
)

SurveysIndexPage.objects.first().add_child(instance=survey)
survey.save_revision().publish()
choices = ['next', 'end', 'survey']

drop_down_field = PersonalisableSurveyFormField.objects.create(
page=survey,
sort_order=1,
admin_label="where",
label='Where should we go, in personsonalised style?',
field_type='dropdown',
skip_logic=skip_logic_data(choices),
required=True,
page_break=True
)
response = self.client.post(
survey.url + '?p=1',
{drop_down_field.clean_name: 'next'},
follow=True,
)
self.assertContains(response, survey.thank_you_text)
self.assertNotContains(response, 'That page number is less than 1')