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

Commit

Permalink
Merge branch 'release/6.7.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaitlyn Crawford committed Mar 9, 2018
2 parents bcb1e74 + ae62dcc commit b322114
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
CHANGE LOG
==========
6.7.5
-----
- Bugfix: Handle errors when testing invalid rules
- Upgrade wagtail-personalisation-molo to 0.11.3

6.7.4
-----
- Upgrade wagtail-personalisation-molo to 0.11.2
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.7.4
6.7.5
14 changes: 12 additions & 2 deletions molo/surveys/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django import forms
from django.apps import apps
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.db import models
from django.test.client import RequestFactory
from django.utils import six, timezone
Expand Down Expand Up @@ -297,7 +297,11 @@ def test_user(self, request, user=None):
if not user:
return False

submission_class = self.survey.get_submission_class()
# Django formsets don't honour 'required' fields so check rule is valid
try:
submission_class = self.survey.get_submission_class()
except ObjectDoesNotExist:
return False

return submission_class.objects.filter(
user=user,
Expand Down Expand Up @@ -463,6 +467,12 @@ def test_user(self, request, user=None):
# Return false if we don't have a user or a request
return False

# Django formsets don't honour 'required' fields so check rule is valid
try:
self.tag
except ObjectDoesNotExist:
return False

from wagtail_personalisation.adapters import get_segment_adapter
operator = self.OPERATORS[self.operator]
adapter = get_segment_adapter(request)
Expand Down
10 changes: 10 additions & 0 deletions molo/surveys/tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ def test_other_user_submitted_fails(self):
self.request.user = new_user
self.assertTrue(rule.test_user(self.request))

def test_call_test_user_on_invalid_rule_fails(self):
self.submit_survey(self.survey, self.user)
rule = SurveyResponseRule()
self.assertFalse(rule.test_user(None, self.request.user))

def test_call_test_user_without_request(self):
self.submit_survey(self.survey, self.user)
rule = SurveyResponseRule(survey=self.survey)
Expand Down Expand Up @@ -644,6 +649,11 @@ def test_visting_non_tagged_page_isnt_error(self):
self.adapter.add_page_visit(self.main)
self.assertFalse(self.request.session['tag_count'])

def test_call_test_user_on_invalid_rule_fails(self):
rule = ArticleTagRule()
self.adapter.add_page_visit(self.article)
self.assertFalse(rule.test_user(None, self.request.user))

def test_call_test_user_without_request(self):
rule = ArticleTagRule(
tag=self.tag,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ celery<4.0
dateparser>=0.7.0,<0.8.0
django-celery
wagtailsurveys==0.1.1
wagtail-personalisation-molo==0.11.2
wagtail-personalisation-molo==0.11.3
psycopg2
html5lib==0.9999999
six==1.11.0
Expand Down

0 comments on commit b322114

Please sign in to comment.