Enable and fix lint
This commit is contained in:
@ -4,6 +4,9 @@ language: python
|
|||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
|
- python: 2.7
|
||||||
|
env: lint
|
||||||
|
|
||||||
- python: 2.7
|
- python: 2.7
|
||||||
env: TOXENV=py27-django111-wagtail113
|
env: TOXENV=py27-django111-wagtail113
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
from wagtail_personalisation.models import Segment
|
from wagtail_personalisation.models import Segment
|
||||||
from wagtail_personalisation.rules import AbstractBaseRule
|
from wagtail_personalisation.rules import AbstractBaseRule
|
||||||
|
@ -8,15 +8,11 @@ from django.contrib.auth import get_user_model
|
|||||||
from django.contrib.auth.models import AnonymousUser
|
from django.contrib.auth.models import AnonymousUser
|
||||||
from django.contrib.sessions.models import Session
|
from django.contrib.sessions.models import Session
|
||||||
from django.contrib.staticfiles.templatetags.staticfiles import static
|
from django.contrib.staticfiles.templatetags.staticfiles import static
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from django.utils import timezone
|
|
||||||
from django.utils.lru_cache import lru_cache
|
from django.utils.lru_cache import lru_cache
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from wagtail.wagtailadmin.forms import WagtailAdminModelForm
|
from wagtail.wagtailadmin.forms import WagtailAdminModelForm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
|
SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +25,6 @@ def user_from_data(user_id):
|
|||||||
return AnonymousUser()
|
return AnonymousUser()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SegmentAdminForm(WagtailAdminModelForm):
|
class SegmentAdminForm(WagtailAdminModelForm):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = super(SegmentAdminForm, self).clean()
|
cleaned_data = super(SegmentAdminForm, self).clean()
|
||||||
@ -62,7 +57,6 @@ class SegmentAdminForm(WagtailAdminModelForm):
|
|||||||
if field not in excluded:
|
if field not in excluded:
|
||||||
form.add_error(field, _('Cannot update a static segment'))
|
form.add_error(field, _('Cannot update a static segment'))
|
||||||
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
is_new = not self.instance.id
|
is_new = not self.instance.id
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
# Generated by Django 1.11.1 on 2017-05-31 14:28
|
# Generated by Django 1.11.1 on 2017-05-31 14:28
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -2,7 +2,6 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.sessions.models import Session
|
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
@ -11,11 +10,7 @@ from django.utils.safestring import mark_safe
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from modelcluster.models import ClusterableModel
|
from modelcluster.models import ClusterableModel
|
||||||
from wagtail.wagtailadmin.edit_handlers import (
|
from wagtail.wagtailadmin.edit_handlers import (
|
||||||
FieldPanel,
|
FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel)
|
||||||
FieldRowPanel,
|
|
||||||
InlinePanel,
|
|
||||||
MultiFieldPanel,
|
|
||||||
)
|
|
||||||
from wagtail.wagtailcore.models import Page
|
from wagtail.wagtailcore.models import Page
|
||||||
|
|
||||||
from wagtail_personalisation.rules import AbstractBaseRule
|
from wagtail_personalisation.rules import AbstractBaseRule
|
||||||
|
@ -103,9 +103,17 @@ def exclude_variants(pages):
|
|||||||
:return: List of pages that aren't variants
|
:return: List of pages that aren't variants
|
||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
return [page for page in pages
|
return [
|
||||||
if (hasattr(page, 'personalisation_metadata') is False)
|
page for page in pages
|
||||||
or (hasattr(page, 'personalisation_metadata')
|
if (
|
||||||
and page.personalisation_metadata is None)
|
(
|
||||||
or (hasattr(page, 'personalisation_metadata')
|
hasattr(page, 'personalisation_metadata') is False
|
||||||
and page.personalisation_metadata.is_canonical)]
|
) or
|
||||||
|
(
|
||||||
|
hasattr(page, 'personalisation_metadata') and page.personalisation_metadata is None
|
||||||
|
) or
|
||||||
|
(
|
||||||
|
hasattr(page, 'personalisation_metadata') and page.personalisation_metadata.is_canonical
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse
|
|||||||
from django.template.defaultfilters import pluralize
|
from django.template.defaultfilters import pluralize
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from wagtail.wagtailadmin.site_summary import SummaryItem, PagesSummaryItem
|
from wagtail.wagtailadmin.site_summary import PagesSummaryItem, SummaryItem
|
||||||
from wagtail.wagtailadmin.widgets import Button, ButtonWithDropdownFromHook
|
from wagtail.wagtailadmin.widgets import Button, ButtonWithDropdownFromHook
|
||||||
from wagtail.wagtailcore import hooks
|
from wagtail.wagtailcore import hooks
|
||||||
from wagtail.wagtailcore.models import Page
|
from wagtail.wagtailcore.models import Page
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pkg_resources import parse_version as V
|
|
||||||
|
|
||||||
import django
|
import django
|
||||||
|
from pkg_resources import parse_version as V
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
@ -56,6 +55,7 @@ TEMPLATES = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_middleware_settings():
|
def get_middleware_settings():
|
||||||
return (
|
return (
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
@ -69,6 +69,7 @@ def get_middleware_settings():
|
|||||||
'wagtail.wagtailcore.middleware.SiteMiddleware',
|
'wagtail.wagtailcore.middleware.SiteMiddleware',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Django 1.10 started to use "MIDDLEWARE" instead of "MIDDLEWARE_CLASSES".
|
# Django 1.10 started to use "MIDDLEWARE" instead of "MIDDLEWARE_CLASSES".
|
||||||
if V(django.get_version()) < V('1.10'):
|
if V(django.get_version()) < V('1.10'):
|
||||||
MIDDLEWARE_CLASSES = get_middleware_settings()
|
MIDDLEWARE_CLASSES = get_middleware_settings()
|
||||||
|
@ -21,7 +21,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='ContentPage',
|
name='ContentPage',
|
||||||
fields=[
|
fields=[
|
||||||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
|
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), # noqa: E501
|
||||||
('subtitle', models.CharField(blank=True, default='', max_length=255)),
|
('subtitle', models.CharField(blank=True, default='', max_length=255)),
|
||||||
('body', wagtail.wagtailcore.fields.RichTextField(blank=True, default='')),
|
('body', wagtail.wagtailcore.fields.RichTextField(blank=True, default='')),
|
||||||
],
|
],
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
# Generated by Django 1.11.1 on 2017-06-02 04:26
|
# Generated by Django 1.11.1 on 2017-06-02 04:26
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
import wagtail.wagtailcore.fields
|
import wagtail.wagtailcore.fields
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@ -18,7 +18,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='RegularPage',
|
name='RegularPage',
|
||||||
fields=[
|
fields=[
|
||||||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
|
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), # noqa: E501
|
||||||
('subtitle', models.CharField(blank=True, default='', max_length=255)),
|
('subtitle', models.CharField(blank=True, default='', max_length=255)),
|
||||||
('body', wagtail.wagtailcore.fields.RichTextField(blank=True, default='')),
|
('body', wagtail.wagtailcore.fields.RichTextField(blank=True, default='')),
|
||||||
],
|
],
|
||||||
|
@ -4,16 +4,14 @@ import datetime
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from tests.factories.page import ContentPageFactory
|
from tests.factories.rule import ReferralRuleFactory
|
||||||
from tests.factories.rule import (
|
|
||||||
DayRuleFactory, DeviceRuleFactory, ReferralRuleFactory, TimeRuleFactory)
|
|
||||||
from tests.factories.segment import SegmentFactory
|
from tests.factories.segment import SegmentFactory
|
||||||
from tests.factories.site import SiteFactory
|
|
||||||
from wagtail_personalisation.models import Segment
|
from wagtail_personalisation.models import Segment
|
||||||
from wagtail_personalisation.rules import TimeRule
|
from wagtail_personalisation.rules import TimeRule
|
||||||
|
|
||||||
# Factory tests
|
# Factory tests
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_segment_create():
|
def test_segment_create():
|
||||||
factoried_segment = SegmentFactory()
|
factoried_segment = SegmentFactory()
|
||||||
@ -27,8 +25,6 @@ def test_segment_create():
|
|||||||
assert factoried_segment.status == segment.status
|
assert factoried_segment.status == segment.status
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_referral_rule_create():
|
def test_referral_rule_create():
|
||||||
segment = SegmentFactory(name='Referral')
|
segment = SegmentFactory(name='Referral')
|
||||||
|
@ -16,6 +16,8 @@ def test_time_rule_create():
|
|||||||
segment=segment)
|
segment=segment)
|
||||||
|
|
||||||
assert time_rule.start_time == datetime.time(8, 0, 0)
|
assert time_rule.start_time == datetime.time(8, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@freeze_time("10:00:00")
|
@freeze_time("10:00:00")
|
||||||
def test_requesttime_segment(client, site):
|
def test_requesttime_segment(client, site):
|
||||||
|
@ -2,15 +2,14 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.forms.models import model_to_dict
|
|
||||||
from django.contrib.sessions.backends.db import SessionStore
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from django.forms.models import model_to_dict
|
||||||
|
|
||||||
|
from tests.factories.segment import SegmentFactory
|
||||||
from wagtail_personalisation.forms import SegmentAdminForm
|
from wagtail_personalisation.forms import SegmentAdminForm
|
||||||
from wagtail_personalisation.models import Segment
|
from wagtail_personalisation.models import Segment
|
||||||
from wagtail_personalisation.rules import TimeRule, VisitCountRule
|
from wagtail_personalisation.rules import TimeRule, VisitCountRule
|
||||||
|
|
||||||
from tests.factories.segment import SegmentFactory
|
|
||||||
|
|
||||||
|
|
||||||
def form_with_data(segment, *rules):
|
def form_with_data(segment, *rules):
|
||||||
model_fields = ['type', 'status', 'count', 'name', 'match_any']
|
model_fields = ['type', 'status', 'count', 'name', 'match_any']
|
||||||
@ -63,6 +62,7 @@ def test_anonymous_user_not_added_to_static_segment_at_creation(site, client):
|
|||||||
|
|
||||||
assert not instance.static_users.all()
|
assert not instance.static_users.all()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_match_any_correct_populates(site, client, django_user_model):
|
def test_match_any_correct_populates(site, client, django_user_model):
|
||||||
user = django_user_model.objects.create(username='first')
|
user = django_user_model.objects.create(username='first')
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from wagtail_personalisation.utils import impersonate_other_page, exclude_variants
|
from wagtail_personalisation.utils import (
|
||||||
|
exclude_variants, impersonate_other_page)
|
||||||
|
|
||||||
|
|
||||||
class Page(object):
|
class Page(object):
|
||||||
|
2
tox.ini
2
tox.ini
@ -20,7 +20,7 @@ commands =
|
|||||||
|
|
||||||
[testenv:lint]
|
[testenv:lint]
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
deps = flake8
|
deps = flake8==3.5.0
|
||||||
commands =
|
commands =
|
||||||
flake8 src tests setup.py
|
flake8 src tests setup.py
|
||||||
isort -q --recursive --diff src/ tests/
|
isort -q --recursive --diff src/ tests/
|
||||||
|
Reference in New Issue
Block a user