コード例 #1
0
ファイル: app.py プロジェクト: madeleine789/eventboard
	'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



コード例 #2
0
ファイル: app.py プロジェクト: madeleine789/sius-eventboard
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',
    authorize_url='https://api.twitter.com/oauth/authenticate',
    consumer_key=app.config['TWITTER_CONSUMER_KEY'],
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,'')
コード例 #4
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, '')