Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions src/wagtail_personalisation/migrations/0010_auto_20170531_1522.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration needs to be given a name

# Generated by Django 1.11.1 on 2017-05-31 15:22
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('wagtail_personalisation', '0009_auto_20170531_0428'),
]

operations = [
migrations.AlterField(
model_name='referralrule',
name='regex_string',
field=models.TextField(help_text='Enter the domain name (like google.com) or a regular expression to match the referrer', verbose_name='Referral'),
),
]
4 changes: 3 additions & 1 deletion src/wagtail_personalisation/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ class ReferralRule(AbstractBaseRule):

"""
regex_string = models.TextField(
_("Regular expression to match the referrer"))
_("Referral"), help_text=_("Enter the domain name (like google.com) "
Copy link

@kaedroho kaedroho May 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The . characters in domain names may be misinterpreted if the value of this field is still going to be interpreted as a regex.

"or a regular expression to match the "
"referrer"))

panels = [
FieldPanel('regex_string'),
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ def test_referral_segment(self, client):

assert client.session['segments'][0]['encoded_name'] == 'referral'

def test_referral_segment_matches_domain(self, client):
referral_segment = SegmentFactory(name='Referral')
ReferralRuleFactory(
regex_string="google.com",
segment=referral_segment
)

client.get('/', **{'HTTP_REFERER': 'https://www.google.com/?q=wagtail'})

assert client.session['segments'][0]['encoded_name'] == 'referral'

@freeze_time("10:00:00")
def test_time_and_referral_segment(self, client):
segment = SegmentFactory(name='Both')
Expand Down