コード例 #1
0
ファイル: test_routing.py プロジェクト: aswadrangnekar/tipfy
    def test_name_prefix(self):
        class DummyHandler(RequestHandler):
            def get(self, **kwargs):
                return ''

        rules = [
            NamePrefix('company-', [
                Rule('/', name='home', handler=DummyHandler),
                Rule('/about', name='about', handler=DummyHandler),
                Rule('/contact', name='contact', handler=DummyHandler),
            ]),
        ]

        app = Tipfy(rules)

        with app.get_test_handler('/') as handler:
            self.assertEqual(handler.url_for('company-home'), '/')
            self.assertEqual(handler.url_for('company-about'), '/about')
            self.assertEqual(handler.url_for('company-contact'), '/contact')

        with app.get_test_handler('/') as handler:
            self.assertEqual(handler.request.rule.name, 'company-home')

        with app.get_test_handler('/about') as handler:
            self.assertEqual(handler.request.rule.name, 'company-about')

        with app.get_test_handler('/contact') as handler:
            self.assertEqual(handler.request.rule.name, 'company-contact')
コード例 #2
0
    def test_name_prefix(self):
        class DummyHandler(RequestHandler):
            def get(self, **kwargs):
                return ''

        rules = [
            NamePrefix('company-', [
                Rule('/', name='home', handler=DummyHandler),
                Rule('/about', name='about', handler=DummyHandler),
                Rule('/contact', name='contact', handler=DummyHandler),
            ]),
        ]

        app = Tipfy(rules)

        with app.get_test_handler('/') as handler:
            self.assertEqual(handler.url_for('company-home'), '/')
            self.assertEqual(handler.url_for('company-about'), '/about')
            self.assertEqual(handler.url_for('company-contact'), '/contact')

        with app.get_test_handler('/') as handler:
            self.assertEqual(handler.request.rule.name, 'company-home')

        with app.get_test_handler('/about') as handler:
            self.assertEqual(handler.request.rule.name, 'company-about')

        with app.get_test_handler('/contact') as handler:
            self.assertEqual(handler.request.rule.name, 'company-contact')
コード例 #3
0
ファイル: app_test.py プロジェクト: tobelegit/tipfy
 def test_get_config(self):
     app = Tipfy(rules=[
         Rule('/', name='home', handler=AllMethodsHandler),
     ],
                 config={'foo': {
                     'bar': 'baz',
                 }})
     with app.get_test_handler('/') as handler:
         self.assertEqual(handler.get_config('foo', 'bar'), 'baz')
コード例 #4
0
ファイル: app_test.py プロジェクト: adilhz/tipfy
 def test_get_config(self):
     app = Tipfy(rules=[
         Rule('/', name='home', handler=AllMethodsHandler),
     ], config = {
         'foo': {
             'bar': 'baz',
         }
     })
     with app.get_test_handler('/') as handler:
         self.assertEqual(handler.get_config('foo', 'bar'), 'baz')
コード例 #5
0
ファイル: app_test.py プロジェクト: adilhz/tipfy
    def test_store_instances(self):
        from tipfy.appengine.auth import AuthStore
        from tipfy.i18n import I18nStore
        from tipfy.sessions import SecureCookieSession

        app = Tipfy(rules=[
            Rule('/', name='home', handler=AllMethodsHandler),
        ], config={
            'tipfy.sessions': {
                'secret_key': 'secret',
            },
        })
        with app.get_test_handler('/') as handler:
            self.assertEqual(isinstance(handler.session, SecureCookieSession), True)
            self.assertEqual(isinstance(handler.auth, AuthStore), True)
            self.assertEqual(isinstance(handler.i18n, I18nStore), True)
コード例 #6
0
ファイル: app_test.py プロジェクト: adilhz/tipfy
    def test_url_for(self):
        app = Tipfy(rules=[
            Rule('/', name='home', handler=AllMethodsHandler),
            Rule('/about', name='about', handler='handlers.About'),
            Rule('/contact', name='contact', handler='handlers.Contact'),
        ])
        with app.get_test_handler('/') as handler:
            self.assertEqual(handler.url_for('home'), '/')
            self.assertEqual(handler.url_for('about'), '/about')
            self.assertEqual(handler.url_for('contact'), '/contact')

            # Extras
            self.assertEqual(handler.url_for('about', _anchor='history'), '/about#history')
            self.assertEqual(handler.url_for('about', _full=True), 'http://localhost/about')
            self.assertEqual(handler.url_for('about', _netloc='www.google.com'), 'http://www.google.com/about')
            self.assertEqual(handler.url_for('about', _scheme='https'), 'https://localhost/about')
コード例 #7
0
ファイル: app_test.py プロジェクト: tobelegit/tipfy
    def test_store_instances(self):
        from tipfy.appengine.auth import AuthStore
        from tipfy.i18n import I18nStore
        from tipfy.sessions import SecureCookieSession

        app = Tipfy(rules=[
            Rule('/', name='home', handler=AllMethodsHandler),
        ],
                    config={
                        'tipfy.sessions': {
                            'secret_key': 'secret',
                        },
                    })
        with app.get_test_handler('/') as handler:
            self.assertEqual(isinstance(handler.session, SecureCookieSession),
                             True)
            self.assertEqual(isinstance(handler.auth, AuthStore), True)
            self.assertEqual(isinstance(handler.i18n, I18nStore), True)
コード例 #8
0
ファイル: app_test.py プロジェクト: tobelegit/tipfy
    def test_url_for(self):
        app = Tipfy(rules=[
            Rule('/', name='home', handler=AllMethodsHandler),
            Rule('/about', name='about', handler='handlers.About'),
            Rule('/contact', name='contact', handler='handlers.Contact'),
        ])
        with app.get_test_handler('/') as handler:
            self.assertEqual(handler.url_for('home'), '/')
            self.assertEqual(handler.url_for('about'), '/about')
            self.assertEqual(handler.url_for('contact'), '/contact')

            # Extras
            self.assertEqual(handler.url_for('about', _anchor='history'),
                             '/about#history')
            self.assertEqual(handler.url_for('about', _full=True),
                             'http://localhost/about')
            self.assertEqual(
                handler.url_for('about', _netloc='www.google.com'),
                'http://www.google.com/about')
            self.assertEqual(handler.url_for('about', _scheme='https'),
                             'https://localhost/about')