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

Commit

Permalink
Merge d189071 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 + d189071 commit 52f4645
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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_unicode
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_unicode(self.label))))))


class TermsAndConditionsIndexPage(TranslatablePageMixinNotRoutable, MoloPage):
Expand Down
22 changes: 22 additions & 0 deletions molo/surveys/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
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 @@ -472,6 +475,11 @@ 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')
self.assertEqual(
field.__str__(), 'Test Survey - When is your birthday')

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 +528,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 52f4645

Please sign in to comment.