Exemple #1
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')
Exemple #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')
Exemple #3
0
 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')
Exemple #4
0
 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')
Exemple #5
0
    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)
Exemple #6
0
    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')
Exemple #7
0
    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)
Exemple #8
0
    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')