Basic Flask skeleton

This commit is contained in:
RunasSudo 2017-11-22 18:46:45 +11:00
parent db74f67474
commit b1730be551
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 92 additions and 37 deletions

View File

@ -55,6 +55,7 @@ class BaseJSTestCase(TestCase):
setattr(cls, method, call_method) setattr(cls, method, call_method)
# Test discovery # Test discovery
def run_tests(prefix=None, lang=None):
import eos.core.tests import eos.core.tests
for dirpath, dirnames, filenames in os.walk('eos'): for dirpath, dirnames, filenames in os.walk('eos'):
if dirpath == 'eos': if dirpath == 'eos':
@ -69,7 +70,7 @@ for dirpath, dirnames, filenames in os.walk('eos'):
if issubclass(obj, eos.core.tests.EosTestCase): if issubclass(obj, eos.core.tests.EosTestCase):
if obj.__module__ != module_name: if obj.__module__ != module_name:
continue continue
if len(sys.argv) > 1 and not obj.__module__.startswith(sys.argv[1]): if prefix is not None and not obj.__module__.startswith(prefix):
continue continue
impl = obj() impl = obj()
@ -79,17 +80,20 @@ for dirpath, dirnames, filenames in os.walk('eos'):
method_val = getattr(impl, method) method_val = getattr(impl, method)
if isinstance(method_val, types.MethodType) and not hasattr(cls_py, method): if isinstance(method_val, types.MethodType) and not hasattr(cls_py, method):
# Python # Python
if not (len(sys.argv) > 2 and sys.argv[2] == 'js') and not getattr(method_val, '_js_only', False): if not (lang is not None and lang == 'js') and not getattr(method_val, '_js_only', False):
cls_py.add_method(method) cls_py.add_method(method)
if method.startswith('test_'): if method.startswith('test_'):
test_case = cls_py(method) test_case = cls_py(method)
test_suite.addTest(test_case) test_suite.addTest(test_case)
# Javascript # Javascript
if not (len(sys.argv) > 2 and sys.argv[2] == 'py') and not getattr(method_val, '_py_only', False): if not (lang is not None and lang == 'py') and not getattr(method_val, '_py_only', False):
if method.startswith('test_'): if method.startswith('test_'):
cls_js.add_method(method) cls_js.add_method(method)
test_case = cls_js(method) test_case = cls_js(method)
test_suite.addTest(test_case) test_suite.addTest(test_case)
TextTestRunner(verbosity=3, failfast=True).run(test_suite) TextTestRunner(verbosity=3, failfast=True).run(test_suite)
if __name__ == '__main__':
run_tests(*sys.argv[1:])

18
eosweb/__init__.py Normal file
View File

@ -0,0 +1,18 @@
# Eos - Verifiable elections
# Copyright © 2017 RunasSudo (Yingtong Li)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Allow FLASK_APP=eosweb instead of eosweb.eosweb
from .eosweb import app

27
eosweb/eosweb.py Normal file
View File

@ -0,0 +1,27 @@
# Eos - Verifiable elections
# Copyright © 2017 RunasSudo (Yingtong Li)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import click
import flask
app = flask.Flask(__name__)
@app.cli.command('test')
@click.option('--prefix', default=None)
@click.option('--lang', default=None)
def run_tests(prefix, lang):
import eos.tests
eos.tests.run_tests(prefix, lang)

View File

@ -1,7 +1,13 @@
click==6.7
coverage==4.4.1 coverage==4.4.1
Flask==0.12.2
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
mypy==0.521 mypy==0.521
PyExecJS==1.4.1 PyExecJS==1.4.1
pymongo==3.5.1 pymongo==3.5.1
six==1.10.0 six==1.10.0
Transcrypt==3.6.50 Transcrypt==3.6.50
typed-ast==1.0.4 typed-ast==1.0.4
Werkzeug==0.12.2