<s> from __future__ import unicode_literals <EOL> import pytest <EOL> import responses <EOL> from urlobject import URLObject <EOL> from flask import Flask <EOL> from flask_dance . contrib . facebook import make_facebook_blueprint , facebook <EOL> from flask_dance . consumer import OAuth2ConsumerBlueprint <EOL> from flask_dance . consumer . backend import MemoryBackend <EOL> def test_blueprint_factory ( ) : <EOL> facebook_bp = make_facebook_blueprint ( <EOL> client_id = "<STR_LIT:foo>" , <EOL> client_secret = "<STR_LIT:bar>" , <EOL> scope = "<STR_LIT>" , <EOL> redirect_to = "<STR_LIT:index>" , <EOL> ) <EOL> assert isinstance ( facebook_bp , OAuth2ConsumerBlueprint ) <EOL> assert facebook_bp . session . scope == "<STR_LIT>" <EOL> assert facebook_bp . session . base_url == "<STR_LIT>" <EOL> assert facebook_bp . session . client_id == "<STR_LIT:foo>" <EOL> assert facebook_bp . client_secret == "<STR_LIT:bar>" <EOL> assert facebook_bp . authorization_url == "<STR_LIT>" <EOL> assert facebook_bp . token_url == "<STR_LIT>" <EOL> def test_load_from_config ( ) : <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> facebook_bp = make_facebook_blueprint ( redirect_to = "<STR_LIT:index>" ) <EOL> app . register_blueprint ( facebook_bp ) <EOL> resp = app . test_client ( ) . get ( "<STR_LIT>" ) <EOL> url = resp . headers [ "<STR_LIT>" ] <EOL> client_id = URLObject ( url ) . query . dict . get ( "<STR_LIT>" ) <EOL> assert client_id == "<STR_LIT:foo>" <EOL> @ responses . activate <EOL> def test_context_local ( ) : <EOL> responses . add ( responses . GET , "<STR_LIT>" ) <EOL> app1 = Flask ( __name__ ) <EOL> fbbp1 = make_facebook_blueprint ( <EOL> "<STR_LIT>" , "<STR_LIT>" , redirect_to = "<STR_LIT>" , <EOL> backend = MemoryBackend ( { "<STR_LIT>" : "<STR_LIT>" } ) , <EOL> ) <EOL> app1 . register_blueprint ( fbbp1 ) <EOL> app2 = Flask ( __name__ ) <EOL> fbbp2 = make_facebook_blueprint ( <EOL> "<STR_LIT>" , "<STR_LIT>" , redirect_to = "<STR_LIT>" , <EOL> backend = MemoryBackend ( { "<STR_LIT>" : "<STR_LIT>" } ) , <EOL> ) <EOL> app2 . register_blueprint ( fbbp2 ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> facebook . get ( "<STR_LIT>" ) <EOL> with app1 . test_request_context ( "<STR_LIT:/>" ) : <EOL> app1 . preprocess_request ( ) <EOL> facebook . get ( "<STR_LIT>" ) <EOL> request = responses . calls [ <NUM_LIT:0> ] . request <EOL> assert request . headers [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> with app2 . test_request_context ( "<STR_LIT:/>" ) : <EOL> app2 . preprocess_request ( ) <EOL> facebook . get ( "<STR_LIT>" ) <EOL> request = responses . calls [ <NUM_LIT:1> ] . request <EOL> assert request . headers [ "<STR_LIT>" ] == "<STR_LIT>" </s>
