update testcode
run isort
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
# Generated by Django 2.0.7 on 2018-07-04 15:26
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Generated by Django 2.0.5 on 2018-07-19 09:57
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -1,8 +1,8 @@
|
||||
# Generated by Django 2.0.6 on 2018-08-10 14:39
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import modelcluster.fields
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -1,5 +1,4 @@
|
||||
import logging
|
||||
|
||||
import re
|
||||
from importlib import import_module
|
||||
|
||||
|
@ -5,6 +5,7 @@ from django.utils.text import slugify
|
||||
from wagtail_factories.factories import PageFactory
|
||||
|
||||
from tests.site.pages import models
|
||||
from wagtail_personalisation.models import PersonalisablePageMetadata
|
||||
|
||||
|
||||
class ContentPageFactory(PageFactory):
|
||||
@ -22,3 +23,9 @@ class RegularPageFactory(PageFactory):
|
||||
|
||||
class Meta:
|
||||
model = models.RegularPage
|
||||
|
||||
|
||||
class PersonalisablePageMetadataFactory(factory.DjangoModelFactory):
|
||||
|
||||
class Meta:
|
||||
model = PersonalisablePageMetadata
|
||||
|
@ -1,5 +1,5 @@
|
||||
from importlib.util import find_spec
|
||||
from unittest.mock import call, MagicMock, patch
|
||||
from unittest.mock import MagicMock, call, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@ -7,7 +7,6 @@ from tests.factories.rule import OriginCountryRuleFactory
|
||||
from tests.factories.segment import SegmentFactory
|
||||
from wagtail_personalisation.rules import get_geoip_module
|
||||
|
||||
|
||||
skip_if_geoip2_installed = pytest.mark.skipif(
|
||||
find_spec('geoip2'), reason='requires GeoIP2 to be not installed'
|
||||
)
|
||||
|
@ -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))
|
||||
|
@ -6,7 +6,7 @@ from wagtail.core.models import Page
|
||||
from wagtail_personalisation.models import Segment
|
||||
from wagtail_personalisation.rules import VisitCountRule
|
||||
from wagtail_personalisation.views import (
|
||||
SegmentModelDeleteView, SegmentModelAdmin)
|
||||
SegmentModelAdmin, SegmentModelDeleteView)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
@ -1,7 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from django.http import Http404
|
||||
|
||||
from wagtail.core.models import Page
|
||||
|
||||
from tests.factories.segment import SegmentFactory
|
||||
|
Reference in New Issue
Block a user