Beispiel #1
0
    def test_external_urls_no_subdomain(self):
        'External URL reverse with no subdomains provided in location'
        def config(env, data, nxt):
            env.root = root.bind_to_env(env)
            return nxt(env, data)

        called_urls = []

        def get_handler(num, result):
            def handler(env, data):
                self.assertEqual(env.root.url1.as_url.with_host(), result)
                called_urls.append(num)
                return Response()
            return handler

        url1 = get_handler(1, 'http://example.com/url')
        url2 = get_handler(2, 'http://example.com:8000/url')
        url3 = get_handler(3, 'https://example.com:80/url')

        app = web.request_filter(config) | web.cases(
                web.match('/url', 'url1') | url1,
                web.match('/url2', 'url2') | url2,
                web.match('/url3', 'url3') | url3,
                )
        root = web.Reverse.from_handler(app)

        assert web.ask(app, 'http://example.com/url')
        assert web.ask(app, 'http://example.com:8000/url2')
        assert web.ask(app, 'https://example.com:80/url3')
        assert called_urls == [1,2,3]
Beispiel #2
0
 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')
Beispiel #3
0
 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")
Beispiel #4
0
 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')
Beispiel #5
0
 def test_response_class_chaining(self):
     nf = HTTPNotFound
     chain = web.request_filter(lambda e,d,n: n(e,d)) | nf
     response = chain(VS(), VS())
     self.assert_(isinstance(response, nf))
Beispiel #6
0
 def test_response_chaining(self):
     nf = HTTPNotFound()
     chain = web.request_filter(lambda e,d,n: n(e,d)) | nf
     response = chain(VS(), VS())
     self.assert_(response is nf)
Beispiel #7
0
 def test_response_class_chaining(self):
     nf = HTTPNotFound
     chain = web.request_filter(lambda e, d, n: n(e, d)) | nf
     response = chain(VS(), VS())
     self.assert_(isinstance(response, nf))
Beispiel #8
0
 def test_response_chaining(self):
     nf = HTTPNotFound()
     chain = web.request_filter(lambda e, d, n: n(e, d)) | nf
     response = chain(VS(), VS())
     self.assert_(response is nf)
    front_env.cfg.DOMAINS = [env.request.host.split(':', 1)[0]]
    old_query = front_env.db._query_cls
    try:
        query_cls = AdminPublicQuery# if env.version == 'admin' else PublicQuery
        # XXX hack!
        front_env.db._query_cls = query_cls
        return nxt(front_env, front_data)
    finally:
        front_env.db._query_cls = old_query


@web.request_filter
def collect_unpublished(env, data, nxt):
    result = nxt(env, data)
    unpublished = []
    for obj in env.db.identity_map.values():
        if (isinstance(obj, env.models._WithState) or
            isinstance(obj, env.models.WithState)) and \
                obj.state == obj.PRIVATE:
            unpublished.append({'title': unicode(obj)})
    if unpublished:
        script = '''<head><script>
            if(window.parent){
                window.parent.unpublishedItems(%s)
            }
        </script>'''% json.dumps(unpublished)
        result.body = script.join(result.body.split('<head>',1));
    return result

front_environment = set_models | web.request_filter(call_with_front_env) | collect_unpublished