Skip to content

Commit

Permalink
Add more tests for wagtail_hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mvantellingen committed Jun 2, 2017
1 parent 559d3c5 commit 6f96f2f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/wagtail_personalisation/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def page_listing_more_buttons(page, page_perms, is_parent=False):
if not isinstance(page, models.PersonalisablePageMixin):
return

metadata = page.personalisable_metadata
metadata = page.personalisation_metadata
for segment in metadata.get_unused_segments():
yield Button(segment.name,
reverse('segment:copy_page', args=[page.pk, segment.pk]),
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def site():
ContentPageFactory(parent=page1, slug='page-1-1')
ContentPageFactory(parent=page2, slug='page-2-1')

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


Expand Down
1 change: 1 addition & 0 deletions tests/site/templates/pages/regular_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "base.html" %}
21 changes: 21 additions & 0 deletions tests/unit/test_wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from tests.factories.segment import SegmentFactory
from wagtail_personalisation import adapters, wagtail_hooks


Expand Down Expand Up @@ -39,3 +40,23 @@ def test_serve_variation_with_variant_segmented(site, rf, segmented_page):

result = wagtail_hooks.serve_variation(page, request, args, kwargs)
assert result.status_code == 200


@pytest.mark.django_db
def test_page_listing_variant_buttons(site, rf, segmented_page):
page = segmented_page.personalisation_metadata.canonical_page

SegmentFactory(name='something')
result = wagtail_hooks.page_listing_variant_buttons(page, [])
items = list(result)
assert len(items) == 1


@pytest.mark.django_db
def test_page_listing_more_buttons(site, rf, segmented_page):
page = segmented_page.personalisation_metadata.canonical_page

SegmentFactory(name='something')
result = wagtail_hooks.page_listing_more_buttons(page, [])
items = list(result)
assert len(items) == 2

0 comments on commit 6f96f2f

Please sign in to comment.