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

Commit

Permalink
Merge ce49241 into 353f1d4
Browse files Browse the repository at this point in the history
  • Loading branch information
moh-moola committed Jul 24, 2018
2 parents 353f1d4 + ce49241 commit e284006
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
5 changes: 4 additions & 1 deletion molo/surveys/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

import json
import datetime
from unidecode import unidecode
Expand All @@ -15,6 +17,7 @@
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from django.utils.text import slugify
from django.utils.encoding import smart_str
from django.utils.six import text_type
from modelcluster.fields import ParentalKey
from molo.core.blocks import MarkDownBlock
Expand Down Expand Up @@ -80,7 +83,7 @@ class Meta:
@property
def clean_name(self):
return str(slugify(text_type(unidecode(
'{} {}'.format(self.pk, self.label.lower())))))
u'{} {}'.format(self.pk, smart_str(self.label))))))


class TermsAndConditionsIndexPage(TranslatablePageMixinNotRoutable, MoloPage):
Expand Down
33 changes: 31 additions & 2 deletions molo/surveys/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# -*- coding: utf-8 -*-

from django.core.exceptions import ValidationError
from django.test import TestCase
from molo.core.tests.base import MoloTestCaseMixin
from molo.surveys.blocks import SkipLogicBlock, SkipState
from django.contrib.auth import get_user_model
from molo.surveys.models import (
MoloSurveyFormField,
MoloSurveyPage,
ArticlePage,
MoloSurveyPageView,
MoloSurveySubmission,
SurveysIndexPage,
PersonalisableSurvey,
Expand Down Expand Up @@ -408,7 +413,8 @@ def create_molo_survey_form_field(self, field_type):
admin_label="birthday",
)

def create_personalisable_survey_form_field(self, field_type):
def create_personalisable_survey_form_field(
self, field_type, label="When is your birthday"):
survey = PersonalisableSurvey(
title='Test Survey',
introduction='Introduction to Test Survey ...',
Expand All @@ -419,7 +425,7 @@ def create_personalisable_survey_form_field(self, field_type):

return PersonalisableSurveyFormField.objects.create(
page=survey,
label="When is your birthday",
label=label,
field_type=field_type,
admin_label="birthday",
)
Expand Down Expand Up @@ -472,6 +478,15 @@ def test_datetime_molo_form_fields_not_clean_with_invalid_default(self):

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

def test_date_personalisabe_form_str_representation(self):
field = self.create_personalisable_survey_form_field(
'date', label="When is your birthdáy")

self.assertTrue(
'Test Survey - When is your birthd' in
field.__str__()
)

def test_date_personalisabe_form_fields_clean_if_blank(self):
field = self.create_personalisable_survey_form_field('date')
field.default_value = ""
Expand Down Expand Up @@ -520,3 +535,17 @@ def test_datetime_personalisable_fields_not_clean_with_invalid_default(
field.clean()

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


class TestMoloSurveyPageView(TestCase, MoloTestCaseMixin):
""" Test case """

def test_model(self):
self.mk_main()
user = get_user_model().objects.create_superuser(
username='superuser',
email='superuser@email.com', password='pass'
)
survey = ArticlePage(title='Test Survey', slug='test-survey')
model = MoloSurveyPageView(user=user, page=survey)
self.assertTrue('superuser viewed Test Survey at' in model.__str__())

0 comments on commit e284006

Please sign in to comment.