From 0f76d1acad47634d9f6c14fcd8811136baa47d91 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sun, 18 Nov 2018 11:58:22 +0100 Subject: [PATCH] Get dummy test suite in place. At least isort/pylava are passing. --- .gitignore | 1 + Pipfile | 1 + Pipfile.lock | 31 ++++++++++++++++++++++++++++++- README.md | 8 ++++++++ tests/__init__.py | 0 tests/conftest.py | 1 + tox.ini | 24 ++++++++++++++++++++++++ xppl/forms.py | 1 + xppl/getannot.py | 1 - xppl/models.py | 2 +- xppl/views.py | 34 +++++++++++++++++----------------- 11 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 936aae3..dac41a8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__/ rqlite* xppl/cover/** xppl/uploads/** +.tox diff --git a/Pipfile b/Pipfile index 450961a..8af201c 100644 --- a/Pipfile +++ b/Pipfile @@ -26,6 +26,7 @@ isort = "*" molecule = "*" pylava = "*" pytest = "*" +tox = "*" [scripts] dev = "python dev.py" diff --git a/Pipfile.lock b/Pipfile.lock index 87d7d1d..3048ebd 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "ff23b231918be30a5c0e107881b3ba4d1c80fa32b8c23c111a7c5de2bc9b067a" + "sha256": "fbaf222a7097845663946321f6cfa0b2d6ddae146ffbdb0d4ce8890dfc637d64" }, "pipfile-spec": 6, "requires": {}, @@ -652,6 +652,13 @@ ], "version": "==0.14.1" }, + "filelock": { + "hashes": [ + "sha256:b8d5ca5ca1c815e1574aee746650ea7301de63d87935b3463d26368b76e31633", + "sha256:d610c1bb404daf85976d7a82eb2ada120f04671007266b708606565dd03b5be6" + ], + "version": "==3.0.10" + }, "flake8": { "hashes": [ "sha256:7253265f7abd8b313e3892944044a365e3f4ac3fcdcfb4298f55ee9ddf188ba0", @@ -1046,6 +1053,21 @@ ], "version": "==1.16.0" }, + "toml": { + "hashes": [ + "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c", + "sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e" + ], + "version": "==0.10.0" + }, + "tox": { + "hashes": [ + "sha256:513e32fdf2f9e2d583c2f248f47ba9886428c949f068ac54a0469cac55df5862", + "sha256:75fa30e8329b41b664585f5fb837e23ce1d7e6fa1f7811f2be571c990f9d911b" + ], + "index": "pypi", + "version": "==3.5.3" + }, "traitlets": { "hashes": [ "sha256:9c4bd2d267b7153df9152698efb1050a5d84982d3384a37b2c1f7723ba3e7835", @@ -1067,6 +1089,13 @@ ], "version": "==1.24.1" }, + "virtualenv": { + "hashes": [ + "sha256:686176c23a538ecc56d27ed9d5217abd34644823d6391cbeb232f42bf722baad", + "sha256:f899fafcd92e1150f40c8215328be38ff24b519cd95357fa6e78e006c7638208" + ], + "version": "==16.1.0" + }, "wcwidth": { "hashes": [ "sha256:3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e", diff --git a/README.md b/README.md index efa533e..41d3991 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,14 @@ $ pipenv run dev [Pipenv]: https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv [RQLite]: https://github.com/rqlite/rqlite +# Test It + +```bash +$ pipenv run tox +``` + +Refer to the [tox.ini](tox.ini) for configuration options. + # Deploy It See [ansible/README.md](ansible/README.md) for this. diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..0cbf2c2 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1 @@ +"""Pytest fixtures.""" diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..53e6924 --- /dev/null +++ b/tox.ini @@ -0,0 +1,24 @@ +[isort] +multi_line_output = 5 +skip = .tox,build/* + +[pylava] +skip = .tox/*,build/* + +[pylava:mccabe] +complexity = 15 + +[tox] +skipsdist = True +envlist = py36 + +[testenv] +setenv = + PIPENV_IGNORE_VIRTUALENVS = 1 +deps = + pipenv +commands = + pipenv install --dev + pipenv run pylava . --options=tox.ini + pipenv run isort --quiet --recursive --check-only --diff --settings-path=tox.ini + # pipenv run pytest {posargs: tests} # Note(decentral1se): add when we have tests diff --git a/xppl/forms.py b/xppl/forms.py index dd6c979..671ea51 100755 --- a/xppl/forms.py +++ b/xppl/forms.py @@ -5,6 +5,7 @@ from wtforms import validators from wtforms.fields import FormField, SelectField, StringField, SubmitField from wtforms.fields.html5 import DecimalRangeField from wtforms.validators import DataRequired, InputRequired + from xppl.models import Author diff --git a/xppl/getannot.py b/xppl/getannot.py index 1644f03..df72051 100644 --- a/xppl/getannot.py +++ b/xppl/getannot.py @@ -1,7 +1,6 @@ import json import requests - from flask import request diff --git a/xppl/models.py b/xppl/models.py index 97feb3b..d62863a 100755 --- a/xppl/models.py +++ b/xppl/models.py @@ -2,8 +2,8 @@ import datetime from marshmallow import Schema, ValidationError, fields from sqlalchemy import Column, DateTime -from xppl.database import db +from xppl.database import db authors = db.Table( 'books_authors', diff --git a/xppl/views.py b/xppl/views.py index 7c4156f..530082f 100755 --- a/xppl/views.py +++ b/xppl/views.py @@ -8,24 +8,11 @@ from functools import wraps from urllib.parse import quote as urlquote import autocomplete -from xppl.database import db -from xppl.socketio import socketio -from xppl.cover import get_cover -from xppl.extractText import extract_text -from xppl.forms import ( - AddtoStackForm, EditForm, EditStackForm, - SearchForm, StackForm, UploadForm -) -from xppl.getannot import get_annot_book, get_annot_results, get_annotations -from xppl.models import ( - Author, AuthorSchema, Book, BookSchema, Chat, - ChatSchema, Instance, Potential, Stack, StackSchema, - UserIns -) +from flask import Response, abort +from flask import current_app as app from flask import ( - Response, abort, flash, jsonify, redirect, - render_template, request, send_from_directory, - url_for, current_app as app + flash, jsonify, redirect, render_template, request, send_from_directory, + url_for ) from flask_socketio import emit from flask_weasyprint import HTML, render_pdf @@ -33,6 +20,19 @@ from sqlalchemy.inspection import inspect from sqlalchemy.sql.expression import func from werkzeug.utils import secure_filename +from xppl.cover import get_cover +from xppl.database import db +from xppl.extractText import extract_text +from xppl.forms import ( + AddtoStackForm, EditForm, EditStackForm, SearchForm, StackForm, UploadForm +) +from xppl.getannot import get_annot_book, get_annot_results, get_annotations +from xppl.models import ( + Author, AuthorSchema, Book, BookSchema, Chat, ChatSchema, Instance, + Potential, Stack, StackSchema, UserIns +) +from xppl.socketio import socketio + ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'epub', 'chm', 'mobi']) author_schema = AuthorSchema()