<s> from __future__ import unicode_literals <EOL> import pytest <EOL> import mock <EOL> import responses <EOL> from flask import Flask <EOL> from flask_dance . contrib . twitter import make_twitter_blueprint , twitter <EOL> from flask_dance . consumer import OAuth1ConsumerBlueprint <EOL> from oauthlib . oauth1 . rfc5849 . utils import parse_authorization_header <EOL> def test_blueprint_factory ( ) : <EOL> twitter_bp = make_twitter_blueprint ( <EOL> api_key = "<STR_LIT>" , <EOL> api_secret = "<STR_LIT>" , <EOL> redirect_to = "<STR_LIT:index>" , <EOL> ) <EOL> assert isinstance ( twitter_bp , OAuth1ConsumerBlueprint ) <EOL> assert twitter_bp . session . base_url == "<STR_LIT>" <EOL> assert twitter_bp . session . auth . client . client_key == "<STR_LIT>" <EOL> assert twitter_bp . session . auth . client . client_secret == "<STR_LIT>" <EOL> assert twitter_bp . request_token_url == "<STR_LIT>" <EOL> assert twitter_bp . access_token_url == "<STR_LIT>" <EOL> assert twitter_bp . authorization_url == "<STR_LIT>" <EOL> @ responses . activate <EOL> def test_load_from_config ( ) : <EOL> responses . add ( <EOL> responses . POST , <EOL> "<STR_LIT>" , <EOL> body = "<STR_LIT>" , <EOL> ) <EOL> app = Flask ( __name__ ) <EOL> app . secret_key = "<STR_LIT>" <EOL> app . config [ "<STR_LIT>" ] = "<STR_LIT:foo>" <EOL> app . config [ "<STR_LIT>" ] = "<STR_LIT:bar>" <EOL> twitter_bp = make_twitter_blueprint ( redirect_to = "<STR_LIT:index>" ) <EOL> app . register_blueprint ( twitter_bp ) <EOL> app . test_client ( ) . get ( "<STR_LIT>" ) <EOL> auth_header = dict ( parse_authorization_header ( <EOL> responses . calls [ <NUM_LIT:0> ] . request . headers [ '<STR_LIT>' ] . decode ( '<STR_LIT:utf-8>' ) <EOL> ) ) <EOL> assert auth_header [ "<STR_LIT>" ] == "<STR_LIT:foo>" <EOL> @ responses . activate <EOL> def test_context_local ( ) : <EOL> responses . add ( responses . GET , "<STR_LIT>" ) <EOL> app1 = Flask ( __name__ ) <EOL> tbp1 = make_twitter_blueprint ( "<STR_LIT>" , "<STR_LIT>" , redirect_to = "<STR_LIT>" ) <EOL> app1 . register_blueprint ( tbp1 ) <EOL> app2 = Flask ( __name__ ) <EOL> tbp2 = make_twitter_blueprint ( "<STR_LIT>" , "<STR_LIT>" , redirect_to = "<STR_LIT>" ) <EOL> app2 . register_blueprint ( tbp2 ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> twitter . get ( "<STR_LIT>" ) <EOL> with app1 . test_request_context ( "<STR_LIT:/>" ) : <EOL> tbp1 . session . auth . client . get_oauth_signature = mock . Mock ( return_value = "<STR_LIT>" ) <EOL> tbp2 . session . auth . client . get_oauth_signature = mock . Mock ( return_value = "<STR_LIT>" ) <EOL> app1 . preprocess_request ( ) <EOL> twitter . get ( "<STR_LIT>" ) <EOL> auth_header = dict ( parse_authorization_header ( <EOL> responses . calls [ <NUM_LIT:0> ] . request . headers [ '<STR_LIT>' ] . decode ( '<STR_LIT:utf-8>' ) <EOL> ) ) <EOL> assert auth_header [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> assert auth_header [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> with app2 . test_request_context ( "<STR_LIT:/>" ) : <EOL> tbp1 . session . auth . client . get_oauth_signature = mock . Mock ( return_value = "<STR_LIT>" ) <EOL> tbp2 . session . auth . client . get_oauth_signature = mock . Mock ( return_value = "<STR_LIT>" ) <EOL> app2 . preprocess_request ( ) <EOL> twitter . get ( "<STR_LIT>" ) <EOL> auth_header = dict ( parse_authorization_header ( <EOL> responses . calls [ <NUM_LIT:1> ] . request . headers [ '<STR_LIT>' ] . decode ( '<STR_LIT:utf-8>' ) <EOL> ) ) <EOL> assert auth_header [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> assert auth_header [ "<STR_LIT>" ] == "<STR_LIT>" </s>
