Ejemplo n.º 1
0
def test_basic():
    m = Mapper(explicit=False)
    m.minimization = False
    m.connect('/:controller/:action/:id')
    m.create_regs(['content'])

    # Recognize
    eq_(None, m.match('/content'))
    eq_(None, m.match('/content/index'))
    eq_(None, m.match('/content/index/'))
    eq_({
        'controller': 'content',
        'action': 'index',
        'id': '4'
    }, m.match('/content/index/4'))
    eq_({
        'controller': 'content',
        'action': 'view',
        'id': '4.html'
    }, m.match('/content/view/4.html'))

    # Generate
    eq_(None, m.generate(controller='content'))
    eq_('/content/index/4', m.generate(controller='content', id=4))
    eq_('/content/view/3', m.generate(controller='content',
                                      action='view',
                                      id=3))
Ejemplo n.º 2
0
def test_full():
    m = Mapper(explicit=False)
    m.minimization = False
    m.connect('/:controller/:action/', id=None)
    m.connect('/:controller/:action/:id')
    m.create_regs(['content'])
    
    # Recognize
    eq_(None, m.match('/content'))
    eq_(None, m.match('/content/index'))
    eq_({'controller':'content','action':'index','id':None}, 
        m.match('/content/index/'))
    eq_({'controller':'content','action':'index','id':'4'}, 
        m.match('/content/index/4'))
    eq_({'controller':'content','action':'view','id':'4.html'},
        m.match('/content/view/4.html'))
    
    # Generate
    eq_(None, m.generate(controller='content'))
    
    # Looks odd, but only controller/action are set with non-explicit, so we
    # do need the id to match
    eq_('/content/index/', m.generate(controller='content', id=None))
    eq_('/content/index/4', m.generate(controller='content', id=4))
    eq_('/content/view/3', m.generate(controller='content', action='view', id=3))
Ejemplo n.º 3
0
def test_other_special_chars():
    m = Mapper()
    m.minimization = False
    m.connect('/:year/:(slug).:(format),:(locale)', locale='en', format='html')
    m.create_regs(['content'])
    
    eq_('/2007/test.xml,ja', m.generate(year=2007, slug='test', format='xml', locale='ja'))
    eq_(None, m.generate(year=2007, format='html'))
Ejemplo n.º 4
0
def test_unicode():
    hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese
    hoge_enc = urllib.quote(hoge.encode('utf-8'))
    m = Mapper()
    m.minimization = False
    m.connect(':hoge')
    eq_("/%s" % hoge_enc, m.generate(hoge=hoge))
    assert isinstance(m.generate(hoge=hoge), str)
Ejemplo n.º 5
0
def main():
    template.register_template_library('ranking_engine.filters')
    template.register_template_library('ranking_engine.tags')

    map = Mapper(explicit=True)
    add_routes(map)
    application = WSGIApplication(map, debug=True)
    run_wsgi_app(application)
Ejemplo n.º 6
0
def test_query_params():
    m = Mapper()
    m.minimization = False
    m.explicit = True
    m.connect('/:controller/index', action='index')
    m.create_regs(['content'])
    
    eq_(None, m.generate(controller='content'))
    eq_('/content/index?test=sample', 
        m.generate(controller='content', action='index', test='sample'))
Ejemplo n.º 7
0
def test_action_required():
    m = Mapper()
    m.minimization = False
    m.explicit = True
    m.connect('/:controller/index', action='index')
    m.create_regs(['content'])
    
    eq_(None, m.generate(controller='content'))
    eq_(None, m.generate(controller='content', action='fred'))
    eq_('/content/index', m.generate(controller='content', action='index'))
Ejemplo n.º 8
0
def test_unicode_static():
    hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese
    hoge_enc = urllib.quote(hoge.encode('utf-8'))
    m = Mapper()
    m.minimization = False
    m.connect('google-jp', 'http://www.google.co.jp/search', _static=True)
    m.create_regs(['messages'])
    eq_("http://www.google.co.jp/search?q=" + hoge_enc,
                     url_for('google-jp', q=hoge))
    assert isinstance(url_for('google-jp', q=hoge), str)
Ejemplo n.º 9
0
    def setup_routes(self):
        """Setup the default TG2 routes

        Override this and setup your own routes maps if you want to use
        custom routes.

        It is recommended that you keep the existing application routing in
        tact, and just add new connections to the mapper above the routes_placeholder
        connection.  Lets say you want to add a pylons controller SamplesController,
        inside the controllers/samples.py file of your application.  You would
        augment the app_cfg.py in the following way::

            from routes import Mapper
            from tg.configuration import AppConfig

            class MyAppConfig(AppConfig):
                def setup_routes(self):
                    map = Mapper(directory=config['pylons.paths']['controllers'],
                                always_scan=config['debug'])

                    # Add a Samples route
                    map.connect('/samples/', controller='samples', action=index)

                    # Setup a default route for the root of object dispatch
                    map.connect('*url', controller='root', action='routes_placeholder')

                    config['routes.map'] = map


            base_config = MyAppConfig()

        """

        from tg.configuration import config
        from routes.mapper import Mapper

        map_ = Mapper(directory=config['pylons.paths']['controllers'],
                      always_scan=config['debug'])

        # Setup a default route for the root of object dispatch
        controller_ = 'root'
        root_folder = config.get('app.root_folder')
        if root_folder:
            controller_ = '%s/root' % root_folder

        map_.connect('*url',
                     controller=controller_,
                     action='routes_placeholder')

        config['routes.map'] = map_
Ejemplo n.º 10
0
    def setUp(self):
        frame.config.logger.driver = 'null'
        frame.app._prep_start()
        frame.routes.mapper = Mapper()

        class Root(frame.Controller):
            def string(self):
                return 'basic string output'

            def error(self):
                return invalid_name

        frame.routes.connect('/string', 'root#string')
        frame.routes.connect('/error', 'root#error')
Ejemplo n.º 11
0
    def __init__(self, uuid):
        """
        Initialize the mapper.

        The C{uuid} is used to create the rules that will either allow or
        disallow the user to perform specific actions.

        @param uuid: The user uuid.
        @type uuid: str
        @param user_db_prefix: The string prefix of users' databases.
        @type user_db_prefix: str
        """
        self._map = Mapper(controller_scan=None)
        self._user_db_name = "%s%s" % (USER_DB_PREFIX, uuid)
        self._uuid = uuid
        self._register_auth_info()
Ejemplo n.º 12
0
def test_syntax():
    m = Mapper(explicit=False)
    m.minimization = False
    m.connect('/{controller}/{action}/{id}')
    m.create_regs(['content'])
    
    # Recognize
    eq_(None, m.match('/content'))
    eq_(None, m.match('/content/index'))
    eq_(None, m.match('/content/index/'))
    eq_({'controller':'content','action':'index','id':'4'}, 
        m.match('/content/index/4'))
    
    # Generate
    eq_(None, m.generate(controller='content'))
    eq_('/content/index/4', m.generate(controller='content', id=4))
    eq_('/content/view/3', m.generate(controller='content', action='view', id=3))
Ejemplo n.º 13
0
 def __init__(self):
     self._map = Mapper(controller_scan=None)
     self._connect_urls()
     self._map.create_regs()
Ejemplo n.º 14
0
        self.db.add(a)
        return Response('non commital')


class SadController(object):
    def __init__(self, route, app):
        self.db = app.helper
        self.route = route
        self.app = app

    def fail_db(self, request):
        a = Account(id='happy account')
        self.db.add(a)
        raise Exception('dbfail')

urlmap = Mapper()
urlmap.connect('/db/happy', controller=HappyController, action="happy_db")
urlmap.connect('/db/lazy', controller=HappyController, action="lazy_db")
urlmap.connect('/db/fail', controller=SadController, action="fail_db")


class TestServer(unittest.TestCase):
    def setUp(self):
        self.app = ApiWsgiApp(TEST_CONF, urlmap)

    def tearDown(self):
        db.Session.remove()

    def test_happydb(self):
        request = Request.blank('/db/happy')
        res = self.app(request)
Ejemplo n.º 15
0
        def run_jobs():
            lock = threading.RLock()
            lock.acquire()
            session = meta.Session
            log.info(source + 'Started scheduled background jobs')

            # add task is for debug
            total = tasks.add(2, 3)
            print total

            try:
                log.info(source + "Checking ueb model build request status")
                from routes import request_config
                from routes.mapper import Mapper
                config = request_config()
                config.mapper = Mapper()
                config.host = '127.0.0.1:5000'
                config.protocol = 'http'
                #if hasattr(config, 'using_request_local'):
                config.request_local = tasks.check_ueb_request_process_status()
                config = request_config()
                #tasks.check_ueb_request_process_status()
                log.info(source +
                         "UEB model build request status check finished")
            except Exception as e:
                log.error(
                    source +
                    'Failed to check ueb package build request status.\nException:%s'
                    % e)
                pass
            try:
                log.info(source +
                         "Retrieving ueb model package from app server")
                tasks.retrieve_ueb_packages()
                log.info(
                    source +
                    "Retrieving ueb model package from app server was successful"
                )
            except Exception as e:
                log.error(
                    source +
                    'Failed to retrieve ueb package from app server.\nException:%s'
                    % e)
                pass

            try:
                log.info(source + "Checking ueb model run status")
                tasks.check_ueb_run_status()
                log.info(source + "UEB model run status check finished")
            except Exception as e:
                log.error(
                    source +
                    'Failed to check ueb package run status.\nException:%s' %
                    e)
                pass
            try:
                log.info(source +
                         "Retrieving ueb model output package from app server")
                tasks.retrieve_ueb_run_output_packages()
                log.info(
                    source +
                    "Retrieving ueb model output package from app server was successful"
                )
            except Exception as e:
                log.error(
                    source +
                    'Failed to retrieve ueb model output package from app server.\nException:%s'
                    % e)
                pass

            session.remove()
            log.info(source + 'Finished scheduled background jobs')
            time.sleep(interval * 60)
            lock.release()