def test_context_local(): responses.add(responses.GET, "https://google.com") # set up two apps with two different set of auth tokens app1 = Flask(__name__) zoho_bp1 = make_zoho_blueprint( "foo1", "bar1", redirect_to="url1", backend=MemoryBackend({"access_token": "app1"}), ) app1.register_blueprint(zoho_bp1) app2 = Flask(__name__) zoho_bp2 = make_zoho_blueprint( "foo2", "bar2", redirect_to="url2", backend=MemoryBackend({"access_token": "app2"}), ) app2.register_blueprint(zoho_bp2) # outside of a request context, referencing functions on the `zoho` object # will raise an exception with pytest.raises(RuntimeError): zoho.get("https://google.com") # inside of a request context, `zoho` should be a proxy to the correct # blueprint session with app1.test_request_context("/"): app1.preprocess_request() zoho.get("https://google.com") request = responses.calls[0].request assert request.headers["Authorization"] == "Zoho-oauthtoken app1" with app2.test_request_context("/"): app2.preprocess_request() zoho.get("https://google.com") request = responses.calls[1].request assert request.headers["Authorization"] == "Zoho-oauthtoken app2"
def test_blueprint_factory(): zoho_bp = make_zoho_blueprint(client_id="foobar", client_secret="supersecret") assert isinstance(zoho_bp, OAuth2ConsumerBlueprint) assert zoho_bp.session.client_id == "foobar" assert zoho_bp.client_secret == "supersecret" assert zoho_bp.token_url == "https://accounts.zoho.com/oauth/v2/token" assert zoho_bp.authorization_url == "https://accounts.zoho.com/oauth/v2/auth"
def test_load_from_config(): app = Flask(__name__) app.secret_key = "anything" app.config["ZOHO_OAUTH_CLIENT_ID"] = "foo" app.config["ZOHO_OAUTH_CLIENT_SECRET"] = "bar" zoho_bp = make_zoho_blueprint() app.register_blueprint(zoho_bp) resp = app.test_client().get("/zoho") url = resp.headers["Location"] client_id = URLObject(url).query.dict.get("client_id") assert client_id == "foo"
from flask import Flask, url_for from werkzeug.contrib.fixers import ProxyFix from flask_sqlalchemy import SQLAlchemy from flask_admin import Admin from flask_admin import helpers as admin_helpers from flask_security import Security, SQLAlchemyUserDatastore from flask_dance.contrib.zoho import make_zoho_blueprint app = Flask(__name__) app.config.from_object(os.environ['APP_SETTINGS']) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.wsgi_app = ProxyFix(app.wsgi_app) db = SQLAlchemy(app) zoho_bp = make_zoho_blueprint( offline=True, scope= "ZohoCRM.modules.ALL,ZohoCRM.settings.all,ZohoCRM.org.all,ZohoCRM.users.all", ) app.register_blueprint(zoho_bp, url_prefix='/login') # Imports needed for Admin view but after app init from webapp.admin_model_view import AdminModelView, ParseAdminIndexView, SettingsView from webapp.models import Email, Lead, User, Role admin = Admin(app, name='parseLeads', index_view=ParseAdminIndexView(), base_template='master_admin.html', template_mode='bootstrap3') admin.add_view(AdminModelView(User, db.session)) admin.add_view(AdminModelView(Role, db.session))
def _make_app(*args, **kwargs): app = Flask(__name__) app.secret_key = "whatever" blueprint = make_zoho_blueprint(*args, **kwargs) app.register_blueprint(blueprint) return app