7

Splits test factories and updates documentation

This commit is contained in:
Jasper Berghoef
2017-04-25 16:15:33 +02:00
parent da56a521a9
commit 6640bf8d74
8 changed files with 97 additions and 63 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ docs/_build
coverage.xml coverage.xml
db.sqlite3 db.sqlite3
.vscode/settings.json .vscode/settings.json
.DS_Store

View File

@ -2,7 +2,9 @@
Wagtail personalisation Wagtail personalisation
======================= =======================
Wagtail personalisation enables simple content personalisation through segmenting for Wagtail. Wagtail personalisation enables simple content personalisation through segmentation for the `Wagtail CMS`_.
.. _Wagtail CMS: http://wagtail.io/
Instructions Instructions
@ -24,6 +26,7 @@ Next, include the ``personalisation`` and ``wagtail.contrib.modeladmin`` app in
Make sure that ``django.contrib.sessions.middleware.SessionMiddleware`` has been added in first, this is a prerequisite for this project. Make sure that ``django.contrib.sessions.middleware.SessionMiddleware`` has been added in first, this is a prerequisite for this project.
Changing segments adapter Changing segments adapter
------------------------- -------------------------
To change the segments adapter, first make a new one based on the ``BaseSegmentsAdapter`` To change the segments adapter, first make a new one based on the ``BaseSegmentsAdapter``
@ -35,6 +38,7 @@ To change the segments adapter, first make a new one based on the ``BaseSegments
Add the ``PERSONALISATION_SEGMENTS_ADAPTER`` setting to your settings.py and choose your own adapter. Add the ``PERSONALISATION_SEGMENTS_ADAPTER`` setting to your settings.py and choose your own adapter.
Roadmap Roadmap
------------------------- -------------------------
.. image:: roadmap.png .. image:: roadmap.png

View File

@ -4,36 +4,44 @@ Usage guide
Creating a segment Creating a segment
------------------ ------------------
As soon as the installation is completed and configured, the module will be visible in the Wagtail administrative area. As soon as the installation is completed and configured, the module will be
visible in the Wagtail administrative area.
To create a segment, go to the "Segments" page. Click on "Add a new segment". To create a segment, go to the "Segments" page and click on "Add a new segment".
On this page you will be presented with a form. Follow the steps to create a segment: On this page you will be presented with a form. Follow these steps to create a
new segment:
1. Enter a name for your segment. 1. Enter a name for your segment.
2. (Optional) Select whether to match any or all defined rules. 2. (Optional) Select whether to match any or all defined rules.
``match any`` will result in a segment that is applied as soon as one of your rules matches the visitor. ``match any`` will result in a segment that is applied as soon as one of
When ``match all`` is selected, all rules must match before the segment is applied. your rules matches the visitor. When ``match all`` is selected, all rules
must match before the segment is applied.
3. (Optional) Set the segment persistence. 3. (Optional) Set the segment persistence.
When persistence is enabled, your segment will stick to the visitor once applied, even if the rules no longer match on the next visit. When persistence is enabled, your segment will stick to the visitor once
applied, even if the rules no longer match on the next visit.
4. Define your segment rules. 4. Define your segment rules.
Wagxperience comes with a basic set of rules :doc:`default_rules` that allow you to get started quickly. The rules you define will be evaluated once a visitor makes a request to your application. Wagxperience comes with a basic set of :doc:`default_rules` that allow
you to get started quickly. The rules you define will be evaluated once a
visitor makes a request to your application.
5. Save your segment. 5. Save your segment.
Click "save" to store your segment. It will be enabled by default, unless otherwise defined. Click "save" to store your segment. It will be enabled by default,
unless otherwise defined.
Creating content for your segment Creating personalized content
--------------------------------- -----------------------------
Once you've created a segment you can start serving these visitors with personalised content. To do this, you can go one of two directions. Once you've created a segment you can start serving these visitors with
personalised content. To do this, you can go one of two directions.
1. Create a copy of a page for your segment. 1. Create a copy of a page for your segment.
@ -43,13 +51,19 @@ Once you've created a segment you can start serving these visitors with personal
Method 1: Create a copy Method 1: Create a copy
^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
To create a copy from a page for a specific Segment (which you can change to your liking after copying it) simply go to the Explorer section and find the page you'd wish to personalize. To create a copy from a page for a specific Segment (which you can change to
your liking after copying it) simply go to the Explorer section and find the
page you'd wish to personalize.
You'll notice a new "Variants" dropdown button has appeared. Click the button and select the segment you'd like to create personalized content for. You'll notice a new "Variants" dropdown button has appeared. Click the button
and select the segment you'd like to create personalized content for.
Once you've selected the segment, a copy of the page will be created with a title that includes the segment. Don't worry, you'r visitors won't be able to see this title. Once you've selected the segment, a copy of the page will be created with a
title that includes the segment. Don't worry, you'r visitors won't be able to
see this title.
You can change everything on this page you'd like. Visitors that are included in your segment, will automatically see the new page you've created for them. You can change everything on this page you'd like. Visitors that are included in
your segment, will automatically see the new page you've created for them.
Method 2: Create a block Method 2: Create a block

48
tests/factories/rule.py Normal file
View File

@ -0,0 +1,48 @@
from __future__ import absolute_import, unicode_literals
import datetime
import factory
from personalisation import rules
class DayRuleFactory(factory.DjangoModelFactory):
class Meta:
model = rules.DayRule
class DeviceRuleFactory(factory.DjangoModelFactory):
class Meta:
model = rules.DeviceRule
class QueryRuleFactory(factory.DjangoModelFactory):
class Meta:
model = rules.QueryRule
class ReferralRuleFactory(factory.DjangoModelFactory):
regex_string = "test.test"
class Meta:
model = rules.ReferralRule
class TimeRuleFactory(factory.DjangoModelFactory):
start_time = datetime.time(8, 0, 0)
end_time = datetime.time(23, 0, 0)
class Meta:
model = rules.TimeRule
class VisitCountRuleFactory(factory.DjangoModelFactory):
operator = "more_than"
count = 0
class Meta:
model = rules.VisitCountRule

View File

@ -1,10 +1,8 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
import datetime
import factory import factory
from personalisation import models, rules from personalisation import models
class SegmentFactory(factory.DjangoModelFactory): class SegmentFactory(factory.DjangoModelFactory):
@ -13,43 +11,3 @@ class SegmentFactory(factory.DjangoModelFactory):
class Meta: class Meta:
model = models.Segment model = models.Segment
class TimeRuleFactory(factory.DjangoModelFactory):
start_time = datetime.time(8, 0, 0)
end_time = datetime.time(23, 0, 0)
class Meta:
model = rules.TimeRule
class DayRuleFactory(factory.DjangoModelFactory):
class Meta:
model = rules.DayRule
class ReferralRuleFactory(factory.DjangoModelFactory):
regex_string = "test.test"
class Meta:
model = rules.ReferralRule
class VisitCountRuleFactory(factory.DjangoModelFactory):
operator = "more_than"
count = 0
class Meta:
model = rules.VisitCountRule
class QueryRuleFactory(factory.DjangoModelFactory):
class Meta:
model = rules.QueryRule
class DeviceRuleFactory(factory.DjangoModelFactory):
class Meta:
model = rules.DeviceRule

View File

@ -6,8 +6,12 @@ import pytest
from personalisation.models import Segment from personalisation.models import Segment
from personalisation.rules import TimeRule from personalisation.rules import TimeRule
from tests.factories.segment import (
ReferralRuleFactory, SegmentFactory, TimeRuleFactory, DayRuleFactory, DeviceRuleFactory) from tests.factories.segment import SegmentFactory
from tests.factories.rule import (
QueryRuleFactory, ReferralRuleFactory, TimeRuleFactory,
DayRuleFactory, VisitCountRuleFactory, DeviceRuleFactory)
"""Factory tests""" """Factory tests"""
@pytest.mark.django_db @pytest.mark.django_db

View File

@ -8,8 +8,9 @@ from freezegun import freeze_time
from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.models import Page
from wagtail_factories import SiteFactory from wagtail_factories import SiteFactory
from tests.factories.segment import ( from tests.factories.segment import SegmentFactory
QueryRuleFactory, ReferralRuleFactory, SegmentFactory, TimeRuleFactory, from tests.factories.rule import (
QueryRuleFactory, ReferralRuleFactory, TimeRuleFactory,
DayRuleFactory, VisitCountRuleFactory, DeviceRuleFactory) DayRuleFactory, VisitCountRuleFactory, DeviceRuleFactory)
@ -22,11 +23,13 @@ class TestUserSegmenting(object):
""" """
self.site = SiteFactory(is_default_site=True) self.site = SiteFactory(is_default_site=True)
def test_no_segments(self, client): def test_no_segments(self, client):
request = client.get('/') request = client.get('/')
assert client.session['segments'] == [] assert client.session['segments'] == []
@freeze_time("10:00:00") @freeze_time("10:00:00")
def test_time_segment(self, client): def test_time_segment(self, client):
time_only_segment = SegmentFactory(name='Time only') time_only_segment = SegmentFactory(name='Time only')

View File

@ -2,6 +2,7 @@ import pytest
from personalisation.utils import impersonate_other_page from personalisation.utils import impersonate_other_page
class Page(object): class Page(object):
def __init__(self, path, depth, url_path, title): def __init__(self, path, depth, url_path, title):
self.path = path self.path = path
@ -12,6 +13,7 @@ class Page(object):
def __eq__(self, other): def __eq__(self, other):
return self.__dict__ == other.__dict__ return self.__dict__ == other.__dict__
def test_impersonate_other_page(): def test_impersonate_other_page():
page = Page(path="/", depth=0, url_path="/", title="Hoi") page = Page(path="/", depth=0, url_path="/", title="Hoi")
other_page = Page(path="/other", depth=1, url_path="/other", title="Doei") other_page = Page(path="/other", depth=1, url_path="/other", title="Doei")