示例#1
0
    def test_rest_enable_api(self):
        from ptah.rest import RestLoginRoute, RestApiRoute

        mapper = self.p_config.get_routes_mapper()

        self.assertIsNone(mapper.get_route('ptah-rest'))
        self.assertIsNone(mapper.get_route('ptah-rest-login'))

        ptah.enable_rest_api(self.p_config)

        marker = object()

        factory = mapper.get_route('ptah-rest').factory
        self.assertIs(factory, RestApiRoute)
        self.assertIs(factory(marker).request, marker)

        factory = mapper.get_route('ptah-rest-login').factory
        self.assertIs(factory, RestLoginRoute)
        self.assertIs(factory(marker).request, marker)
示例#2
0
    def test_rest_enable_api(self):
        from ptah.rest import RestLoginRoute, RestApiRoute

        mapper = self.config.get_routes_mapper()

        self.assertIsNone(mapper.get_route('ptah-rest'))
        self.assertIsNone(mapper.get_route('ptah-rest-login'))

        ptah.enable_rest_api(self.config)
        self.init_ptah()

        marker = object()

        factory = mapper.get_route('ptah-rest').factory
        self.assertIs(factory, RestApiRoute)
        self.assertIs(factory(marker).request, marker)

        factory = mapper.get_route('ptah-rest-login').factory
        self.assertIs(factory, RestLoginRoute)
        self.assertIs(factory(marker).request, marker)
示例#3
0
文件: app.py 项目: nerdfiles/ptah-aha
def main(global_config, **settings):
    """ This is your application startup.
    """
    config = Configurator(root_factory=APP_FACTORY, settings=settings,
                          session_factory = session_factory,
                          authentication_policy = auth_policy)

    config.include('ptah')
    config.include('pyramid_tm')

    import sqlahelper, sqlalchemy
    engine = sqlalchemy.engine_from_config(settings, 'sqlalchemy.')
    sqlahelper.add_engine(engine)
    
    # you could use ptah.ptah_init() and be home by now
    # --- start ptah.ptah_init() ---
    config.ptah_initialize(('nerdfilestest', 'ptah'))
    config.commit()
    # --- end ptah.ptah_init() ---

    # create sql tables
    Base = sqlahelper.get_base()
    Base.metadata.create_all()

    # your application configuration
    root = APP_FACTORY()

    # admin user
    user = Session.query(User).first()
    if user is None:
        user = User('Admin', 'admin', '*****@*****.**', '12345')
        Session.add(user)

    # give manager role to admin
    if user.uri not in root.__local_roles__:
        root.__local_roles__[user.uri] = [Manager.id]
    
    # set authcontext as admin user
    ptah.authService.set_userid(user.uri)

    # create default page
    if 'front-page' not in root.keys():
        page = Page(title=u'Welcome to Ptah')
        page.text = open(
            abspath_from_asset_spec('nerdfilestest:welcome.pt'), 'rb').read()

        root['front-page'] = page

    # We are not in a web request; we need to manually commit.
    import transaction
    transaction.commit()

    # enable rest api
    ptah.enable_rest_api(config)

    # enable ptah-manage, see ptah.managers in .ini for users whom can access
    config.add_route(
        'ptah-manage','/ptah-manage/*traverse',
        factory=ptah.manage.PtahManageRoute, use_global_views=True)
    config.begin()
    ptah.manage.CONFIG['managers'] = ['admin']
    config.end()

    config.scan()

    return config.make_wsgi_app()