Skip to content

Commit

Permalink
Test for all supported versions (#21)
Browse files Browse the repository at this point in the history
* Add tox

* Add coverage configuration

* Linting

* Define supported versions

* Fix travis notification token
  • Loading branch information
loicteixeira authored Feb 23, 2018
1 parent 4e7efe2 commit 39e32d4
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 25 deletions.
29 changes: 29 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# .coveragerc to control coverage.py
[run]
branch = True

source = ./wagtailmodelchoosers

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
return NotImplemented

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

ignore_errors = True

[html]
directory = coverage_html_report
28 changes: 24 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,34 @@ cache:
directories:
- node_modules
- ".tox"
matrix:
# See `Which version combinations to include in Travis test matrix?` in `/docs/README.md`.
include:
- env: TOXENV=py34-dj111-wt113
python: 3.4
- env: TOXENV=py35-dj111-wt113
python: 3.5
- env: TOXENV=py36-dj111-wt112
python: 3.6
- env: TOXENV=py36-dj111-wt113
python: 3.6
# - env: TOXENV=py36-dj111-wt2b
# python: 3.6
# - env: TOXENV=py36-dj2-wt2b
# python: 3.6
install:
- nvm install
- npm install
- pip install tox coveralls
- gem install coveralls-lcov
script:
- npm run lint
- make dist
- make test-ci
after_success:
# This is ran on all build, but the coverage is only fully calculated in one.
# Convert JS LCOV report to Coveralls JSON, merge and send.
- coveralls-lcov -v -n coverage/lcov.info > js_coverage.json
- coveralls --merge=js_coverage.json
notifications:
email: false
slack:
rooms:
secure: ECApgbjlDLJYxMSMKo40PJj8nG5BesJXa5GsreQ5h6ursJ5elTs8RugJa3IvPw7fc71RJUH1Hv/g0KMpanlGT7o+jc/V18Ts4r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QogopntnvuLPiJEHAssGatEgejcP7KmDpE6uv6J9xAU35gBdVubDhkwkssfwzNR/hntNrjmiOmvJs1UIU4KQo7GacB5oHyMPR4WZ+SoOCLNNO+2MvvkQ0lDTkwUsfaXoGpo6FkGzYoLAddrfzd8+tJKGOMkyYfAZtwBNi1H52Bg0D/4BGSzg2qhLpHOor1Bni+iLKjDX6QM=
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
help: ## See what commands are available.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36mmake %-15s\033[0m # %s\n", $$1, $$2}'

init: clean-pyc ## Install dependencies and initialise for development.
pip install -e .[testing,docs] -U
python ./tests/testapp/manage.py migrate --noinput
# python ./tests/testapp/manage.py loaddata test_data

clean-pyc: ## Remove Python file artifacts.
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
Expand All @@ -12,9 +17,22 @@ clean-pyc: ## Remove Python file artifacts.
start: ## Starts the development server.
python ./tests/testapp/manage.py runserver

lint: ## Lint the project.
flake8 wagtailmodelchoosers tests setup.py
isort --check-only --diff --recursive wagtailmodelchoosers tests setup.py

test: ## Test the project.
python ./runtests.py

test-coverage: ## Run the tests while generating test coverage data.
coverage run ./runtests.py && coverage report && coverage html

test-ci: ## Continuous integration test suite.
tox

update-test-fixture: ## Update test fixture from the db.
python ./tests/testapp/manage.py dumpdata --indent=4 -e contenttypes -e auth.permission -e auth.group -e sessions -e wagtailcore.site -e wagtailcore.pagerevision -e wagtailcore.grouppagepermission -e wagtailimages.rendition -e wagtailcore.collection -e wagtailcore.groupcollectionpermission > tests/testapp/core/fixtures/test_data.json

dist: ## Compile the JS and CSS for release.
npm run dist

Expand Down
21 changes: 21 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Documentation

## Browser support

We align our browser support targets with that of Wagtail. Have a look at the [official documentation](http://docs.wagtail.io/en/latest/contributing/developing.html).

## Python/Django/Wagtail support

Python versions as defined in `setup.py` classifiers.

Wagtail versions as [supported](http://docs.wagtail.io/en/latest/releases/upgrading.html) by Wagtail (LTS, current and current-1).

Django/Wagtail combinations as [supported](http://docs.wagtail.io/en/latest/releases/upgrading.html#compatible-django-python-versions) by Wagtail (for the Wagtail versions as defined above).

### Which version combinations to include in Travis test matrix?

In order to keep for CI build time from growing out of control, not all Python/Django/Wagtail combinations will be tested.

Test as follow:
- All supported Django/Wagtail combinations with the latest supported Python version of the `3.x` series.
- The latest supported Django/Wagtail combination for the remaining Python versions.
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ exclude =

[isort]
line_length=100
multi_line_output=4
# add_imports=from __future__ import absolute_import,from __future__ import unicode_literals
multi_line_output=3
include_trailing_comma=True
skip=
migrations,
16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
# Testing dependencies
testing_extras = [
# Required for running the tests
'tox>=2.3.1',
'tox>=2.3.1,<2.4',

# For coverage and PEP8 linting
'coverage>=4.1.0',
'flake8>=3.2.0',
'isort>=4.2.5',
'coverage>=4.1.0,<4.2',
'flake8>=3.2.0,<3.3',
'flake8-colors>=0.1.6,<1',
'isort==4.2.5',
]

# Documentation dependencies
Expand Down Expand Up @@ -52,11 +53,10 @@
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
# 'Programming Language :: Python :: 2',
# 'Programming Language :: Python :: 2.7',
# 'Programming Language :: Python :: 3',
# 'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Internet :: WWW/HTTP :: Site Management',
Expand Down
4 changes: 1 addition & 3 deletions tests/test_blocks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from __future__ import absolute_import, unicode_literals

from django.test import TestCase, override_settings

from wagtail.wagtailcore.models import Page
from wagtailmodelchoosers import blocks
from wagtailmodelchoosers import widgets

from core.models import SimplePage
from wagtailmodelchoosers import blocks, widgets

TEST_MODEL_CHOOSERS_OPTIONS = {
'core_page': {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_widget.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import absolute_import, unicode_literals

import uuid
from django.test import TestCase

from django.test import TestCase
from wagtail.wagtailcore.models import Page
from wagtailmodelchoosers import widgets

from core.models import SimplePage
from wagtailmodelchoosers import widgets


class TestModelChooserWidget(TestCase):
Expand Down
Empty file.
32 changes: 32 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
skipsdist = True
usedevelop = True
envlist =
py{34,35,36}-dj{111}-wt{112,113}
# py{34,35,36}-dj{111,2}-wt{2b}

[testenv]
install_command = pip install -e ".[testing]" -U {opts} {packages}
whitelist_externals =
make

basepython =
py34: python3.4
py35: python3.5
py36: python3.6

deps =
dj111: Django>=1.11,<2.0
# dj2: Django>=2.0,<2.1
wt112: wagtail>=1.12,<1.13
wt113: wagtail>=1.13,<1.14
# wt2b: wagtail==2.0b1

commands =
make lint
make test-coverage
12 changes: 7 additions & 5 deletions wagtailmodelchoosers/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.apps import apps
from django.db.models import Q, CharField

import requests

from django.apps import apps
from django.db.models import CharField, Q
from rest_framework import filters, serializers
from rest_framework.authentication import BasicAuthentication, SessionAuthentication
from rest_framework.mixins import ListModelMixin
Expand All @@ -11,7 +9,11 @@
from rest_framework.viewsets import GenericViewSet, ViewSet

from wagtailmodelchoosers.paginators import GenericModelPaginator
from wagtailmodelchoosers.utils import get_chooser_options, get_query_keys_map, get_response_keys_map
from wagtailmodelchoosers.utils import (
get_chooser_options,
get_query_keys_map,
get_response_keys_map,
)


class ModelView(ListModelMixin, GenericViewSet):
Expand Down
3 changes: 2 additions & 1 deletion wagtailmodelchoosers/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def get_js_init_data(self, id_, name, value):

def render_js_init(self, id_, name, value):
data = self.get_js_init_data(id_, name, value)
return 'wagtailModelChoosers.initRemoteModelChooser({id_}, {data})'.format(id_=json.dumps(id_), data=json.dumps(data))
return 'wagtailModelChoosers.initRemoteModelChooser({id_}, {data})'.format(
id_=json.dumps(id_), data=json.dumps(data))

def render_html(self, name, value, attrs):
context = {
Expand Down

0 comments on commit 39e32d4

Please sign in to comment.