From 5b63aa0d80d4c24222867c516118d8af41359fef Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Thu, 4 May 2017 15:00:50 +0530 Subject: [PATCH] Fix #204 (#205) --- .travis.yml | 2 +- instance/settings-sample.py | 3 ++ lastuserapp/__init__.py | 73 ++++++++++++++++++------------------- manage.py | 4 +- requirements.txt | 2 - rq.sh | 2 +- rqdev.py | 15 -------- rqinit.py | 3 +- runserver.py | 5 +-- runtests.sh | 4 ++ runtestserver.py | 3 +- website.py | 3 +- 12 files changed, 52 insertions(+), 67 deletions(-) delete mode 100644 rqdev.py create mode 100755 runtests.sh diff --git a/.travis.yml b/.travis.yml index c8d6768..6086c8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ before_script: - psql -c 'create database lastuser_test_app;' -U postgres script: - - nosetests --with-timer + - ./runtests.sh notifications: email: false diff --git a/instance/settings-sample.py b/instance/settings-sample.py index a2b3b5e..db0eca8 100644 --- a/instance/settings-sample.py +++ b/instance/settings-sample.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- from flask import Markup +#: Debug mode (put this value in development.py only, never in settings.py) +DEBUG = True + #: The title of this site SITE_TITLE = 'Lastuser' diff --git a/lastuserapp/__init__.py b/lastuserapp/__init__.py index 04b001e..ba16986 100644 --- a/lastuserapp/__init__.py +++ b/lastuserapp/__init__.py @@ -26,42 +26,41 @@ assets['lastuser-oauth.js'][version] = lastuser_oauth.lastuser_oauth_js, assets['lastuser-oauth.css'][version] = lastuser_oauth.lastuser_oauth_css +# Configure the app +coaster.app.init_app(app) +db.init_app(app) +db.app = app # To make it work without an app context +RQ(app) # Pick up RQ configuration from the app +baseframe.init_app(app, requires=['lastuser-oauth'], + ext_requires=['baseframe-bs3', 'fontawesome>=4.0.0', 'jquery.cookie', 'timezone']) -def init_for(env): - coaster.app.init_app(app, env) - db.init_app(app) - db.app = app # To make it work without an app context - RQ(app) # Pick up RQ configuration from the app - baseframe.init_app(app, requires=['lastuser-oauth'], - ext_requires=['baseframe-bs3', 'fontawesome>=4.0.0', 'jquery.cookie', 'timezone']) +lastuser_oauth.lastuser_oauth.init_app(app) +lastuser_oauth.mailclient.mail.init_app(app) +lastuser_oauth.views.login.oid.init_app(app) - lastuser_oauth.lastuser_oauth.init_app(app) - lastuser_oauth.mailclient.mail.init_app(app) - lastuser_oauth.views.login.oid.init_app(app) - - # Register some login providers - if app.config.get('OAUTH_TWITTER_KEY') and app.config.get('OAUTH_TWITTER_SECRET'): - login_registry['twitter'] = providers.TwitterProvider('twitter', 'Twitter', - at_login=True, priority=True, icon='twitter', - key=app.config['OAUTH_TWITTER_KEY'], - secret=app.config['OAUTH_TWITTER_SECRET'], - access_key=app.config.get('OAUTH_TWITTER_ACCESS_KEY'), - access_secret=app.config.get('OAUTH_TWITTER_ACCESS_SECRET')) - if app.config.get('OAUTH_GOOGLE_KEY') and app.config.get('OAUTH_GOOGLE_SECRET'): - login_registry['google'] = providers.GoogleProvider('google', 'Google', - client_id=app.config['OAUTH_GOOGLE_KEY'], - secret=app.config['OAUTH_GOOGLE_SECRET'], - scope=app.config.get('OAUTH_GOOGLE_SCOPE', ['email', 'profile']), - at_login=True, priority=True, icon='google') - if app.config.get('OAUTH_LINKEDIN_KEY') and app.config.get('OAUTH_LINKEDIN_SECRET'): - login_registry['linkedin'] = providers.LinkedInProvider('linkedin', 'LinkedIn', - at_login=True, priority=False, icon='linkedin', - key=app.config['OAUTH_LINKEDIN_KEY'], - secret=app.config['OAUTH_LINKEDIN_SECRET']) - if app.config.get('OAUTH_GITHUB_KEY') and app.config.get('OAUTH_GITHUB_SECRET'): - login_registry['github'] = providers.GitHubProvider('github', 'GitHub', - at_login=True, priority=False, icon='github', - key=app.config['OAUTH_GITHUB_KEY'], - secret=app.config['OAUTH_GITHUB_SECRET']) - login_registry['openid'] = providers.OpenIdProvider('openid', 'OpenID', - at_login=True, priority=False, icon='openid') +# Register some login providers +if app.config.get('OAUTH_TWITTER_KEY') and app.config.get('OAUTH_TWITTER_SECRET'): + login_registry['twitter'] = providers.TwitterProvider('twitter', 'Twitter', + at_login=True, priority=True, icon='twitter', + key=app.config['OAUTH_TWITTER_KEY'], + secret=app.config['OAUTH_TWITTER_SECRET'], + access_key=app.config.get('OAUTH_TWITTER_ACCESS_KEY'), + access_secret=app.config.get('OAUTH_TWITTER_ACCESS_SECRET')) +if app.config.get('OAUTH_GOOGLE_KEY') and app.config.get('OAUTH_GOOGLE_SECRET'): + login_registry['google'] = providers.GoogleProvider('google', 'Google', + client_id=app.config['OAUTH_GOOGLE_KEY'], + secret=app.config['OAUTH_GOOGLE_SECRET'], + scope=app.config.get('OAUTH_GOOGLE_SCOPE', ['email', 'profile']), + at_login=True, priority=True, icon='google') +if app.config.get('OAUTH_LINKEDIN_KEY') and app.config.get('OAUTH_LINKEDIN_SECRET'): + login_registry['linkedin'] = providers.LinkedInProvider('linkedin', 'LinkedIn', + at_login=True, priority=False, icon='linkedin', + key=app.config['OAUTH_LINKEDIN_KEY'], + secret=app.config['OAUTH_LINKEDIN_SECRET']) +if app.config.get('OAUTH_GITHUB_KEY') and app.config.get('OAUTH_GITHUB_SECRET'): + login_registry['github'] = providers.GitHubProvider('github', 'GitHub', + at_login=True, priority=False, icon='github', + key=app.config['OAUTH_GITHUB_KEY'], + secret=app.config['OAUTH_GITHUB_SECRET']) +login_registry['openid'] = providers.OpenIdProvider('openid', 'OpenID', + at_login=True, priority=False, icon='openid') diff --git a/manage.py b/manage.py index 0b903b4..3db3761 100755 --- a/manage.py +++ b/manage.py @@ -8,10 +8,10 @@ import lastuserapp import lastuser_core.models as models from lastuser_core.models import db -from lastuserapp import app, init_for +from lastuserapp import app if __name__ == '__main__': db.init_app(app) - manager = init_manager(app, db, init_for, lastuser_core=lastuser_core, lastuser_oauth=lastuser_oauth, lastuser_ui=lastuser_ui, lastuserapp=lastuserapp, models=models) + manager = init_manager(app, db, lastuser_core=lastuser_core, lastuser_oauth=lastuser_oauth, lastuser_ui=lastuser_ui, lastuserapp=lastuserapp, models=models) manager.run() diff --git a/requirements.txt b/requirements.txt index 332606d..2205794 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,6 @@ Flask-WTF requests blinker Flask-RQ -Flask-Script==0.5.3 tweepy unicodecsv oauth2client @@ -25,4 +24,3 @@ itsdangerous psycopg2 git+https://github.com/hasgeek/coaster git+https://github.com/hasgeek/baseframe -git+https://github.com/jace/flask-alembic diff --git a/rq.sh b/rq.sh index 9c80752..af7f29c 100755 --- a/rq.sh +++ b/rq.sh @@ -1,3 +1,3 @@ #!/bin/bash -rqworker -c rqdev lastuser +rqworker -c rqinit lastuser diff --git a/rqdev.py b/rqdev.py deleted file mode 100644 index 4387a35..0000000 --- a/rqdev.py +++ /dev/null @@ -1,15 +0,0 @@ -from urlparse import urlparse -from lastuserapp 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 cc075ac..35c0dd7 100644 --- a/rqinit.py +++ b/rqinit.py @@ -1,7 +1,6 @@ from urlparse import urlparse -from lastuserapp import init_for, app +from lastuserapp import app -init_for('production') 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 d680901..4297218 100755 --- a/runserver.py +++ b/runserver.py @@ -4,7 +4,6 @@ reload(sys) sys.setdefaultencoding('utf-8') -from lastuserapp import app, init_for +from lastuserapp import app -init_for('dev') -app.run('0.0.0.0', 7000, debug=True) +app.run('0.0.0.0', 7000) diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 0000000..b9fc181 --- /dev/null +++ b/runtests.sh @@ -0,0 +1,4 @@ +#!/bin/sh +export FLASK_ENV="TESTING" +coverage run `which nosetests --with-timer` +coverage report diff --git a/runtestserver.py b/runtestserver.py index 8db0de4..7b528d2 100644 --- a/runtestserver.py +++ b/runtestserver.py @@ -4,10 +4,9 @@ reload(sys) sys.setdefaultencoding('utf-8') -from lastuserapp import app, init_for, db +from lastuserapp import app, db from lastuser_core.models import * -init_for('testing') #incase data exists from previously run tests db.drop_all() #create schema again diff --git a/website.py b/website.py index c96b225..c18cb31 100644 --- a/website.py +++ b/website.py @@ -1,5 +1,4 @@ import sys import os.path sys.path.insert(0, os.path.dirname(__file__)) -from lastuserapp import app as application, init_for -init_for('production') +from lastuserapp import app as application