Ejemplo n.º 1
0
def test_render_default():
    conf = AppConfig(minimal=True)
    conf.default_renderer = 'json'
    app = conf.make_wsgi_app()

    res = tg.render_template({'value': 'value'})
    assert 'value": "value' in res
Ejemplo n.º 2
0
 def setup(self):
     conf = AppConfig(minimal=True, root_controller=i18nRootController())
     conf['paths']['root'] = 'tests'
     conf['i18n.enabled'] = True
     conf['session.enabled'] = True
     conf['i18n.lang'] = 'kr'
     conf['beaker.session.key'] = 'tg_test_session'
     conf['beaker.session.secret'] = 'this-is-some-secret'
     conf.renderers = ['json']
     conf.default_renderer = 'json'
     conf.package = _FakePackage()
     app = conf.make_wsgi_app()
     self.app = TestApp(app)
Ejemplo n.º 3
0
def configure_app(using):
    # Simulate starting configuration process from scratch
    milestones._reset_all()

    app_cfg = AppConfig(minimal=True)
    app_cfg.renderers = ['kajiki']
    app_cfg.default_renderer = 'kajiki'
    app_cfg.use_dotted_templatenames = True
    app_cfg.package = FakeAppPackage()
    app_cfg.use_toscawidgets2 = True
    app_cfg['tw2.enabled'] = True
    app_cfg.sa_auth.authmetadata = TestAuthMetadata()
    app_cfg['beaker.session.secret'] = app_cfg['session.secret'] = 'SECRET'
    app_cfg.auth_backend = 'ming'
    app_cfg['mail.debugmailer'] = "dummy"

    if using == 'sqlalchemy':
        app_cfg.package.model = FakeSQLAModel()
        app_cfg.use_sqlalchemy = True
        app_cfg['sqlalchemy.url'] = 'sqlite://'
        app_cfg.use_transaction_manager = True
        app_cfg['tm.enabled'] = True
        app_cfg.SQLASession = app_cfg.package.model.DBSession
    elif using == 'ming':
        app_cfg.package.model = FakeMingModel()
        app_cfg.use_ming = True
        app_cfg['ming.url'] = 'mim:///mailtemapltes'
        app_cfg.MingSession = app_cfg.package.model.DBSession
    else:
        raise ValueError('Unsupported backend')

    app_cfg.model = app_cfg.package.model
    app_cfg.DBSession = app_cfg.package.model.DBSession

    # Guarantee that the same form is used between multiple
    # configurations of TGApps. Otherwise the validated
    # form would be different from the displayed one.

    plug(app_cfg, 'tgext.mailer', plug_bootstrap=True, debugmailer='dummy')
    plug(app_cfg,
         'tgext.asyncjob',
         plug_bootstrap=True,
         app_globals=app_cfg['app_globals'])
    # it is important that tgext.mailer and tgext.asyncjob are plugged
    # before mailtemplates or not plugged at all as mailtemplates plugs them
    plug(app_cfg, 'mailtemplates', plug_bootstrap=True, default_language='EN')
    return app_cfg
Ejemplo n.º 4
0
def configure_app(using):
    # Simulate starting configuration process from scratch
    milestones._reset_all()

    app_cfg = AppConfig(minimal=True)
    app_cfg.renderers = ['kajiki']
    app_cfg.default_renderer = 'kajiki'
    app_cfg.use_dotted_templatenames = True
    app_cfg.package = FakeAppPackage()
    app_cfg.use_toscawidgets2 = True
    app_cfg.sa_auth.authmetadata = TestAuthMetadata()
    app_cfg['beaker.session.secret'] = app_cfg['session.secret'] = 'SECRET'
    app_cfg.auth_backend = 'ming'
    app_cfg['mail.debugmailer'] = 'dummy'

    if using == 'sqlalchemy':
        app_cfg.package.model = FakeSQLAModel()
        app_cfg.use_sqlalchemy = True
        app_cfg['sqlalchemy.url'] = 'sqlite://'
        app_cfg.use_transaction_manager = True
    elif using == 'ming':
        app_cfg.package.model = FakeMingModel()
        app_cfg.use_ming = True
        app_cfg['ming.url'] = 'mim:///testregistration'
    else:
        raise ValueError('Unsupported backend')

    app_cfg.model = app_cfg.package.model
    app_cfg.DBSession = app_cfg.package.model.DBSession

    # CUSTOM registration options
    app_cfg['registration.email_sender'] = '*****@*****.**'

    from registration.lib import send_email, get_form

    # Guarantee that the same form is used between multiple
    # configurations of TGApps. Otherwise the validated
    # form would be different from the displayed one.
    plug_args = {}
    if '_pluggable_registration_config' in config:
        plug_args['form_instance'] = get_form()

    plug(app_cfg, 'tgext.mailer', plug_bootstrap=True, debugmailer='dummy')
    plug(app_cfg, 'registration', plug_bootstrap=False, **plug_args)
    return app_cfg
Ejemplo n.º 5
0
    def setUp(self):
        self.root_controller = self.controller_factory()
        conf = AppConfig(minimal=True, root_controller=self.root_controller)
        conf.package = FakePackage()
        conf.model = conf.package.model
        conf.use_dotted_templatenames = True
        conf.renderers = ['json', 'jinja', 'mako']
        conf.default_renderer = 'jinja'
        conf.use_sqlalchemy = True
        conf.paths = {'controllers': 'tests', 'templates': ['tests']}
        conf.disable_request_extensions = False
        conf.prefer_toscawidgets2 = True
        conf.use_transaction_manager = True
        conf['sqlalchemy.url'] = 'sqlite:///:memory:'

        self.app = TestApp(conf.make_wsgi_app())

        metadata.create_all()
Ejemplo n.º 6
0
    def setUp(self):
        self.root_controller = self.controller_factory()
        conf = AppConfig(minimal=True, root_controller=self.root_controller)
        conf.package = FakePackage()
        conf.model = conf.package.model
        conf.use_dotted_templatenames = True
        conf.renderers = ['json', 'jinja', 'mako']
        conf.default_renderer = 'jinja'
        conf.use_sqlalchemy = True
        conf.paths = {'controllers':'tests',
                      'templates':['tests']}
        conf.disable_request_extensions = False
        conf.prefer_toscawidgets2 = True
        conf.use_transaction_manager = True
        conf['sqlalchemy.url'] = 'sqlite:///:memory:'

        self.app = TestApp(conf.make_wsgi_app())

        metadata.create_all()
Ejemplo n.º 7
0
def start_server():
    """ start webserver """

    catalog_engine = create_engine(SQLITE_DATA_TARGET)
    login_engine = create_engine(LOGIN_DATA_TARGET)
    config = AppConfig(minimal=True,
                       root_controller=RootController(catalog_engine,
                                                      login_engine))
    config.sa_auth.charset = 'utf-8'
    config.renderers = ['kajiki']
    config.default_renderer = 'kajiki'
    config.serve_static = True
    config.paths['static_files'] = 'public'
    config.paths['controllers'] = 'controllers'

    application = config.make_wsgi_app()
    print "Serving on port 8080..."
    httpd = make_server('', 8080, application)
    httpd.serve_forever()
Ejemplo n.º 8
0
def configure_app(using):
    # Simulate starting configuration process from scratch
    milestones._reset_all()

    app_cfg = AppConfig(minimal=True)
    app_cfg.renderers = ['kajiki']
    app_cfg.default_renderer = 'kajiki'
    app_cfg.use_dotted_templatenames = True
    app_cfg.package = FakeAppPackage()
    app_cfg.use_toscawidgets2 = True
    app_cfg['tw2.enabled'] = True
    app_cfg.sa_auth.authmetadata = TestAuthMetadata()
    app_cfg['beaker.session.secret'] = app_cfg['session.secret'] = 'SECRET'
    app_cfg.auth_backend = 'ming'
    app_cfg['mail.debugmailer'] = 'dummy'

    if using == 'sqlalchemy':
        app_cfg.package.model = FakeSQLAModel()
        app_cfg.use_sqlalchemy = True
        app_cfg['sqlalchemy.url'] = 'sqlite://'
        app_cfg.use_transaction_manager = True
        app_cfg['tm.enabled'] = True
    elif using == 'ming':
        app_cfg.package.model = FakeMingModel()
        app_cfg.use_ming = True
        app_cfg['ming.url'] = 'mim:///testregistration'
    else:
        raise ValueError('Unsupported backend')

    app_cfg.model = app_cfg.package.model
    app_cfg.DBSession = app_cfg.package.model.DBSession

    # CUSTOM registration options
    app_cfg['registration.email_sender'] = '*****@*****.**'

    plug(app_cfg, 'tgext.mailer', plug_bootstrap=True, debugmailer='dummy')
    plug(app_cfg,
         'registration',
         plug_bootstrap=False,
         form_instance=registration_form)

    return app_cfg
Ejemplo n.º 9
0
def configure_app(using):
    # Simulate starting configuration process from scratch
    milestones._reset_all()

    app_cfg = AppConfig(minimal=True)
    app_cfg.renderers = ['kajiki']
    app_cfg.default_renderer = 'kajiki'
    app_cfg.use_dotted_templatenames = True
    app_cfg.package = FakeAppPackage()
    app_cfg.use_toscawidgets2 = True
    app_cfg['beaker.session.secret'] = app_cfg['session.secret'] = 'SECRET'
    app_cfg['mail.debugmailer'] = "dummy"

    if using == 'sqlalchemy':
        app_cfg.auth_backend = 'sqlalchemy'
        app_cfg.package.model = FakeSQLAModel()
        app_cfg.use_sqlalchemy = True
        app_cfg['sqlalchemy.url'] = 'sqlite://'
        app_cfg.use_transaction_manager = True
        app_cfg.SQLASession = app_cfg.package.model.DBSession
    elif using == 'ming':
        app_cfg.auth_backend = 'ming'
        app_cfg.package.model = FakeMingModel()
        app_cfg.use_ming = True
        app_cfg['ming.url'] = 'mim:///userprofile'
        app_cfg.MingSession = app_cfg.package.model.DBSession
    else:
        raise ValueError('Unsupported backend')

    app_cfg.model = app_cfg.package.model
    app_cfg.DBSession = app_cfg.package.model.DBSession
    app_cfg.sa_auth.authmetadata = TestAuthMetadata()

    # Guarantee that the same form is used between multiple
    # configurations of TGApps. Otherwise the validated
    # form would be different from the displayed one.

    app_cfg['userprofile.email_sender'] = '[email protected]'

    plug(app_cfg, 'userprofile', plug_bootstrap=True)
    return app_cfg
Ejemplo n.º 10
0
                    'clusters':clusters,
                    'cluster_counts':cluster_counts,
                    'degree_distribution':degree_distribution,
                    'degree':foaf_graph.degree(),
                    'top10':top10
                }
                foaf_data = json.dumps(infos)
                data_file.write(foaf_data)
                return foaf_data

    @expose(content_type='application/json')
    def graph(self, **kw):
        with closing(open('graph_cache.json', 'w')) as graph_file:
            foaf_graph = retrieve_foaf(FBTOKEN)                             
            foaf_graph_json = jg.dumps(foaf_graph)
            graph_file.write(foaf_graph_json)
            return foaf_graph_json
 
config = AppConfig(minimal=True, root_controller=RootController())
config.serve_static = True
config.paths['static_files'] = './'

config.renderers = ['jinja', 'json']
config.default_renderer = 'jinja'

application = config.make_wsgi_app()

print 'Serving on port 8080...'
httpd = make_server('', 8080, application)
httpd.serve_forever()
Ejemplo n.º 11
0
    @expose('json:', content_type='application/json')
    def timeline(self, **kw):
        f = open(TIMELINE_FILE)
        yield f.read()

    @expose('json:', content_type='application/json')
    def clusters(self, **kw):
        f = open(CLUSTERS_FILE)
        yield f.read()

    @expose('json:', content_type='application/json')
    def force(self, **kw):
        f = open(FORCE_FILE)
        yield f.read()

config = AppConfig(minimal=True, root_controller=RootController())

#Only change since before is that we register the 'json' renderer
#into our list of available renderers, so that we are able to
#encode our responses as JSON
config.renderers = ['json', 'jinja']
config.default_renderer = 'jinja'

config.serve_static = True
config['paths']['static_files'] = './'

from wsgiref.simple_server import make_server
print "Serving on port 8080..."
httpd = make_server('', 8080, config.make_wsgi_app())
httpd.serve_forever()
Ejemplo n.º 12
0
    app_globals.player.start()

def _setup_google_music():
    log.info('Connecting to Google Music')
    config = tg.config
    app_globals = config.tg.app_globals

    app_globals.gm = Webclient()
    app_globals.gm.login(config.gm.username, config.gm.password)

    song_sorting = lambda song: '%(artist)s-%(album)s-%(track)s' % song
    app_globals.library = sorted(app_globals.gm.get_all_songs(), key=song_sorting)

config = AppConfig(minimal=True, root_controller=RootController())
config.renderers = ['json']
config.default_renderer = 'json'
config.serve_static = True
config.paths['static_files'] = '.'
config.register_hook('startup', _setup_google_music)
config.register_hook('startup', _setup_music_player)

from wsgiref.simple_server import make_server
import json

config_options = {}
with open('config.json') as config_file:
    config_options.update(json.load(config_file))

print "Serving on port 8080..."
httpd = make_server('', 8080, config.make_wsgi_app(**config_options))
httpd.serve_forever()