def test_get_token(self): """ OAuthSignIn.get_token() should return the oauth_token key in current session dict """ session['oauth_token'] = 'test token' self.assertEqual('test token', OAuthSignIn.get_token())
def test_get_twitter_user_data(self): test_id, test_name = '1234', 'marcanuy' oauth = OAuthSignIn.get_provider('twitter') data = {'user_id': test_id, 'screen_name': test_name} #session['oauth_token'] = 'test' user_data = oauth.get_user_data(data) self.assertEqual((test_id, test_name), user_data)
def test_get_user_creates_new_and_logs_in(self): # check user does not exists test_user_id = '1234' user = User.query.filter_by(twitter_user_id=test_user_id).first() self.assertIsNone(user) session['oauth_token'] = 'test' session['user_id'] = test_user_id session['screen_name'] = 'foobar' oauth = OAuthSignIn.get_provider('twitter') oauth.get_user() user = User.query.filter_by(twitter_user_id=test_user_id).first() self.assertTrue(user) self.assertTrue(current_user.is_authenticated)
def test_get_user_logins_in(self, get_mock): test_user_id = '1234' test_screen_name = 'foobar' user = User(twitter_user_id=test_user_id, twitter_screen_name=test_screen_name) db.session.add(user) db.session.commit() session['user_id'] = test_user_id session['screen_name'] = test_screen_name session['oauth_token'] = 'test' oauth = OAuthSignIn.get_provider('twitter') oauth.get_user() self.assertTrue(current_user.is_authenticated)
from dotenv import load_dotenv from flask import Flask from flask_login import LoginManager from flask_oauthlib.client import OAuth from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() login_manager = LoginManager() # connect to a remote application #oauth = OAuth() # import OAuthSign after initializing db from notificamesta.oauth.model import OAuthSignIn twitter = OAuthSignIn.get_provider('twitter') def create_app(env_type=None): app = Flask(__name__, instance_relative_config=True) load_config(app, env_type) db.init_app(app) load_blueprints(app) login_manager.init_app(app) # detect if we are just tweeting tuit = os.getenv('NOTIFICAMESTA_TUIT') if tuit=="True":
def test_get_session_data(self): oauth = OAuthSignIn.get_provider('twitter') data = {'oauth_token': 'test', 'oauth_token_secret': 'secret'} session_data = oauth.get_session_data(data) self.assertEqual(('test', 'secret'), session_data)
def test_authorized_response(self, authorized_response_mock): """ OauthSignIn.authorized_response() should return a dict """ authorized_response_mock.return_value = {'test': 'dict'} oauth = OAuthSignIn.get_provider('twitter') response = oauth.authorized_response() self.assertEqual({'test': 'dict'}, response)
def test_twitter_get_callback_url(self): oauth = OAuthSignIn.get_provider('twitter') self.assertEqual( url_for('oauth.authorized', provider='twitter', _external=True), oauth.get_callback_url())
def test_twitter_subclass(self): oauth = OAuthSignIn.get_provider('twitter') self.assertEqual('TwitterSignIn', oauth.__class__.__name__)