Exemplo n.º 1
0
    def setUp(self):
        # create a WSGI application.
        app = webapp2.WSGIApplication(config=config.webapp2_config)
        routes.add_routes(app)
        self.testapp = webtest.TestApp(
            app, extra_environ={'REMOTE_ADDR': '127.0.0.1'})

        # activate GAE stubs
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()

        # some shortcuts
        self.cookie_name = config.webapp2_config['webapp2_extras.auth'][
            'cookie_name']
        self.headers = {'User-Agent': 'Safari', 'Accept-Language': 'en_US'}

        # register test account
        self.testapp.post('/register/',
                          forms.RegisterForm(username='******',
                                             password='******',
                                             c_password='******',
                                             email='*****@*****.**',
                                             country='').data,
                          headers=self.headers)

        # is test account created?
        users = models.User.query().fetch(2)
        self.assertEqual(1, len(users), 'testuser could not register')
        self.user = users[0]

        # clear cookies
        self.testapp.reset()
Exemplo n.º 2
0
    def setUp(self):

        # create a WSGI application.
        webapp2_config = boilerplate_config.config
        webapp2_config.update(config.config)
        self.app = webapp2.WSGIApplication(config=webapp2_config)
        routes.add_routes(self.app)
        boilerplate_routes.add_routes(self.app)
        self.testapp = webtest.TestApp(self.app, extra_environ={'REMOTE_ADDR' : '127.0.0.1'})
        
        # use absolute path for templates
        self.app.config['webapp2_extras.jinja2']['template_path'] =  [os.path.join(os.path.dirname(boilerplate.__file__), '../templates'), os.path.join(os.path.dirname(boilerplate.__file__), 'templates')]

        # activate GAE stubs
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()
        self.testbed.init_taskqueue_stub()
        self.testbed.init_mail_stub()
        self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
        self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
        self.testbed.init_user_stub()

        self.headers = {'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) Version/6.0 Safari/536.25',
                        'Accept-Language' : 'en_US'}

        # fix configuration if this is still a raw boilerplate code - required by test with mails
        if not utils.is_email_valid(self.app.config.get('contact_sender')):
            self.app.config['contact_sender'] = "*****@*****.**"
        if not utils.is_email_valid(self.app.config.get('contact_recipient')):
            self.app.config['contact_recipient'] = "*****@*****.**"
Exemplo n.º 3
0
    def setUp(self):
        
        # fix configuration if this is still a raw boilerplate code - required by tests with mails
        if not utils.is_email_valid(config.contact_sender):
            config.contact_sender = "*****@*****.**"
        if not utils.is_email_valid(config.contact_recipient):
            config.contact_recipient = "*****@*****.**"

        # create a WSGI application.
        w2config = config.webapp2_config
        # use absolute path for templates
        w2config['webapp2_extras.jinja2']['template_path'] =  os.path.join(os.path.join(os.path.dirname(web.__file__), '..'), 'templates')
        self.app = webapp2.WSGIApplication(config=w2config)
        routes.add_routes(self.app)
        self.testapp = webtest.TestApp(self.app, extra_environ={'REMOTE_ADDR' : '127.0.0.1'})

        # activate GAE stubs
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()
        self.testbed.init_taskqueue_stub()
        self.testbed.init_mail_stub()
        self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
        self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
        self.testbed.init_user_stub()
        
        self.headers = {'User-Agent' : 'Safari', 'Accept-Language' : 'en_US'}
Exemplo n.º 4
0
    def setUp(self):

        # fix configuration if this is still a raw boilerplate code - required by tests with mails
        if not utils.is_email_valid(config.contact_sender):
            config.contact_sender = "*****@*****.**"
        if not utils.is_email_valid(config.contact_recipient):
            config.contact_recipient = "*****@*****.**"

        # create a WSGI application.
        w2config = config.webapp2_config
        # use absolute path for templates
        w2config["webapp2_extras.jinja2"]["template_path"] = os.path.join(
            os.path.join(os.path.dirname(web.__file__), ".."), "templates"
        )
        self.app = webapp2.WSGIApplication(config=w2config)
        routes.add_routes(self.app)
        self.testapp = webtest.TestApp(self.app, extra_environ={"REMOTE_ADDR": "127.0.0.1"})

        # activate GAE stubs
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()
        self.testbed.init_taskqueue_stub()
        self.testbed.init_mail_stub()
        self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
        self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
        self.testbed.init_user_stub()

        self.headers = {"User-Agent": "Safari", "Accept-Language": "en_US"}
Exemplo n.º 5
0
def create_app(armazenamento=None):
    app = Flask(__name__, static_folder=static_folder)
    app.config.update({
        'SECRET_KEY': 'MySecretIsMyPasswordBlaBla',
        'TESTING': True,
        'DEBUG': True,
        'SQLALCHEMY_DATABASE_URI': openid_db,
        'OIDC_CLIENT_SECRETS': 'client_secrets.json',
        'OIDC_ID_TOKEN_COOKIE_SECURE': False,
        'OIDC_REQUIRE_VERIFIED_EMAIL': False,
        'OIDC_OPENID_REALM': uri + '/oidc_callback'
    })

    CORS(app)
    Compress(app)
    print("app criado.")

    from db import create_db
    db = create_db()
    db.init_app(app)

    oidc = OpenIDConnect(app, armazenamento)
    add_routes(app, oidc)

    return app
Exemplo n.º 6
0
def create_app(test=False):
    app = Flask(__name__)
    CORS(app)

    # TODO user urandom to generate this
    app.secret_key = 'super secret key'

    config = configparser.ConfigParser()
    config.read('config.ini')
    if test:
        if os.environ.get('TEST_DATABASE_URL') is None:
            database_uri = config['database']['sqlalchemy.test.url']
        else:
            database_uri = os.environ.get('TEST_DATABASE_URL')
    else:
        if os.environ.get('DATABASE_URL') is None:
            database_uri = config['database']['sqlalchemy.url']
        else:
            database_uri = os.environ.get('DATABASE_URL')

    app.config['SQLALCHEMY_DATABASE_URI'] = database_uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['TESTING'] = test
    app.config['LOGIN_DISABLED'] = test
    app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False

    add_routes(app)

    db.init_app(app)
    db.create_all(app=app)

    return app
Exemplo n.º 7
0
    def setUp(self):
        # create a WSGI application.
        app = webapp2.WSGIApplication(config=config.webapp2_config)
        routes.add_routes(app)
        self.testapp = webtest.TestApp(app, extra_environ={'REMOTE_ADDR' : '127.0.0.1'})

        # activate GAE stubs
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()

        # some shortcuts
        self.cookie_name=config.webapp2_config['webapp2_extras.auth']['cookie_name']
        self.headers = {'User-Agent' : 'Safari', 'Accept-Language' : 'en_US'}
        
        # register test account
        self.testapp.post('/register/',
                        forms.RegisterForm(username='******', password='******',
                            c_password='******', email='*****@*****.**', country='').data,
                        headers=self.headers)
        
        # is test account created?
        users = models.User.query().fetch(2)
        self.assertEqual(1, len(users), 'testuser could not register')
        self.user = users[0]

        # clear cookies
        self.testapp.reset()
Exemplo n.º 8
0
	def setUp(self):

		# create a WSGI application.
		webapp2_config = config.config
		self.app = webapp2.WSGIApplication(config=webapp2_config)
		routes.add_routes(self.app)
		boilerplate_routes.add_routes(self.app)
		self.testapp = webtest.TestApp(self.app, extra_environ={'REMOTE_ADDR' : '127.0.0.1'})

		# # use absolute path for templates
		# self.app.config['webapp2_extras.jinja2']['template_path'] =	 ['/templates']

		# activate GAE stubs
		self.testbed = testbed.Testbed()
		self.testbed.activate()
		self.testbed.init_datastore_v3_stub()
		self.testbed.init_memcache_stub()
		self.testbed.init_urlfetch_stub()
		self.testbed.init_taskqueue_stub()
		self.testbed.init_mail_stub()
		self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
		self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
		self.testbed.init_user_stub()

		self.headers = {'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) Version/6.0 Safari/536.25',
						'Accept-Language' : 'en_US'}

		# fix configuration if this is still a raw boilerplate code - required by test with mails
		if not utils.is_email_valid(self.app.config.get('contact_sender')):
			self.app.config['contact_sender'] = "*****@*****.**"
		if not utils.is_email_valid(self.app.config.get('contact_recipient')):
			self.app.config['contact_recipient'] = "*****@*****.**"
		
		##: Setup global variables
		self.deleteTestProduct()
		product, best_price, productPriceTiers = self.getTestProduct()
		urlsafeKey = product.key.urlsafe()
		
		self.testProduct = product
		self.testProduct_urlsafeKey = urlsafeKey
		self.testProduct_bestPrice = best_price
		self.testProduct_priceTiers = productPriceTiers
		
		logging.info('product = {}'.format(self.testProduct))
		logging.info('urlsafeKey = {}'.format(self.testProduct_urlsafeKey))
		logging.info('best_price = {}'.format(self.testProduct_bestPrice))
Exemplo n.º 9
0
def app_factory(config, app_name=None, blueprints=None):
    app_name = app_name or __name__
    app = Flask(app_name)

    config = config_str_to_obj(config)
    configure_app(app, config)
    configure_logger(app, config)
    configure_error_handlers(app)
    configure_database(app)
    configure_context_processors(app)
    configure_template_filters(app)
    configure_extensions(app)
    configure_before_request(app)
    configure_views(app)
    add_routes(app)
    configure_bcrypt(app)

    return app
Exemplo n.º 10
0
    def setUp(self):

        # create a WSGI application.
        webapp2_config = boilerplate_config.config
        webapp2_config.update(config.config)
        self.app = webapp2.WSGIApplication(config=webapp2_config)
        routes.add_routes(self.app)
        boilerplate_routes.add_routes(self.app)
        self.testapp = webtest.TestApp(
            self.app, extra_environ={'REMOTE_ADDR': '127.0.0.1'})

        # use absolute path for templates
        self.app.config['webapp2_extras.jinja2']['template_path'] = [
            os.path.join(os.path.dirname(boilerplate.__file__),
                         '../templates'),
            os.path.join(os.path.dirname(boilerplate.__file__), 'templates')
        ]

        # activate GAE stubs
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()
        self.testbed.init_taskqueue_stub()
        self.testbed.init_mail_stub()
        self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
        self.taskqueue_stub = self.testbed.get_stub(
            testbed.TASKQUEUE_SERVICE_NAME)
        self.testbed.init_user_stub()

        self.headers = {
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) Version/6.0 Safari/536.25',
            'Accept-Language': 'en_US'
        }

        # fix configuration if this is still a raw boilerplate code - required by test with mails
        if not utils.is_email_valid(self.app.config.get('contact_sender')):
            self.app.config['contact_sender'] = "*****@*****.**"
        if not utils.is_email_valid(self.app.config.get('contact_recipient')):
            self.app.config[
                'contact_recipient'] = "*****@*****.**"
Exemplo n.º 11
0
def create_app(*, debug=False, threads=4):
    """Return an instance of the Flask application.

    Args:
        debug (bool): a flag to activate the debug mode for the app
            (default: False).
        threads (int): number of threads to use
    Return:
        an instance of the Flask application.
    """

    app = Flask(__name__)

    app.debug = debug

    app.config['bigchain_pool'] = utils.pool(Bigchain, size=threads)

    add_routes(app)

    return app
Exemplo n.º 12
0
    def setUp(self):
        # create a WSGI application.
        w2config = config.webapp2_config
        # use absolute path for templates
        w2config['webapp2_extras.jinja2']['template_path'] =  os.path.join(os.path.join(os.path.dirname(web.__file__), '..'), 'templates')
        app = webapp2.WSGIApplication(config=w2config)
        routes.add_routes(app)
        self.testapp = webtest.TestApp(app, extra_environ={'REMOTE_ADDR' : '127.0.0.1'})
        # HTTP_HOST in extra_environ is not enough for taskqueue stub and it warns
        os.environ['HTTP_HOST'] = 'localhost'

        # activate GAE stubs
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()
        self.testbed.init_taskqueue_stub()

        # some shortcuts
        self.cookie_name=config.webapp2_config['webapp2_extras.auth']['cookie_name']
        self.headers = {'User-Agent' : 'Safari', 'Accept-Language' : 'en_US'}
        
        # register test account
        self.testapp.post('/register/',
                        forms.RegisterForm(username='******', password='******',
                            c_password='******', email='*****@*****.**', country='').data,
                        headers=self.headers)
        
        # is test account created?
        users = models.User.query().fetch(2)
        self.assertEqual(1, len(users), 'testuser could not register')
        self.user = users[0]

        # clear cookies
        self.testapp.reset()
Exemplo n.º 13
0
#!/usr/bin/env python3

import falcon

import routes
from config import Config
from middleware import ValidateComponent

api = falcon.API(media_type=falcon.MEDIA_JSON,
                 middleware=[ValidateComponent()])

cfg = Config()
routes.add_routes(api, cfg)
Exemplo n.º 14
0
# python paths
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'web/models'))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))

# imports
import webapp2
import config
import routes
import logging

from web.basehandler import handle_error

logging.getLogger().setLevel(logging.WARNING)

# base application
app = webapp2.WSGIApplication(
    debug=os.environ['SERVER_SOFTWARE'].startswith('Dev'),
    config=config.webapp2_config)

# error handling
app.error_handlers[403] = handle_error
app.error_handlers[404] = handle_error

# debug output
if not app.debug:
    app.error_handlers[500] = handle_error

# add routes
routes.add_routes(app)
Exemplo n.º 15
0
from sanic import Sanic
from sanic_cors import CORS

from config import SSO_API_PORT, SSO_API_HOST
from routes import add_routes

app = Sanic(name=__name__)
cors = CORS(app, automatic_options=True, supports_credentials=True)
add_routes(app)

if __name__ == '__main__':
    app.run(host=SSO_API_HOST, port=SSO_API_PORT)
Exemplo n.º 16
0
# install third party libraries
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib/externals'))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'web/models'))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))

import webapp2
import config
import routes

"""
import ssl
import logging
import sys
logging.info(sys.version)
logging.info(os.environ)
logging.info("cert_none is %s" % CERT_NONE)
"""

from web.basehandler import handle_error

app = webapp2.WSGIApplication(debug = os.environ['SERVER_SOFTWARE'].startswith('Dev'), config=config.webapp2_config)

app.debug = True

app.error_handlers[403] = handle_error
app.error_handlers[404] = handle_error
if not app.debug:
    app.error_handlers[500] = handle_error
routes.add_routes(app)

Exemplo n.º 17
0
 def __init__(self):
     self.flask = Flask(__name__)
     self.flask.config.from_object(ServerConfiguration)
     add_routes(self.flask)
Exemplo n.º 18
0
from flask import Flask
from flask_restful import Api
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
from routes import add_routes  # routes added in a separate file
from config import add_configs  # configs added in a separate file
from db import db
from flask_jwt_extended import JWTManager

app = Flask(__name__)

add_configs(app)
api = add_routes(Api(app))
manager = Manager(app)
db.init_app(app)
migrate = Migrate(app, db)
jwt = JWTManager(app)


def make_shell_context():
    return dict(app=app, db=db)


manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)

if __name__ == "__main__":
    manager.run()
Exemplo n.º 19
0
import sys
# Third party libraries path must be fixed before importing webapp2
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'bp_includes/external'))

import webapp2

from bp_includes.lib.error_handler import handle_error
from bp_includes import config as config_boilerplate

sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'bp_content/themes/', os.environ['theme']))
# Import Config Importing
import config as config_theme

# Routes Importing
from bp_admin import routes as routes_admin
from bp_includes import routes as routes_boilerplate
import routes as routes_theme

webapp2_config = config_boilerplate.config
webapp2_config.update(config_theme.config)

app = webapp2.WSGIApplication(debug=os.environ['SERVER_SOFTWARE'].startswith('Dev'), config=webapp2_config)

if not app.debug:
    for status_int in app.config['error_templates']:
        app.error_handlers[status_int] = handle_error

routes_theme.add_routes(app)
routes_boilerplate.add_routes(app)
routes_admin.add_routes(app)
Exemplo n.º 20
0
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'bp_includes/external'))

import webapp2


from bp_includes.lib.error_handler import handle_error
from bp_includes import config as config_boilerplate

sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'bp_content/themes/', os.environ['theme']))
# Import Config Importing
import config as config_theme

# Routes Importing
from bp_admin import routes as routes_admin
from bp_includes import routes as routes_boilerplate
import routes as routes_theme


webapp2_config = config_boilerplate.config
webapp2_config.update(config_theme.config)

app = webapp2.WSGIApplication(debug=os.environ['SERVER_SOFTWARE'].startswith('Dev'), config=webapp2_config)

if not app.debug:
    for status_int in app.config['error_templates']:
        app.error_handlers[status_int] = handle_error

routes_theme.add_routes(app)
routes_boilerplate.add_routes(app)
routes_admin.add_routes(app)
Exemplo n.º 21
0
        stats_middleware,
        auth_middleware,
        cors.middleware,
    ])

else:
    api = application = falcon.API(middleware=[
        stats_middleware,
        cors.middleware,
    ])

# Add exception handling
middleware.falcon_exceptions.register_defaults(api)

# Add Swagger UI
services.swaggerui.register_swaggerui(api)

# Routes  ###############
# Add routes to skip authentication in common/middleware:AuthMiddleware.skip_routes list
routes.add_routes(api)

# Useful for debugging problems in your API; works with pdb.set_trace()
if __name__ == '__main__':
    from wsgiref import simple_server

    host = "127.0.0.1"
    port = 8181
    httpd = simple_server.make_server(host, port, api)
    print("Serving on {}:{}".format(host, port))
    httpd.serve_forever()
Exemplo n.º 22
0
def test_cli(loop, sanic_client):
    app = Sanic()
    add_routes(app)
    return loop.run_until_complete(sanic_client(app))
Exemplo n.º 23
0
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Api

# Initiliaze Flask app object with configs
app = Flask(__name__)
app.config.from_object('config')

# Initialize Flask-SQLAlchemy db object
# db = SQLAlchemy(app) ## not using db for now
# Initialize Flask-RESTful api object
api = Api(app)

# Attach routes to the Flask-RESTful Resource objects found at controllers/*
import routes
routes.add_routes()
Exemplo n.º 24
0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################

# python imports
import os

# GAE imports
import webapp2

# local imports
import routes


_debug = os.environ.get('SERVER_SOFTWARE').startswith('Dev')
_config = {}
_routes = []

APP = webapp2.WSGIApplication(debug=_debug, config=_config)

routes.add_routes(APP)
Exemplo n.º 25
0
import routes
import webapp2
import config

application = webapp2.WSGIApplication(config=config.webapp2_config)
routes.add_routes(application)