Skip to content

Commit

Permalink
Add unittest for serving a regular page
Browse files Browse the repository at this point in the history
See #150
  • Loading branch information
mvantellingen committed Jun 2, 2017
1 parent 5aa754d commit 559d3c5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
16 changes: 12 additions & 4 deletions tests/factories/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

import factory
from django.utils.text import slugify
from wagtail_factories.factories import MP_NodeFactory
from wagtail_factories.factories import PageFactory

from tests.site.pages.models import ContentPage
from tests.site.pages import models


class ContentPageFactory(MP_NodeFactory):
class ContentPageFactory(PageFactory):
title = 'Test page'
slug = factory.LazyAttribute(lambda obj: slugify(obj.title))

class Meta:
model = ContentPage
model = models.ContentPage


class RegularPageFactory(PageFactory):
title = 'Regular page'
slug = factory.LazyAttribute(lambda obj: slugify(obj.title))

class Meta:
model = models.RegularPage
8 changes: 5 additions & 3 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.contrib.sessions.backends.db import SessionStore
from django.test.client import RequestFactory as BaseRequestFactory

from tests.factories.page import ContentPageFactory
from tests.factories.page import ContentPageFactory, RegularPageFactory
from tests.factories.segment import SegmentFactory
from tests.factories.site import SiteFactory

Expand All @@ -14,10 +14,12 @@ def site():
root_page = ContentPageFactory(parent=None, slug='')
site = SiteFactory(is_default_site=True, root_page=root_page)

page1 = ContentPageFactory(parent=site.root_page, slug='page-1')
page2 = ContentPageFactory(parent=site.root_page, slug='page-2')
page1 = ContentPageFactory(parent=root_page, slug='page-1')
page2 = ContentPageFactory(parent=root_page, slug='page-2')
ContentPageFactory(parent=page1, slug='page-1-1')
ContentPageFactory(parent=page2, slug='page-2-1')

ContentPageFactory(parent=root_page, slug='regular')
return site


Expand Down
10 changes: 10 additions & 0 deletions tests/site/pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
from wagtail_personalisation.models import PersonalisablePageMixin


class RegularPage(Page):
subtitle = models.CharField(max_length=255, blank=True, default='')
body = RichTextField(blank=True, default='')

content_panels = Page.content_panels + [
FieldPanel('subtitle'),
FieldPanel('body'),
]


class ContentPage(PersonalisablePageMixin, Page):
subtitle = models.CharField(max_length=255, blank=True, default='')
body = RichTextField(blank=True, default='')
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_regressions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest


@pytest.mark.django_db
def test_request_device_segment_no_match(client, site):
response = client.get('/regular/')
assert response.status_code == 200

0 comments on commit 559d3c5

Please sign in to comment.