コード例 #1
0
ファイル: reverse.py プロジェクト: riffm/iktomi
    def test_external_urls(self):
        "External URL reverse"

        def host1(env, data):
            self.assertEqual(env.root.host1.as_url.with_host(), "http://host1.example.com/url")
            self.assertEqual(env.root.host2.as_url, "http://host2.example.com/url")
            self.assertEqual(env.root.host1.as_url, "/url")
            self.host1_called = True
            return Response()

        def host2(env, data):
            self.assertEqual(env.root.host2.as_url.with_host(), "https://host2.example.com/url")
            self.assertEqual(env.root.host1.as_url, "https://host1.example.com/url")
            self.assertEqual(env.root.host2.as_url, "/url")
            self.host2_called = True
            return Response()

        app = web.subdomain("example.com") | web.cases(
            web.subdomain("host1") | web.match("/url", "host1") | host1,
            web.subdomain("host2") | web.match("/url", "host2") | host2,
        )

        assert web.ask(app, "http://host1.example.com/url")
        assert web.ask(app, "https://host2.example.com/url")
        assert self.host1_called and self.host2_called
コード例 #2
0
ファイル: filter.py プロジェクト: oas89/iktomi
 def test_unicode(self):
     '''IRI tests'''
     app = web.subdomain(u'рф') | web.subdomain(u'сайт') | web.match('/', 'site') | (lambda e,d: Response() )
     encoded = 'http://xn--80aswg.xn--p1ai/'
     self.assertEqual(web.Reverse.from_handler(app).site.as_url.get_readable(), u'http://сайт.рф/')
     self.assertEqual(web.Reverse.from_handler(app).site.as_url, encoded)
     self.assertNotEqual(web.ask(app, encoded), None)
コード例 #3
0
ファイル: filter.py プロジェクト: oas89/iktomi
    def test_aliases(self):
        def handler(env, data):
            return Response(env.current_location + ' ' +
                            env.root.domain1.as_url + ' ' +
                            env.root.domain1.as_url.with_host() + ' ' +
                            env.root.domain2.as_url + ' ' +
                            env.root.domain2.as_url.with_host())
        www = web.subdomain('', 'www')
        app = web.subdomain('example.com', 'example.ru', 'example.com.ua') | web.cases(
              web.subdomain('ru', None, primary=None) | web.cases(
                  web.subdomain('moscow') | www | web.match('/', 'domain3'),
                  www | web.match('/', 'domain1')
                  ),
              web.subdomain('en', 'eng') | www | web.match('/', 'domain2'),
              )
        app = app | handler
        # XXX As for now .with_host() return primary domain, not the current one
        #     It is easy to change the behaviour, but which behaviour is
        #     correct?
        self.assertEqual(web.ask(app, 'http://ru.example.com/').body,
                'domain1 / http://example.com/ '
                'http://en.example.com/ http://en.example.com/')

        self.assertEqual(web.ask(app, 'http://www.ru.example.ru/').body,
                'domain1 / http://example.com/ '
                'http://en.example.com/ http://en.example.com/')

        self.assertEqual(web.ask(app, 'http://www.example.ru/').body,
                'domain1 / http://example.com/ '
                'http://en.example.com/ http://en.example.com/')

        self.assertEqual(web.ask(app, 'http://moscow.example.ru/').body,
                'domain3 http://example.com/ http://example.com/ '
                'http://en.example.com/ http://en.example.com/')
コード例 #4
0
ファイル: filter.py プロジェクト: riffm/iktomi
 def test_unicode(self):
     """IRI tests"""
     app = web.subdomain(u"рф") | web.subdomain(u"сайт") | web.match("/", "site") | (lambda e, d: Response())
     encoded = "http://xn--80aswg.xn--p1ai/"
     self.assertEqual(web.Reverse.from_handler(app).site.as_url.get_readable(), u"http://сайт.рф/")
     self.assertEqual(web.Reverse.from_handler(app).site.as_url, encoded)
     self.assertNotEqual(web.ask(app, encoded), None)
コード例 #5
0
ファイル: reverse.py プロジェクト: SmartTeleMax/iktomi
    def test_external_urls(self):
        'External URL reverse'

        def host1(env, data):
            self.assertEqual(env.root.host1.as_url.with_host(), 'http://host1.example.com/url')
            self.assertEqual(env.root.host2.as_url, 'http://host2.example.com/url')
            self.assertEqual(env.root.host1.as_url, '/url')
            self.host1_called = True
            return Response()

        def host2(env, data):
            self.assertEqual(env.root.host2.as_url.with_host(), 'https://host2.example.com/url')
            self.assertEqual(env.root.host1.as_url, 'https://host1.example.com/url')
            self.assertEqual(env.root.host2.as_url, '/url')
            self.host2_called = True
            return Response()

        app = web.subdomain('example.com') | web.cases (
            web.subdomain('host1') | web.match('/url', 'host1') | host1,
            web.subdomain('host2') | web.match('/url', 'host2') | host2,
        )

        assert web.ask(app, 'http://host1.example.com/url')
        assert web.ask(app, 'https://host2.example.com/url')
        assert self.host1_called and self.host2_called
コード例 #6
0
ファイル: reverse.py プロジェクト: riffm/iktomi
 def test_subdomains_and_namespace(self):
     app = (
         web.subdomain("d2")
         | web.namespace("subdomain")
         | web.subdomain("d1")
         | web.namespace("more")
         | web.match("/", "index")
     )
     r = web.Reverse.from_handler(app)
     self.assertEqual(r.subdomain.more.index.as_url, "http://d1.d2/")
コード例 #7
0
ファイル: filter.py プロジェクト: vlaght/iktomi
 def test_unicode(self):
     '''IRI tests'''
     app = web.subdomain(u'рф') | web.subdomain(u'сайт') | web.match(
         '/', 'site') | (lambda e, d: Response())
     encoded = 'http://xn--80aswg.xn--p1ai/'
     self.assertEqual(
         web.Reverse.from_handler(app).site.as_url.get_readable(),
         u'http://сайт.рф/')
     self.assertEqual(web.Reverse.from_handler(app).site.as_url, encoded)
     self.assertNotEqual(web.ask(app, encoded), None)
コード例 #8
0
ファイル: reverse.py プロジェクト: SmartTeleMax/iktomi
 def test_subdomain_after_namespace(self):
     app = web.subdomain('news', name='news') | web.subdomain('eng') | web.cases(
             web.match('/'),
             web.match('/<int:id>', 'item'),
             )
     r = web.Reverse.from_handler(app)
     self.assertEqual(r.build_url('news.item', id=1), 'http://eng.news/1')
     self.assertEqual(r.build_url('news'), 'http://eng.news/')
     self.assertEqual(r.news.item(id=1).as_url, 'http://eng.news/1')
     self.assertEqual(r.news.as_url, 'http://eng.news/')
コード例 #9
0
ファイル: reverse.py プロジェクト: riffm/iktomi
 def test_subdomains_and_cases(self):
     "Locations of web.cases with subdomains"
     chain = web.subdomain("news") | web.cases(web.match("/", "index"), web.match("/docs", "docs"))
     for k in ("index", "docs"):
         self.assert_(web.locations(chain).keys(), [k])
         self.assert_(web.locations(chain)[k][0].subdomains)
         self.assertEqual(web.locations(chain)[k][0].subdomains, ["news"])
コード例 #10
0
ファイル: chain.py プロジェクト: vlaght/iktomi
    def test_subdomain_ns_shortcut(self):
        view = lambda e, d: None
        chain = web.subdomain('www', name='namespace') | view

        assert isinstance(chain.next_handler, web.namespace)
        self.assertEqual(chain.next_handler.namespace, 'namespace')
        self.assertEqual(chain.next_handler.next_handler, view)
コード例 #11
0
ファイル: chain.py プロジェクト: Lehych/iktomi
    def test_subdomain_ns_shortcut(self):
        view = lambda e, d: None
        chain = web.subdomain('www', name='namespace') | view

        assert isinstance(chain.next_handler, web.namespace)
        self.assertEqual(chain.next_handler.namespace, 'namespace')
        self.assertEqual(chain.next_handler.next_handler, view)
コード例 #12
0
ファイル: filter.py プロジェクト: vlaght/iktomi
    def test_subdomain(self):
        '''Subdomain filter'''
        def handler(env, data):
            self.assertEqual(env.request.path, '/')
            return Response()

        def handler_with_prefix(env, data):
            self.assertEqual(env.request.path, '/j')
            return Response()

        app = web.subdomain('host') | web.cases(
            web.subdomain('') | web.match('/', 'index') | handler,
            web.subdomain('k') | web.cases(
                web.subdomain('l')
                | web.cases(web.match('/', 'l') | handler, ),
                web.subdomain('') | web.match('/', 'k') | handler),
            web.subdomain('j') | web.match('/', 'j1') | handler,
            web.subdomain('j') | web.match('/j', 'j2') | handler_with_prefix)

        self.assertEqual(web.ask(app, 'http://host/').status_int, 200)
        self.assertEqual(web.ask(app, 'http://k.host/').status_int, 200)
        self.assertEqual(web.ask(app, 'http://l.k.host/').status_int, 200)
        self.assertEqual(web.ask(app, 'http://x.l.k.host/').status_int, 200)
        self.assertEqual(web.ask(app, 'http://j.host/').status_int, 200)
        # Test if subdomains in routing are cleaned properly
        self.assertEqual(web.ask(app, 'http://j.host/j').status_int, 200)
        self.assert_(web.ask(app, 'http://x.k.host/') is None)
        self.assert_(web.ask(app, 'http://lk.host/') is None)
        self.assert_(web.ask(app, 'http://mhost/') is None)
コード例 #13
0
ファイル: filter.py プロジェクト: oas89/iktomi
    def test_subdomain(self):
        '''Subdomain filter'''

        def handler(env, data):
            self.assertEqual(env.request.path, '/')
            return Response()

        def handler_with_prefix(env, data):
            self.assertEqual(env.request.path, '/j')
            return Response()

        app = web.subdomain('host') | web.cases(
            web.subdomain('') | web.match('/', 'index') | handler,
            web.subdomain('k') | web.cases(
                web.subdomain('l') | web.cases(
                    web.match('/', 'l') | handler,
                ),
                web.subdomain('') | web.match('/', 'k') | handler),
            web.subdomain('j') | web.match('/', 'j1') | handler,
            web.subdomain('j') | web.match('/j', 'j2') | handler_with_prefix)

        self.assertEqual(web.ask(app, 'http://host/').status_int, 200)
        self.assertEqual(web.ask(app, 'http://k.host/').status_int, 200)
        self.assertEqual(web.ask(app, 'http://l.k.host/').status_int, 200)
        self.assertEqual(web.ask(app, 'http://x.l.k.host/').status_int, 200)
        self.assertEqual(web.ask(app, 'http://j.host/').status_int, 200)
        # Test if subdomains in routing are cleaned properly
        self.assertEqual(web.ask(app, 'http://j.host/j').status_int, 200)
        self.assert_(web.ask(app, 'http://x.k.host/') is None)
        self.assert_(web.ask(app, 'http://lk.host/') is None)
        self.assert_(web.ask(app, 'http://mhost/') is None)
コード例 #14
0
ファイル: reverse.py プロジェクト: SmartTeleMax/iktomi
    def test_subdomain(self):
        'Locations and subdomains'
        chain = web.subdomain('news') | web.match('/', 'index')
        self.assert_(location_keys(chain), ['index'])
        self.assert_(locations(chain)['index'][0].subdomains)

        subdomains = [x.primary 
                      for x in locations(chain)['index'][0].subdomains]
        self.assertEqual(subdomains, ['news'])
コード例 #15
0
ファイル: reverse.py プロジェクト: riffm/iktomi
    def test_external_urls_no_port(self):
        "External URL reverse with no port in Request.host (sometimes happens using Flup)"

        def host1(env, data):
            if ":" in env.request.host:
                env.request.host = env.request.host.split(":")[0]
            self.assertEqual(env.root.host1.as_url.with_host(), "http://host1.example.com/url")
            self.assertEqual(env.root.host2.as_url, "http://host2.example.com/url")
            self.assertEqual(env.root.host1.as_url, "/url")
            self.host1_called = True
            return Response()

        app = web.subdomain("example.com") | web.cases(
            web.subdomain("host1") | web.match("/url", "host1") | host1,
            web.subdomain("host2") | web.match("/url", "host2"),
        )

        assert web.ask(app, "http://host1.example.com/url")
        assert self.host1_called
コード例 #16
0
ファイル: reverse.py プロジェクト: SmartTeleMax/iktomi
    def test_external_urls_no_port(self):
        'External URL reverse with no port in Request.host (sometimes happens using Flup)'

        def host1(env, data):
            if ':' in env.request.host:
                env.request.host = env.request.host.split(':')[0]
            self.assertEqual(env.root.host1.as_url.with_host(), 'http://host1.example.com/url')
            self.assertEqual(env.root.host2.as_url, 'http://host2.example.com/url')
            self.assertEqual(env.root.host1.as_url, '/url')
            self.host1_called = True
            return Response()

        app = web.subdomain('example.com') | web.cases (
            web.subdomain('host1') | web.match('/url', 'host1') | host1,
            web.subdomain('host2') | web.match('/url', 'host2'),
        )

        assert web.ask(app, 'http://host1.example.com/url')
        assert self.host1_called
コード例 #17
0
ファイル: reverse.py プロジェクト: SmartTeleMax/iktomi
 def test_subdomains_and_cases(self):
     'Locations of web.cases with subdomains'
     chain = web.subdomain('news') | web.cases(
             web.match('/', 'index'),
             web.match('/docs', 'docs'))
     for k in ('index', 'docs'):
         self.assert_(location_keys(chain), [k])
         self.assert_(locations(chain)[k][0].subdomains)
         subdomains = [x.primary 
                   for x in locations(chain)[k][0].subdomains]
         self.assertEqual(subdomains, ['news'])
コード例 #18
0
ファイル: filter.py プロジェクト: oas89/iktomi
 def test_repr(self):
     # for coverage
     '%r' % web.WebHandler()
     '%r' % web.cases()
     '%r' % web.request_filter(lambda e, d, n: None)
     '%r' % web.match('/', 'index')
     '%r' % web.method('GET')
     '%r' % web.static_files('/prefix')
     '%r' % web.prefix('/prefix')
     '%r' % web.subdomain('name')
     '%r' % web.namespace('name')
コード例 #19
0
ファイル: filter.py プロジェクト: vlaght/iktomi
 def test_repr(self):
     # for coverage
     '%r' % web.WebHandler()
     '%r' % web.cases()
     '%r' % web.request_filter(lambda e, d, n: None)
     '%r' % web.match('/', 'index')
     '%r' % web.method('GET')
     '%r' % web.static_files('/prefix')
     '%r' % web.prefix('/prefix')
     '%r' % web.subdomain('name')
     '%r' % web.namespace('name')
コード例 #20
0
ファイル: filter.py プロジェクト: riffm/iktomi
 def test_repr(self):
     # for coverage
     "%r" % web.WebHandler()
     "%r" % web.cases()
     "%r" % web.request_filter(lambda e, d, n: None)
     "%r" % web.match("/", "index")
     "%r" % web.method("GET")
     "%r" % web.static_files("/prefix")
     "%r" % web.prefix("/prefix")
     "%r" % web.subdomain("name")
     "%r" % web.namespace("name")
コード例 #21
0
ファイル: filter.py プロジェクト: vlaght/iktomi
    def test_aliases(self):
        def handler(env, data):
            return Response(env.current_location + ' ' +
                            env.root.domain1.as_url + ' ' +
                            env.root.domain1.as_url.with_host() + ' ' +
                            env.root.domain2.as_url + ' ' +
                            env.root.domain2.as_url.with_host())

        www = web.subdomain('', 'www')
        app = web.subdomain(
            'example.com', 'example.ru', 'example.com.ua') | web.cases(
                web.subdomain('ru', None, primary=None) | web.cases(
                    web.subdomain('moscow') | www | web.match('/', 'domain3'),
                    www | web.match('/', 'domain1')),
                web.subdomain('en', 'eng') | www | web.match('/', 'domain2'),
            )
        app = app | handler
        # XXX As for now .with_host() return primary domain, not the current one
        #     It is easy to change the behaviour, but which behaviour is
        #     correct?
        self.assertEqual(
            web.ask(app, 'http://ru.example.com/').body,
            b'domain1 / http://example.com/ '
            b'http://en.example.com/ http://en.example.com/')

        self.assertEqual(
            web.ask(app, 'http://www.ru.example.ru/').body,
            b'domain1 / http://example.com/ '
            b'http://en.example.com/ http://en.example.com/')

        self.assertEqual(
            web.ask(app, 'http://www.example.ru/').body,
            b'domain1 / http://example.com/ '
            b'http://en.example.com/ http://en.example.com/')

        self.assertEqual(
            web.ask(app, 'http://moscow.example.ru/').body,
            b'domain3 http://example.com/ http://example.com/ '
            b'http://en.example.com/ http://en.example.com/')
コード例 #22
0
ファイル: filter.py プロジェクト: riffm/iktomi
    def test_subdomain(self):
        """Subdomain filter"""

        def handler(env, data):
            self.assertEqual(env.request.path, "/")
            return Response()

        app = web.subdomain("host") | web.cases(
            web.subdomain("") | web.match("/", "index") | handler,
            web.subdomain("k")
            | web.cases(
                web.subdomain("l") | web.cases(web.match("/", "l") | handler),
                web.subdomain("") | web.match("/", "k") | handler,
            ),
        )

        self.assertEqual(web.ask(app, "http://host/").status_int, 200)
        self.assertEqual(web.ask(app, "http://k.host/").status_int, 200)
        self.assertEqual(web.ask(app, "http://l.k.host/").status_int, 200)
        self.assertEqual(web.ask(app, "http://x.l.k.host/").status_int, 200)
        self.assert_(web.ask(app, "http://x.k.host/") is None)
        self.assert_(web.ask(app, "http://lk.host/") is None)
        self.assert_(web.ask(app, "http://mhost/") is None)
コード例 #23
0
ファイル: reverse.py プロジェクト: SmartTeleMax/iktomi
    def test_unicode(self):
        'Reverse with unicode'
        # various combinations of url parts containing unicode
        chain = web.subdomain(u'п') | web.cases(
            web.prefix(u'/з') | web.match('/', 'unicode1'),
            web.prefix(u'/з') | web.match('/<string:slug>', 'unicode2'),
            web.match(u'/д/<string:slug>', 'unicode3'), #regression
            web.match(u'/<string:slug1>/<string:slug2>', 'unicode4'), #regression
        )
        r = web.Reverse.from_handler(chain)

        self.assertEqual(r.unicode1.as_url, 'http://xn--o1a/%D0%B7/')
        self.assertEqual(str(r.unicode1), 'http://xn--o1a/%D0%B7/')
        self.assertEqual(r.unicode2(slug=u'ю').as_url, 'http://xn--o1a/%D0%B7/%D1%8E')
        self.assertEqual(r.unicode3(slug=u'ю').as_url, 'http://xn--o1a/%D0%B4/%D1%8E')
        self.assertEqual(r.unicode4(slug1=u'д', slug2=u'ю').as_url, 'http://xn--o1a/%D0%B4/%D1%8E')
コード例 #24
0
ファイル: reverse.py プロジェクト: riffm/iktomi
    def test_unicode(self):
        "Reverse with unicode"
        # various combinations of url parts containing unicode
        chain = web.subdomain(u"п") | web.cases(
            web.prefix(u"/з") | web.match("/", "unicode1"),
            web.prefix(u"/з") | web.match("/<string:slug>", "unicode2"),
            web.match(u"/д/<string:slug>", "unicode3"),  # regression
            web.match(u"/<string:slug1>/<string:slug2>", "unicode4"),  # regression
        )
        r = web.Reverse.from_handler(chain)

        self.assertEqual(r.unicode1.as_url, "http://xn--o1a/%D0%B7/")
        self.assertEqual(str(r.unicode1), "http://xn--o1a/%D0%B7/")
        self.assertEqual(r.unicode2(slug=u"ю").as_url, "http://xn--o1a/%D0%B7/%D1%8E")
        self.assertEqual(r.unicode3(slug=u"ю").as_url, "http://xn--o1a/%D0%B4/%D1%8E")
        self.assertEqual(r.unicode4(slug1=u"д", slug2=u"ю").as_url, "http://xn--o1a/%D0%B4/%D1%8E")
コード例 #25
0
ファイル: reverse.py プロジェクト: riffm/iktomi
 def test_subdomain(self):
     "Locations and subdomains"
     chain = web.subdomain("news") | web.match("/", "index")
     self.assert_(web.locations(chain).keys(), ["index"])
     self.assert_(web.locations(chain)["index"][0].subdomains)
     self.assertEqual(web.locations(chain)["index"][0].subdomains, ["news"])
コード例 #26
0
ファイル: reverse.py プロジェクト: SmartTeleMax/iktomi
 def test_subdomains_and_namespace(self):
     app = web.subdomain('d2') | web.namespace('subdomain') | \
             web.subdomain('d1') | web.namespace('more') | \
             web.match('/', 'index')
     r = web.Reverse.from_handler(app)
     self.assertEqual(r.subdomain.more.index.as_url, 'http://d1.d2/')
コード例 #27
0
ファイル: reverse.py プロジェクト: SmartTeleMax/iktomi
 def test_port(self):
     chain = web.subdomain(u'example.com:8000') | web.match('/', name="index")
     r = web.Reverse.from_handler(chain)
     self.assertEqual(r.index.as_url.port, '8000')
     self.assertEqual(r.index.as_url.host, 'example.com')