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

Commit

Permalink
Merge f1adfef into fde6e03
Browse files Browse the repository at this point in the history
  • Loading branch information
sewagodimo committed Mar 29, 2018
2 parents fde6e03 + f1adfef commit d2f7eb4
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 4 deletions.
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
85 changes: 82 additions & 3 deletions molo/surveys/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from molo.surveys.models import (
MoloSurveyFormField,
MoloSurveyPage,
PersonalisableSurvey,
SurveysIndexPage,
PersonalisableSurveyFormField
)
from .utils import skip_logic_data

Expand All @@ -25,13 +27,16 @@ def create_molo_survey_form_field(survey, sort_order, obj):


def create_molo_survey_page(
parent, title="Test Survey", slug='test-survey', **kwargs):
parent, title="Test Survey", slug='test-survey',
thank_you_text='Thank you for taking the Test Survey',
homepage_introduction='Shorter homepage introduction',
**kwargs):
molo_survey_page = MoloSurveyPage(
title=title, slug=slug,
introduction='Introduction to Test Survey ...',
thank_you_text='Thank you for taking the Test Survey',
thank_you_text=thank_you_text,
submit_text='survey submission text',
**kwargs
homepage_introduction=homepage_introduction, **kwargs
)

parent.add_child(instance=molo_survey_page)
Expand All @@ -40,6 +45,25 @@ def create_molo_survey_page(
return molo_survey_page


def create_personalisable_survey_page(
parent, title="Test Personalisable Survey",
slug='test-personalisable-survey',
thank_you_text='Thank you for taking the Personalisable Survey',
**kwargs):
personalisable_survey_page = PersonalisableSurvey(
title=title, slug=slug,
introduction='Introduction to Test Personalisable Survey ...',
thank_you_text=thank_you_text,
submit_text='personalisable survey submission text',
**kwargs
)

parent.add_child(instance=personalisable_survey_page)
personalisable_survey_page.save_revision().publish()

return personalisable_survey_page


def create_survey(fields={}, **kwargs):
survey = create_molo_survey_page(SurveysIndexPage.objects.first())

Expand All @@ -49,3 +73,58 @@ def create_survey(fields={}, **kwargs):
sort_order = num_questions - (index + 1)
create_molo_survey_form_field(survey, sort_order, field)
return survey


def create_molo_poll(parent, **kwargs):
return create_molo_survey_page(
parent=parent,
title="Molo Survey Poll",
slug="molo-survey-poll",
display_survey_directly=True,
allow_anonymous_submissions=True,
allow_multiple_submissions_per_user=True,
thank_you_text='Thank you for taking the Molo Poll',
)


def create_personalisable_poll(parent, **kwargs):
survey = create_personalisable_survey_page(
parent=parent,
title='Personalisable Survey Poll',
slug="personalisable-survey-poll",
allow_anonymous_submissions=True,
display_survey_directly=True,
allow_multiple_submissions_per_user=True,
thank_you_text='Thank you for taking the Personalisable Poll',
)
return survey


def molo_dropddown_field(
parent, survey, choices, page_break=False,
sort_order=1, label="Is this a dropdown?", **kwargs):
return MoloSurveyFormField.objects.create(
page=survey,
sort_order=sort_order,
admin_label="is-this-a-drop-down",
label=label,
field_type='dropdown',
skip_logic=skip_logic_data(choices),
required=True,
page_break=page_break
)


def personalisable_dropddown_field(
parent, survey, choices, page_break=False,
sort_order=1, label="Is this a dropdown?", **kwargs):
return PersonalisableSurveyFormField.objects.create(
page=survey,
sort_order=sort_order,
admin_label="is-this-a-drop-down",
label=label,
field_type='dropdown',
skip_logic=skip_logic_data(choices),
required=True,
page_break=page_break
)
67 changes: 67 additions & 0 deletions molo/surveys/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
)

from .utils import skip_logic_data
from .base import (
create_molo_poll,
create_personalisable_poll,
molo_dropddown_field,
personalisable_dropddown_field
)

from .constants import SEGMENT_FORM_DATA

Expand Down Expand Up @@ -1116,3 +1122,64 @@ def test_segment_user_count_returns_errors(self):
"Select a valid choice. That choice is not one of the "
"available choices."],
"name": ["This field is required."]}})


class TestPollsViaSurveysView(TestCase, MoloTestCaseMixin):

"""
Tests to check if polls are not
being paginated when they include fields with skip_logic_data.
Also test that page_break is not causing any pagination on the surveys
"""
def setUp(self):
self.mk_main()
self.choices = ['next', 'end', 'survey']
self.surveys_index = SurveysIndexPage.objects.first()

def test_molo_poll(self):
survey = create_molo_poll(self.surveys_index)
drop_down_field = molo_dropddown_field(
self.surveys_index, survey, self.choices)
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_molo_poll_with_page_break(self):
survey = create_molo_poll(self.surveys_index)
drop_down_field = molo_dropddown_field(
self.surveys_index, survey, self.choices, 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 = create_personalisable_poll(self.surveys_index)
drop_down_field = personalisable_dropddown_field(
self.surveys_index, survey, self.choices)
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_with_page_break(self):
survey = create_personalisable_poll(self.surveys_index)
drop_down_field = personalisable_dropddown_field(
self.surveys_index, survey, self.choices, 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')

0 comments on commit d2f7eb4

Please sign in to comment.