예제 #1
0
    def create_app(self):
        app = Flask(__name__)
        app.config['TESTING'] = True
        app.config['CACHE_TYPE'] = 'simple'
        app.config['TWITTER_CONSUMER_KEY'] = 'twitter_consumer_key'
        app.config['TWITTER_CONSUMER_SECRET'] = 'twitter_consumer_secret'
        app.config['TWITTER_ACCESS_TOKEN'] = 'twitter_access_token'
        app.config['TWITTER_TOKEN_SECRET'] = 'twitter_token_secret'
        self.cache = Cache(app)
        self.twitter_oembedder = TwitterOEmbedder(app, self.cache)

        @app.route('/')
        def index():
            return render_template_string('')

        return app
    def create_app(self):
        app = Flask(__name__)
        app.config['TESTING']=True
        app.config['CACHE_TYPE'] = 'simple'
        app.config['TWITTER_CONSUMER_KEY'] = 'twitter_consumer_key'
        app.config['TWITTER_CONSUMER_SECRET'] = 'twitter_consumer_secret'
        app.config['TWITTER_ACCESS_TOKEN'] = 'twitter_access_token'
        app.config['TWITTER_TOKEN_SECRET'] = 'twitter_token_secret'
        self.cache = Cache(app)
        self.twitter_oembedder = TwitterOEmbedder(app,self.cache)

        @app.route('/')
        def index():
            return render_template_string('')

        return app
예제 #3
0
	'host':'mongodb://*****:*****@ds029317.mongolab.com:29317/eventboard'
}

app.config['THREADS_PER_PAGE'] = 4
app.config['CSRF_ENABLED'] = True
app.config['SECRET_KEY'] = 'you-will-never-know'

app.config['TWITTER_CONSUMER_KEY'] = 'IRh7xn4AZfryNrsXQI3hXNIPu'
app.config['TWITTER_CONSUMER_SECRET'] = 'YhJ0JWYoS7am327ST6PQVkdxmbkvI10A5dIzJs3xv5FWNrgDjV'
app.config['TWITTER_ACCESS_TOKEN'] = '3305385699-0WEBODjVEuMn48QaK80hPCkA7xTJGNk2CU21YSc'
app.config['TWITTER_TOKEN_SECRET'] = 'g8cgsMCNtx8cohb3tNccJX2gEaKZ9u8QcqY1a8wKV7SiK'


db = MongoEngine(app)
app.session_interface = MongoEngineSessionInterface(db)

twitter_oembedder = TwitterOEmbedder()
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
twitter_oembedder.init(app, cache)

flask_bcrypt = Bcrypt(app)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.refresh_view = 'auth_app.login'

app.debug = True



예제 #4
0
파일: app.py 프로젝트: henryj885/flock
from flask_sqlalchemy import SQLAlchemy
from flask.ext.cache import Cache
from flask.ext.twitter_oembedder import TwitterOEmbedder
from flask.ext.iniconfig import INIConfig
from flask.ext.sqlalchemy import get_debug_queries
from flask_humanize import Humanize
from flask_debugtoolbar import DebugToolbarExtension

from flock.model import metadata


cache = Cache()
db = SQLAlchemy(metadata=metadata)
ini_config = INIConfig()
twitter_oembedder = TwitterOEmbedder()
humanise = Humanize()
toolbar = DebugToolbarExtension()


def url_for_other_page(page):
    return restricted_url(_page=page)


def restricted_url(endpoint=None, **kwargs):
    if endpoint is None:
        endpoint = request.endpoint

    if endpoint == request.endpoint:
        args = request.view_args.copy()
    else:
class FlaskStaticTest(TestCase):
    def create_app(self):
        app = Flask(__name__)
        app.config['TESTING']=True
        app.config['CACHE_TYPE'] = 'simple'
        app.config['TWITTER_CONSUMER_KEY'] = 'twitter_consumer_key'
        app.config['TWITTER_CONSUMER_SECRET'] = 'twitter_consumer_secret'
        app.config['TWITTER_ACCESS_TOKEN'] = 'twitter_access_token'
        app.config['TWITTER_TOKEN_SECRET'] = 'twitter_token_secret'
        self.cache = Cache(app)
        self.twitter_oembedder = TwitterOEmbedder(app,self.cache)

        @app.route('/')
        def index():
            return render_template_string('')

        return app


    def test_big_timeout_exception(self):
        try:
            self.twitter_oembedder.init(self.app,
                                        self.cache,
                                        timeout=60*60*24*365*2)
            assert False
        except Exception as e:
            self.assertIsInstance(e,Exception)

    def test_jinja_oembed_tweet_avaliable(self):
        response = self.client.get('/')
        self.assertIsInstance(self.get_context_variable('oembed_tweet'), types.FunctionType)

    @httpretty.activate
    def test_oembed_tweet_valid_id_debug_off(self):
        with open('tests/data/99530515043983360.json') as f:
            httpretty.register_uri(httpretty.GET, 'https://api.twitter.com/1.1/statuses/oembed.json?id=99530515043983360',
                body = f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        valid = oembed_tweet('99530515043983360')
        self.assertIsInstance(valid, Markup)

    @httpretty.activate
    def test_oembed_tweet_invaild_id_debug_off(self):
        with open('tests/data/abc.json') as f:
            httpretty.register_uri(httpretty.GET, 'https://api.twitter.com/1.1/statuses/oembed.json?id=abc',
                body = f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        invalid = oembed_tweet('abc')
        self.assertIs(invalid,'')

    @httpretty.activate
    def test_oembed_tweet_invalid_id_debug_on(self):
        self.twitter_oembedder.init(self.app, self.cache, debug=True)
        with open('tests/data/abc.json') as f:
            httpretty.register_uri(httpretty.GET, 'https://api.twitter.com/1.1/statuses/oembed.json?id=abc',
                body = f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        try:
            invalid = oembed_tweet('abc')
            assert False
        except Exception as e:
            self.assertIsInstance(e, KeyError)

    @httpretty.activate
    def test_oembed_tweet_valid_id_app_debug_on(self):
        self.app.config['DEBUG'] = True
        self.twitter_oembedder.init(self.app, self.cache)
        with open('tests/data/99530515043983360.json') as f:
            httpretty.register_uri(httpretty.GET, 'https://api.twitter.com/1.1/statuses/oembed.json?id=99530515043983360',
                body = f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        valid = oembed_tweet('99530515043983360')
        self.assertIsInstance(valid, Markup)

    @httpretty.activate
    def test_oembed_tweet_invalid_id_app_debug_on(self):
        self.app.config['DEBUG'] = True
        self.twitter_oembedder.init(self.app, self.cache)
        with open('tests/data/abc.json') as f:
            httpretty.register_uri(httpretty.GET, 'https://api.twitter.com/1.1/statuses/oembed.json?id=abc',
                body = f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        try:
            invalid = oembed_tweet('abc')
            assert False
        except Exception as e:
            self.assertIsInstance(e, KeyError)

    @httpretty.activate
    def test_oembed_tweet_valid_id_app_debug_on_override(self):
        self.app.config['DEBUG'] = True
        self.twitter_oembedder.init(self.app, self.cache, debug=False)
        with open('tests/data/99530515043983360.json') as f:
            httpretty.register_uri(httpretty.GET, 'https://api.twitter.com/1.1/statuses/oembed.json?id=99530515043983360',
                body = f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        valid = oembed_tweet('99530515043983360')
        self.assertIsInstance(valid, Markup)

    @httpretty.activate
    def test_oembed_tweet_invalid_id_app_debug_on_override(self):
        self.app.config['DEBUG'] = True
        self.twitter_oembedder.init(self.app, self.cache, debug=False)
        with open('tests/data/abc.json') as f:
            httpretty.register_uri(httpretty.GET, 'https://api.twitter.com/1.1/statuses/oembed.json?id=abc',
                body = f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        invalid = oembed_tweet('abc')
        self.assertIs(invalid,'')
예제 #6
0
from fetch_top_tweets import fetch_top_tweets
from fetch_all_tweets import fetch_all_tweets
from update_retweets import update_retweets
from insert_user import insert_user
from validate_user import validate_user
from insert_preferences import insert_preferences
from get_preferences import get_preferences
import requests
import json
import datetime
app = Flask(__name__)
app.config.from_object(__name__)
app.secret_key = 'any random string'

cache = Cache(app, config={'CACHE_TYPE': 'simple'})
twitter_oembedder = TwitterOEmbedder(app, cache, debug=True)
app.config['TWITTER_CONSUMER_KEY'] = 'FrTtImImzPxthrIjkTFrsUatY'
app.config[
    'TWITTER_CONSUMER_SECRET'] = 'cbPq4hNVEIj87LKcnP4XgCPAdPVc0By8ZVKH7WWVE5H9FS6ihb'
app.config[
    'TWITTER_ACCESS_TOKEN'] = '635902588-6BuJRUYxXQ63vfmQYcP7auLAjkTgxaCRz70MwP5x'
app.config[
    'TWITTER_TOKEN_SECRET'] = 'YsLyHMKLoUl47cCge1sBb7KfjDhg2wBbjWhBWm4VVOXtd'


@app.route('/')
#@app.route('/teams/')
def home():

    if 'key' in session:
        return render_template('home.html', email=session['key'])
예제 #7
0
app.config['THREADS_PER_PAGE'] = 4
app.config['CSRF_ENABLED'] = True
app.config['SECRET_KEY'] = 'you-will-never-know'

app.config['TWITTER_CONSUMER_KEY'] = 'IRh7xn4AZfryNrsXQI3hXNIPu'
app.config[
    'TWITTER_CONSUMER_SECRET'] = 'YhJ0JWYoS7am327ST6PQVkdxmbkvI10A5dIzJs3xv5FWNrgDjV'
app.config[
    'TWITTER_ACCESS_TOKEN'] = '3305385699-0WEBODjVEuMn48QaK80hPCkA7xTJGNk2CU21YSc'
app.config[
    'TWITTER_TOKEN_SECRET'] = 'g8cgsMCNtx8cohb3tNccJX2gEaKZ9u8QcqY1a8wKV7SiK'

db = MongoEngine(app)
app.session_interface = MongoEngineSessionInterface(db)

twitter_oembedder = TwitterOEmbedder()
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
twitter_oembedder.init(app, cache)

flask_bcrypt = Bcrypt(app)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.refresh_view = 'auth_app.login'

oauth = OAuth()
twitter = oauth.remote_app(
    'twitter',
    base_url='https://api.twitter.com/1/',
    request_token_url='https://api.twitter.com/oauth/request_token',
    access_token_url='https://api.twitter.com/oauth/access_token',
예제 #8
0
class FlaskStaticTest(TestCase):
    def create_app(self):
        app = Flask(__name__)
        app.config['TESTING'] = True
        app.config['CACHE_TYPE'] = 'simple'
        app.config['TWITTER_CONSUMER_KEY'] = 'twitter_consumer_key'
        app.config['TWITTER_CONSUMER_SECRET'] = 'twitter_consumer_secret'
        app.config['TWITTER_ACCESS_TOKEN'] = 'twitter_access_token'
        app.config['TWITTER_TOKEN_SECRET'] = 'twitter_token_secret'
        self.cache = Cache(app)
        self.twitter_oembedder = TwitterOEmbedder(app, self.cache)

        @app.route('/')
        def index():
            return render_template_string('')

        return app

    def test_big_timeout_exception(self):
        try:
            self.twitter_oembedder.init(self.app,
                                        self.cache,
                                        timeout=60 * 60 * 24 * 365 * 2)
            assert False
        except Exception as e:
            self.assertIsInstance(e, Exception)

    def test_jinja_oembed_tweet_avaliable(self):
        response = self.client.get('/')
        self.assertIsInstance(self.get_context_variable('oembed_tweet'),
                              types.FunctionType)

    @httpretty.activate
    def test_oembed_tweet_valid_id_debug_off(self):
        with open('tests/data/99530515043983360.json') as f:
            httpretty.register_uri(
                httpretty.GET,
                'https://api.twitter.com/1.1/statuses/oembed.json?id=99530515043983360',
                body=f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        valid = oembed_tweet('99530515043983360')
        self.assertIsInstance(valid, Markup)

    @httpretty.activate
    def test_oembed_tweet_invaild_id_debug_off(self):
        with open('tests/data/abc.json') as f:
            httpretty.register_uri(
                httpretty.GET,
                'https://api.twitter.com/1.1/statuses/oembed.json?id=abc',
                body=f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        invalid = oembed_tweet('abc')
        self.assertIs(invalid, '')

    @httpretty.activate
    def test_oembed_tweet_invalid_id_debug_on(self):
        self.twitter_oembedder.init(self.app, self.cache, debug=True)
        with open('tests/data/abc.json') as f:
            httpretty.register_uri(
                httpretty.GET,
                'https://api.twitter.com/1.1/statuses/oembed.json?id=abc',
                body=f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        try:
            invalid = oembed_tweet('abc')
            assert False
        except Exception as e:
            self.assertIsInstance(e, KeyError)

    @httpretty.activate
    def test_oembed_tweet_valid_id_app_debug_on(self):
        self.app.config['DEBUG'] = True
        self.twitter_oembedder.init(self.app, self.cache)
        with open('tests/data/99530515043983360.json') as f:
            httpretty.register_uri(
                httpretty.GET,
                'https://api.twitter.com/1.1/statuses/oembed.json?id=99530515043983360',
                body=f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        valid = oembed_tweet('99530515043983360')
        self.assertIsInstance(valid, Markup)

    @httpretty.activate
    def test_oembed_tweet_invalid_id_app_debug_on(self):
        self.app.config['DEBUG'] = True
        self.twitter_oembedder.init(self.app, self.cache)
        with open('tests/data/abc.json') as f:
            httpretty.register_uri(
                httpretty.GET,
                'https://api.twitter.com/1.1/statuses/oembed.json?id=abc',
                body=f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        try:
            invalid = oembed_tweet('abc')
            assert False
        except Exception as e:
            self.assertIsInstance(e, KeyError)

    @httpretty.activate
    def test_oembed_tweet_valid_id_app_debug_on_override(self):
        self.app.config['DEBUG'] = True
        self.twitter_oembedder.init(self.app, self.cache, debug=False)
        with open('tests/data/99530515043983360.json') as f:
            httpretty.register_uri(
                httpretty.GET,
                'https://api.twitter.com/1.1/statuses/oembed.json?id=99530515043983360',
                body=f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        valid = oembed_tweet('99530515043983360')
        self.assertIsInstance(valid, Markup)

    @httpretty.activate
    def test_oembed_tweet_invalid_id_app_debug_on_override(self):
        self.app.config['DEBUG'] = True
        self.twitter_oembedder.init(self.app, self.cache, debug=False)
        with open('tests/data/abc.json') as f:
            httpretty.register_uri(
                httpretty.GET,
                'https://api.twitter.com/1.1/statuses/oembed.json?id=abc',
                body=f.read())
        response = self.client.get('/')
        oembed_tweet = self.get_context_variable('oembed_tweet')
        invalid = oembed_tweet('abc')
        self.assertIs(invalid, '')