update testcode
run isort
This commit is contained in:
@ -1,16 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from django.test import override_settings
|
||||
|
||||
from tests.factories.page import ContentPageFactory
|
||||
from wagtail.core.models import Page as WagtailPage
|
||||
|
||||
from tests.factories.page import (
|
||||
ContentPageFactory, PersonalisablePageMetadataFactory)
|
||||
from wagtail_personalisation.utils import (
|
||||
can_delete_pages, get_client_ip, impersonate_other_page, exclude_variants)
|
||||
|
||||
|
||||
class Metadata:
|
||||
def __init__(self, is_canonical=True):
|
||||
self.is_canonical = is_canonical
|
||||
can_delete_pages, exclude_variants, get_client_ip, impersonate_other_page)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -77,13 +72,13 @@ def test_exclude_variants_with_pages_querysets():
|
||||
Test that excludes variant works for querysets
|
||||
'''
|
||||
for i in range(5):
|
||||
page = WagtailPage(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||
page = ContentPageFactory(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||
page.save()
|
||||
pages = WagtailPage.objects.all().order_by('id')
|
||||
pages = WagtailPage.objects.all().specific().order_by('id')
|
||||
|
||||
result = exclude_variants(pages)
|
||||
assert type(result) == type(pages)
|
||||
assert result == pages
|
||||
assert set(result.values_list('pk', flat=True)) == set(pages.values_list('pk', flat=True))
|
||||
|
||||
|
||||
def test_exclude_variants_with_pages_querysets_not_canonical():
|
||||
@ -92,17 +87,19 @@ def test_exclude_variants_with_pages_querysets_not_canonical():
|
||||
personalisation_metadata canonical False
|
||||
'''
|
||||
for i in range(5):
|
||||
page = WagtailPage(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||
page = ContentPageFactory(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||
page.save()
|
||||
pages = WagtailPage.objects.all().order_by('id')
|
||||
pages = WagtailPage.objects.all().specific().order_by('id')
|
||||
# add variants
|
||||
for page in pages:
|
||||
page.personalisation_metadata = Metadata(is_canonical=False)
|
||||
variant = ContentPageFactory(title='variant %d' % page.pk)
|
||||
page.personalisation_metadata = PersonalisablePageMetadataFactory(canonical_page=page, variant=variant)
|
||||
page.save()
|
||||
|
||||
pages = WagtailPage.objects.all().specific()
|
||||
result = exclude_variants(pages)
|
||||
assert type(result) == type(pages)
|
||||
assert result.count() == 0
|
||||
assert result.count() < pages.count()
|
||||
|
||||
|
||||
def test_exclude_variants_with_pages_querysets_meta_none():
|
||||
@ -110,14 +107,15 @@ def test_exclude_variants_with_pages_querysets_meta_none():
|
||||
Test that excludes variant works for querysets with meta as none
|
||||
'''
|
||||
for i in range(5):
|
||||
page = WagtailPage(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||
page = ContentPageFactory(path="/" + str(i), depth=0, url_path="/", title="Hoi " + str(i))
|
||||
page.save()
|
||||
pages = WagtailPage.objects.all().order_by('id')
|
||||
pages = WagtailPage.objects.all().specific().order_by('id')
|
||||
# add variants
|
||||
for page in pages:
|
||||
page.personalisation_metadata = None
|
||||
page.personalisation_metadata = PersonalisablePageMetadataFactory(canonical_page=page, variant=page)
|
||||
page.save()
|
||||
|
||||
pages = WagtailPage.objects.all().specific()
|
||||
result = exclude_variants(pages)
|
||||
assert type(result) == type(pages)
|
||||
assert result == pages
|
||||
assert set(result.values_list('pk', flat=True)) == set(pages.values_list('pk', flat=True))
|
||||
|
Reference in New Issue
Block a user