示例#1
0
    def test_all_configurations(self):
        backend = mock.Mock()

        self.app.config.update({
            "PUSHER_SSL": False,
            "PUSHER_TIMEOUT": 3,
            "PUSHER_CLUSTER": "eu",
            "PUSHER_BACKEND": backend,
            "PUSHER_BACKEND_OPTIONS": {
                "anything": True
            },
            "PUSHER_NOTIFICATION_HOST": "example.com",
            "PUSHER_NOTIFICATION_SSL": True,
        })
        pusher = Pusher(self.app)
        with self.app.test_request_context():
            self.assertIsNotNone(pusher.client)

            if "ssl" in argspec.args:
                self.assertFalse(pusher.client.ssl)

            if "timeout" in argspec.args:
                self.assertEqual(3, pusher.client.timeout)

            if "cluster" in argspec.args:
                self.assertEqual("api-eu.pusher.com", pusher.client.host)

            if "backend" in argspec.args:
                self.assertTrue(backend.called)

            if argspec.keywords == "backend_options":
                self.assertTrue(backend.call_args[1]["anything"])
示例#2
0
 def test_configuration(self):
     self.app.config["PUSHER_HOST"] = "example.com"
     self.app.config["PUSHER_PORT"] = 8080
     pusher = Pusher(self.app)
     with self.app.test_request_context():
         self.assertIsNotNone(pusher.client)
         self.assertEqual("KEY", pusher.client.key)
         self.assertEqual("SUPERSECRET", pusher.client.secret)
         self.assertEqual("example.com", pusher.client.host)
         self.assertEqual(8080, pusher.client.port)
示例#3
0
    def setUp(self):
        self.app = Flask(__name__)
        self.app.debug = True
        self.app.config.update(pusher_conf)
        self.pusher = Pusher()
        self.client = self.app.test_client()
        self._called = False

        @self.pusher.webhooks.client
        def c():
            self._called = True

        self.pusher.init_app(self.app)
示例#4
0
    def test_json_encoder(self):
        if not _json_encoder_support:
            msg = u"JSON encoder override is not supported on pusher>=1.0,<1.1"
            self.skipTest(msg)

        self.app.json_encoder = CustomJSONEncoder
        pusher = Pusher(self.app)

        with self.app.test_request_context():
            try:
                enc = pusher.client._json_encoder
            except AttributeError:
                enc = pusher.client.encoder
        self.assertEqual(CustomJSONEncoder, enc)
示例#5
0
from contextlib import redirect_stdout
from time import sleep

import subprocess
import os
import sys  

from qa.question_answering import answer_question

app_id = "960906"
key = "d18ed2e42cf337876806"
secret = "ffd3ef254ef8617ab31a"
cluster = "us2"

app = Flask(__name__)
pusher = Pusher(app, secret = secret, app_id = app_id, key = key, cluster = cluster)


app.secret_key = 'secret key'
CORS(app)

UPLOAD_FOLDER = './data_upload'
ALLOWED_EXTENSIONS = {'json'}
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

def write_to_pusher(message):
    
    if isinstance(message, bytes):
        message = message.decode('utf-8')
    
    messages = message.split('\n')
示例#6
0
 def test_create_extensions_map(self):
     del self.app.extensions
     pusher = Pusher(self.app)
     with self.app.test_request_context():
         self.assertIsNotNone(pusher.client)
示例#7
0
 def test_lazy_init_app(self):
     pusher = Pusher()
     pusher.init_app(self.app)
     with self.app.test_request_context():
         self.assertIsNotNone(pusher.client)
示例#8
0
 def test_default_config(self):
     # fallback to Pusher globals still works
     pusher = Pusher(self.app)
     with self.app.test_request_context():
         self.assertIsNotNone(pusher.client)
示例#9
0
 def setUp(self):
     self.app = Flask(__name__)
     self.app.debug = True
     self.app.config.update(pusher_conf)
     self.pusher = Pusher(self.app)
     self.client = self.app.test_client()
示例#10
0
 def test_pusher_key_in_template(self):
     Pusher(self.app)
     with self.app.test_request_context():
         rendered = render_template_string("{{ PUSHER_KEY }}")
         self.assertEqual("KEY", rendered)
示例#11
0
from flask import Flask
from config import Config
from flask_cors import CORS
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_mail import Mail
from flask_pusher import Pusher

cors = CORS()
db = SQLAlchemy()
migrate = Migrate()
login = LoginManager()
login.login_view = 'auth.login'
mail = Mail()
pusher = Pusher()


def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)

    cors.init_app(app, resources={r"/api/*": {"origins": "*"}})
    db.init_app(app)
    migrate.init_app(app, db)
    login.init_app(app)
    mail.init_app(app)
    pusher.init_app(app)

    from app.auth import bp as auth_bp
    app.register_blueprint(auth_bp, url_prefix='/auth')
示例#12
0
#TODO: find out if this is bad
server_session.app.session_interface.db.create_all()
login_manager = LoginManager()
login_manager.init_app(app)

#pusher credentials configuration
app.config['PUSHER_APP_ID'] = os.environ['PUSHER_APP_ID']
app.config['PUSHER_KEY'] = os.environ['PUSHER_KEY']
app.config['PUSHER_CLUSTER'] = os.environ['PUSHER_CLUSTER']
app.config['PUSHER_SECRET'] = os.environ['PUSHER_SECRET']
app.config['PUSHER_SSL'] = False
#pusher server location configuration
if 'PUSHER_HOST' in os.environ and 'PUSHER_PORT' in os.environ:
    app.config['PUSHER_HOST'] = os.environ['PUSHER_HOST']
    app.config['PUSHER_PORT'] = int(os.environ['PUSHER_PORT'])

pusher = Pusher(app)


#This is here to avoid weird authentication bypasses.
#TODO: get rid of pusher-flask, use the official python library instead
@pusher.auth
def pusher_auth(channel_name, socket_id):
    return False


# initialize the api blueprint
from .api_views import api
app.register_blueprint(api, url_prefix='/api/v1/')