Skip to content

Commit

Permalink
Merge branch 'release/0.7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
wooyek committed Dec 25, 2015
2 parents 954c42b + 25ed537 commit 897f446
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 111 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ example/sqla/website/settings_prd.py
example/gae/website/settings_dev.py
example/mongodb/website/settings_dev.py
example/sqla/website/settings_dev.py
.ssh_key
example/gae/website/settings/production.py
example/sqla/website/settings/production.py
example/gae/website/settings/local.py
example/sqla/website/settings/local.py
example/sqla/website/db.sqlite
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: python

python:
- "2.7"
- "3.5"

sudo: false

cache:
- apt
- pip

install:
- pip install -r requirements.txt -r requirements-dev.txt

script: nosetests

branches:
only:
- develop
- master
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ override.

https://github.com/wooyek/flask-social-blueprint

.. image:: https://travis-ci.org/wooyek/flask-social-blueprint.svg

.. image:: https://coveralls.io/repos/wooyek/flask-social-blueprint/badge.svg?branch=develop&service=github :target: https://coveralls.io/github/wooyek/flask-social-blueprint?branch=develop

Demo
----

Expand Down
35 changes: 27 additions & 8 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,62 @@
# vi: set ft=ruby :

$script = <<SCRIPT
sudo apt-get update
sudo apt-get install -y python-dev python-pip
sudo apt-get install -y mongodb
sudo apt-get install -y git unzip
sudo pip install virtualenv
# ======================================
# System update and common utilities
# ======================================
cat /vagrant/.ssh_key >> .ssh/authorized_keys
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y htop git unzip
sudo apt-get install -y build-essential libffi-dev libssl-dev
sudo apt-get install -y python python-dev python-pip python-virtualenv
sudo pip install virtualenvwrapper
# Change Time Zone
# dpkg-reconfigure tzdata
sudo timedatectl set-timezone Europe/Warsaw
# ======================================
# Vagrant development setup
# ======================================
echo "export WORKON_HOME=/home/vagrant/.virtualenvs" >> /home/vagrant/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> /home/vagrant/.bashrc
export WORKON_HOME=/home/vagrant/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
# ======================================
echo "Setting up virtual environments"
mkvirtualenv dev
/home/vagrant/.virtualenvs/dev/bin/pip install -r /vagrant/requirements.txt
/home/vagrant/.virtualenvs/vde/bin/pip install -r /vagrant/requirements-dev.txt
/home/vagrant/.virtualenvs/dev/bin/pip install -r /vagrant/requirements-dev.txt
# ======================================
echo "Setting up sqla example environment"
mkvirtualenv sqla
/home/vagrant/.virtualenvs/sqla/bin/pip install -r /vagrant/example/sqla/requirements.txt
# ======================================
echo "Setting up mongodb example environment"
mkvirtualenv mongodb
/home/vagrant/.virtualenvs/mongodb/bin/pip install -r /vagrant/example/mongodb/requirements.txt
# ======================================
echo "Setting up gae example environment"
mkvirtualenv gae
/home/vagrant/.virtualenvs/gae/bin/pip install --target=/vagrant/example/gae/lib -r /vagrant/example/gae/requirements.txt
wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.17.zip
unzip google_appengine_1.9.17.zip
wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.30.zip
unzip google_appengine_1.9.30.zip
chown -R vagrant:vagrant /home/vagrant/.virtualenvs
SCRIPT

Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "vagrant"
config.vm.provision "shell", inline: $script
config.vm.network "private_network", ip: "192.168.113.4"
config.vm.network "forwarded_port", host_ip: "127.0.0.1", host: 5055, guest: 5055
Expand Down
2 changes: 1 addition & 1 deletion example/gae/app.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
application: flask-social-blueprint
version: 2
version: 3
runtime: python27
api_version: 1
threadsafe: true
Expand Down
2 changes: 1 addition & 1 deletion example/gae/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def by_profile(cls, profile):

@classmethod
def from_profile(cls, user, profile):
if not user or user.is_anonymous():
if not user or user.is_anonymous:
email = profile.data.get("email")
if not email:
msg = "Cannot create new user, authentication provider did not not provide email"
Expand Down
7 changes: 6 additions & 1 deletion example/gae/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
app.debug = DEBUG
app.testing = DEBUG # WARNING: this will disable login_manager decorators

if not PRODUCTION:
# enable jinja debugging info in GAE SDK
# http://jinja.pocoo.org/docs/faq/#my-tracebacks-look-weird-what-s-happening
from google.appengine.tools.devappserver2.python import sandbox
sandbox._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt', 'pwd']

# -------------------------------------------------------------
# Load settings from separate modules
Expand All @@ -63,7 +68,7 @@
import website.settings
app.config.from_object(website.settings)

config = "website.settings_prd" if PRODUCTION else "website.settings_dev"
config = "website.settings.production" if PRODUCTION else "website.settings.local"
import importlib
try:
cfg = importlib.import_module(config)
Expand Down
34 changes: 9 additions & 25 deletions example/gae/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
flask-social-blueprint>=0.7
Babel>=1.3
Flask>=0.10.1
Flask-Babel>=0.9
Flask-Login>=0.2.11
Flask-Mail>=0.9.0
Flask-OAuth>=0.12
Flask-Principal>=0.4.0
Flask-Script>=2.0.5
Flask-Security>=1.7.2
Flask-WTF>=0.9.5
Jinja2>=2.7.2
MarkupSafe>=0.19
WTForms>=1.0.5
Werkzeug>=0.9.4
blinker>=1.3
Flask-Security>=1.7.5
Flask-Mail>=0.9.1
Flask-Script
Flask-SQLAlchemy
facebook-sdk>=0.4.0
google-api-python-client>=1.2
httplib2>=0.8
itsdangerous>=0.24
oauth2>=1.5.211
oauthlib>=0.6.1
passlib>=1.6.2
python-twitter>=1.3.1
pytz>=2014.2
requests>=2.2.1
requests-oauthlib>=0.4.0
simplejson>=3.5.2
speaklater>=1.3
certifi
python-twitter
PyOpenSSL
ndg-httpsclient
pyasn1

Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion example/sqla/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def by_profile(cls, profile):

@classmethod
def from_profile(cls, user, profile):
if not user or user.is_anonymous():
if not user or user.is_anonymous:
email = profile.data.get("email")
if not email:
msg = "Cannot create new user, authentication provider did not not provide email"
Expand Down
2 changes: 1 addition & 1 deletion example/sqla/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import website.settings
app.config.from_object(website.settings)

config = "website.settings_prd" if PRODUCTION else "website.settings_dev"
config = "website.settings.production" if PRODUCTION else "website.settings.local"
import importlib
try:
cfg = importlib.import_module(config)
Expand Down
34 changes: 8 additions & 26 deletions example/sqla/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
flask-social-blueprint>=0.7
Babel>=1.3
Flask>=0.10.1
Flask-Babel>=0.9
Flask-Login==0.2.11
Flask-Mail>=0.9.0
Flask-OAuth>=0.12
Flask-Principal>=0.4.0
Flask-Script>=2.0.5
Flask-Security>=1.7.2
Flask-WTF>=0.9.5
Jinja2>=2.7.2
MarkupSafe>=0.19
WTForms>=1.0.5
Werkzeug>=0.9.4
blinker>=1.3
Flask-Security>=1.7.5
Flask-Mail>=0.9.1
Flask-Script
Flask-SQLAlchemy
facebook-sdk>=0.4.0
google-api-python-client>=1.2
httplib2>=0.8
itsdangerous>=0.24
oauth2>=1.5.211
oauthlib>=0.6.1
passlib>=1.6.2
python-twitter>=1.3.1
pytz>=2014.2
requests>=2.2.1
requests-oauthlib>=0.4.0
simplejson>=3.5.2
speaklater>=1.3
python-twitter
PyOpenSSL
ndg-httpsclient
pyasn1

SQLAlchemy>=0.9.4
Flask-SQLAlchemy>=1.0

66 changes: 36 additions & 30 deletions example/sqla/tests.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
# coding=utf-8
# Created 2014 by Janusz Skonieczny
import logging
import os
import tempfile
import unittest
import flask_social_blueprint

from main import app
from website import database


class TestFlaskSocialBlueprint(unittest.TestCase):
def setUp(self):
self.db_fd, self.db_file = tempfile.mkstemp()
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///" + self.db_file
self.app = app.test_client()
with app.app_context():
database.init_db()

def tearDown(self):
os.close(self.db_fd)
os.unlink(self.db_file)

def test_login_redirect(self):
# simple smoke test
rv = self.app.get('/')
logging.debug("rv: %s" % rv.headers)
self.assertEqual(302, rv.status_code)
assert rv.headers.get('Location').startswith("http://localhost/login")
# coding=utf-8
# Created 2014 by Janusz Skonieczny
import logging
import os
import tempfile
import unittest
import flask_social_blueprint

from main import app
from website import database


class TestFlaskSocialBlueprint(unittest.TestCase):
def setUp(self):
self.db_fd, self.db_file = tempfile.mkstemp()
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///" + self.db_file
self.app = app.test_client()
with app.app_context():
database.init_db()

def tearDown(self):
os.close(self.db_fd)
os.unlink(self.db_file)

def test_root_requires_login(self):
# simple smoke test
rv = self.app.get('/')
logging.debug("rv: %s" % rv.headers)
self.assertEqual(302, rv.status_code)
assert rv.headers.get('Location').startswith("http://localhost/login")

def test_not_redirect_loop(self):
# simple smoke test
rv = self.app.get('/login')
logging.debug("rv: %s" % rv.headers)
self.assertEqual(200, rv.status_code)
Empty file.
File renamed without changes.
5 changes: 3 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# extra development dependencies
nose>=1.3.3
# extra development dependencies
nose>=1.3.7
pip>=7.1
2 changes: 1 addition & 1 deletion src/flask_social_blueprint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# coding=utf-8
# Copyright 2013 Janusz Skonieczny
__version__ = '0.7.1'
__version__ = '0.7.2'
7 changes: 6 additions & 1 deletion src/flask_social_blueprint/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from flask_login import login_user, current_user
from flask_security.utils import do_flash
from flask_babel import gettext as _
from flask_oauth import OAuthException

from werkzeug.exceptions import abort
from werkzeug.local import LocalProxy
Expand Down Expand Up @@ -39,7 +40,11 @@ def callback(self, provider):
Handles 3rd party callback and processes it's data
"""
provider = self.get_provider(provider)
return provider.authorized_handler(self.login)(provider=provider)
try:
return provider.authorized_handler(self.login)(provider=provider)
except OAuthException as ex:
logging.error("Data: %s", ex.data)
raise

def login(self, raw_data, provider):
logger.debug("raw_data: %s" % raw_data)
Expand Down
2 changes: 1 addition & 1 deletion src/flask_social_blueprint/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_profile(self, raw_data):
import facebook

graph = facebook.GraphAPI(access_token)
profile = graph.get_object("me?fields=email")
profile = graph.get_object("me", fields="email")
profile_id = profile['id']
data = {
"provider": "Facebook",
Expand Down
22 changes: 10 additions & 12 deletions src/flask_social_blueprint/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# coding=utf-8
# Created 2014 by Janusz Skonieczny
import os
import tempfile
import unittest
import flask_social_blueprint
import main

from main import app

class TestFlaskSocialBlueprint(unittest.TestCase):
pass
# coding=utf-8
# Created 2014 by Janusz Skonieczny
import os
import tempfile
import unittest
import flask_social_blueprint


class TestFlaskSocialBlueprint(unittest.TestCase):
pass

0 comments on commit 897f446

Please sign in to comment.