From 994a5d3b457f86dda6426401c3557047b9ad9a63 Mon Sep 17 00:00:00 2001 From: Vidya Ramakrishnan Date: Thu, 4 May 2017 13:35:43 +0530 Subject: [PATCH 1/2] Make init_for call implicit. Fixes #5 --- outreach/__init__.py | 23 +++++++++++------------ rq.sh | 2 +- rqdev.py | 16 ---------------- rqinit.py | 3 +-- runserver.py | 3 +-- tests/test_kharcha.py | 3 +-- tests/test_order.py | 3 +-- website.wsgi | 3 +-- 8 files changed, 17 insertions(+), 39 deletions(-) delete mode 100644 rqdev.py diff --git a/outreach/__init__.py b/outreach/__init__.py index 007f7d7..b093caa 100644 --- a/outreach/__init__.py +++ b/outreach/__init__.py @@ -48,19 +48,18 @@ def init_flask_admin(): # Configure the app -def init_for(env): - coaster.app.init_app(app, env) - db.init_app(app) - db.app = app +coaster.app.init_app(app) +db.init_app(app) +db.app = app - RQ(app) +RQ(app) - lastuser.init_app(app) - lastuser.init_usermanager(UserManager(db, User)) - app.config['tz'] = timezone(app.config['TIMEZONE']) - baseframe.init_app(app, requires=['outreach'], ext_requires=['baseframe-bs3', 'fontawesome>=4.0.0', 'ractive', 'ractive-transitions-fly', 'validate', 'nprogress', 'baseframe-footable']) +lastuser.init_app(app) +lastuser.init_usermanager(UserManager(db, User)) +app.config['tz'] = timezone(app.config['TIMEZONE']) +baseframe.init_app(app, requires=['outreach'], ext_requires=['baseframe-bs3', 'fontawesome>=4.0.0', 'ractive', 'ractive-transitions-fly', 'validate', 'nprogress', 'baseframe-footable']) - mail.init_app(app) - wtforms_json.init() +mail.init_app(app) +wtforms_json.init() - init_flask_admin() +init_flask_admin() diff --git a/rq.sh b/rq.sh index 92df0ea..b09470d 100644 --- a/rq.sh +++ b/rq.sh @@ -1,3 +1,3 @@ #!/bin/bash -rqworker -c rqdev outreach +rqworker -c rqinit outreach diff --git a/rqdev.py b/rqdev.py deleted file mode 100644 index 8d77d9b..0000000 --- a/rqdev.py +++ /dev/null @@ -1,16 +0,0 @@ -from urlparse import urlparse - -from outreach import init_for, app - -init_for('dev') - -REDIS_URL = app.config.get('REDIS_URL', 'redis://localhost:6379/0') - -# REDIS_URL is not taken by setup_default_arguments function of rq/scripts/__init__.py -# so, parse it into pieces and give it - -r = urlparse(REDIS_URL) -REDIS_HOST = r.hostname -REDIS_PORT = r.port -REDIS_PASSWORD = r.password -REDIS_DB = 0 diff --git a/rqinit.py b/rqinit.py index 9512caa..4f7b613 100644 --- a/rqinit.py +++ b/rqinit.py @@ -1,8 +1,7 @@ from urlparse import urlparse -from outreach import init_for, app +from outreach import app -init_for('prod') REDIS_URL = app.config.get('REDIS_URL', 'redis://localhost:6379/0') # REDIS_URL is not taken by setup_default_arguments function of rq/scripts/__init__.py diff --git a/runserver.py b/runserver.py index 1717d41..ea8e1f8 100755 --- a/runserver.py +++ b/runserver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -from outreach import app, init_for +from outreach import app from outreach.models import * -init_for('dev') app.run('0.0.0.0', debug=True, port=4000) diff --git a/tests/test_kharcha.py b/tests/test_kharcha.py index 8d2bf96..e842075 100644 --- a/tests/test_kharcha.py +++ b/tests/test_kharcha.py @@ -1,7 +1,7 @@ import json import unittest from flask import url_for -from outreach import app, init_for +from outreach import app from outreach.models import (db, SaleItem) from fixtures import init_data @@ -11,7 +11,6 @@ class TestKharchaAPI(unittest.TestCase): def setUp(self): self.ctx = app.test_request_context() self.ctx.push() - init_for('test') db.drop_all() db.create_all() init_data() diff --git a/tests/test_order.py b/tests/test_order.py index 59b2a65..82c67b5 100644 --- a/tests/test_order.py +++ b/tests/test_order.py @@ -1,6 +1,6 @@ import unittest import json -from outreach import app, init_for +from outreach import app from outreach.models import * from fixtures import init_data @@ -10,7 +10,6 @@ class TestOrder(unittest.TestCase): def setUp(self): self.ctx = app.test_request_context() self.ctx.push() - init_for('test') db.create_all() init_data() self.client = app.test_client() diff --git a/website.wsgi b/website.wsgi index 91f325a..fac343b 100644 --- a/website.wsgi +++ b/website.wsgi @@ -1,5 +1,4 @@ import sys import os.path sys.path.insert(0, os.path.dirname(__file__)) -from outreach import app as application, init_for -init_for('production') +from outreach import app as application From 9237d8cb785379ca7b74ea3beeaf7e597afde682 Mon Sep 17 00:00:00 2001 From: Shreyas Satish Date: Thu, 4 May 2017 14:47:54 +0530 Subject: [PATCH 2/2] fix run tests --- .travis.yml | 4 ++-- runtests.sh | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 runtests.sh diff --git a/.travis.yml b/.travis.yml index ae07c0e..b2daf94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,8 @@ install: - pip install -r test_requirements.txt - pip install -r requirements.txt script: - - nosetests -v tests - - nohup python runtestserver.py & + - FLASK_ENV=testing nosetests -v tests + - FLASK_ENV=testing nohup python runtestserver.py & - sleep 10 addons: postgresql: "9.4" diff --git a/runtests.sh b/runtests.sh new file mode 100644 index 0000000..594321e --- /dev/null +++ b/runtests.sh @@ -0,0 +1,3 @@ +#!/bin/sh +export FLASK_ENV="TESTING" +coverage run `nosetests -v tests`