当前位置: 首页>>代码示例>>Python>>正文


Python test.run_wsgi_app函数代码示例

本文整理汇总了Python中werkzeug.test.run_wsgi_app函数的典型用法代码示例。如果您正苦于以下问题:Python run_wsgi_app函数的具体用法?Python run_wsgi_app怎么用?Python run_wsgi_app使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了run_wsgi_app函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_shared_data_middleware

def test_shared_data_middleware(tmpdir):
    def null_application(environ, start_response):
        start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])
        yield b'NOT FOUND'

    test_dir = str(tmpdir)
    with open(path.join(test_dir, to_native(u'äöü', 'utf-8')), 'w') as test_file:
        test_file.write(u'FOUND')

    app = wsgi.SharedDataMiddleware(null_application, {
        '/':        path.join(path.dirname(__file__), 'res'),
        '/sources': path.join(path.dirname(__file__), 'res'),
        '/pkg':     ('werkzeug.debug', 'shared'),
        '/foo':     test_dir
    })

    for p in '/test.txt', '/sources/test.txt', '/foo/äöü':
        app_iter, status, headers = run_wsgi_app(app, create_environ(p))
        assert status == '200 OK'
        with closing(app_iter) as app_iter:
            data = b''.join(app_iter).strip()
        assert data == b'FOUND'

    app_iter, status, headers = run_wsgi_app(
        app, create_environ('/pkg/debugger.js'))
    with closing(app_iter) as app_iter:
        contents = b''.join(app_iter)
    assert b'$(function() {' in contents

    app_iter, status, headers = run_wsgi_app(
        app, create_environ('/missing'))
    assert status == '404 NOT FOUND'
    assert b''.join(app_iter).strip() == b'NOT FOUND'
开发者ID:geekKeen,项目名称:werkzeug,代码行数:33,代码来源:test_wsgi.py

示例2: test_shared_data_middleware

    def test_shared_data_middleware(self):
        def null_application(environ, start_response):
            start_response("404 NOT FOUND", [("Content-Type", "text/plain")])
            yield b"NOT FOUND"

        app = wsgi.SharedDataMiddleware(
            null_application,
            {
                "/": path.join(path.dirname(__file__), "res"),
                "/sources": path.join(path.dirname(__file__), "res"),
                "/pkg": ("werkzeug.debug", "shared"),
            },
        )

        for p in "/test.txt", "/sources/test.txt":
            app_iter, status, headers = run_wsgi_app(app, create_environ(p))
            self.assert_equal(status, "200 OK")
            with closing(app_iter) as app_iter:
                data = b"".join(app_iter).strip()
            self.assert_equal(data, b"FOUND")

        app_iter, status, headers = run_wsgi_app(app, create_environ("/pkg/debugger.js"))
        with closing(app_iter) as app_iter:
            contents = b"".join(app_iter)
        self.assert_in(b"$(function() {", contents)

        app_iter, status, headers = run_wsgi_app(app, create_environ("/missing"))
        self.assert_equal(status, "404 NOT FOUND")
        self.assert_equal(b"".join(app_iter).strip(), b"NOT FOUND")
开发者ID:kopf,项目名称:werkzeug,代码行数:29,代码来源:wsgi.py

示例3: test_dispatchermiddleware

def test_dispatchermiddleware():
    def null_application(environ, start_response):
        start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])
        yield b'NOT FOUND'

    def dummy_application(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/plain')])
        yield to_bytes(environ['SCRIPT_NAME'])

    app = wsgi.DispatcherMiddleware(null_application, {
        '/test1': dummy_application,
        '/test2/very': dummy_application,
    })
    tests = {
        '/test1': ('/test1', '/test1/asfd', '/test1/very'),
        '/test2/very': ('/test2/very', '/test2/very/long/path/after/script/name')
    }
    for name, urls in tests.items():
        for p in urls:
            environ = create_environ(p)
            app_iter, status, headers = run_wsgi_app(app, environ)
            assert status == '200 OK'
            assert b''.join(app_iter).strip() == to_bytes(name)

    app_iter, status, headers = run_wsgi_app(
        app, create_environ('/missing'))
    assert status == '404 NOT FOUND'
    assert b''.join(app_iter).strip() == b'NOT FOUND'
开发者ID:geekKeen,项目名称:werkzeug,代码行数:28,代码来源:test_wsgi.py

示例4: test_shared_data_middleware

    def test_shared_data_middleware(self):
        def null_application(environ, start_response):
            start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])
            yield b'NOT FOUND'
        app = wsgi.SharedDataMiddleware(null_application, {
            '/':        path.join(path.dirname(__file__), 'res'),
            '/sources': path.join(path.dirname(__file__), 'res'),
            '/pkg':     ('werkzeug.debug', 'shared')
        })

        for p in '/test.txt', '/sources/test.txt':
            app_iter, status, headers = run_wsgi_app(app, create_environ(p))
            self.assert_equal(status, '200 OK')
            with closing(app_iter) as app_iter:
                data = b''.join(app_iter).strip()
            self.assert_equal(data, b'FOUND')

        app_iter, status, headers = run_wsgi_app(
            app, create_environ('/pkg/debugger.js'))
        with closing(app_iter) as app_iter:
            contents = b''.join(app_iter)
        self.assert_in(b'$(function() {', contents)

        app_iter, status, headers = run_wsgi_app(
            app, create_environ('/missing'))
        self.assert_equal(status, '404 NOT FOUND')
        self.assert_equal(b''.join(app_iter).strip(), b'NOT FOUND')
开发者ID:TheWaWaR,项目名称:werkzeug,代码行数:27,代码来源:wsgi.py

示例5: test_run_wsgi_app_closing_iterator

def test_run_wsgi_app_closing_iterator():
    got_close = []

    @implements_iterator
    class CloseIter(object):

        def __init__(self):
            self.iterated = False

        def __iter__(self):
            return self

        def close(self):
            got_close.append(None)

        def __next__(self):
            if self.iterated:
                raise StopIteration()
            self.iterated = True
            return 'bar'

    def bar(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/plain')])
        return CloseIter()

    app_iter, status, headers = run_wsgi_app(bar, {})
    assert status == '200 OK'
    assert list(headers) == [('Content-Type', 'text/plain')]
    assert next(app_iter) == 'bar'
    pytest.raises(StopIteration, partial(next, app_iter))
    app_iter.close()

    assert run_wsgi_app(bar, {}, True)[0] == ['bar']

    assert len(got_close) == 2
开发者ID:brunoais,项目名称:werkzeug,代码行数:35,代码来源:test_test.py

示例6: test_shared_data_middleware

def test_shared_data_middleware(tmpdir):
    def null_application(environ, start_response):
        start_response("404 NOT FOUND", [("Content-Type", "text/plain")])
        yield b"NOT FOUND"

    test_dir = str(tmpdir)
    with open(path.join(test_dir, to_native(u"äöü", "utf-8")), "w") as test_file:
        test_file.write(u"FOUND")

    app = wsgi.SharedDataMiddleware(
        null_application,
        {
            "/": path.join(path.dirname(__file__), "res"),
            "/sources": path.join(path.dirname(__file__), "res"),
            "/pkg": ("werkzeug.debug", "shared"),
            "/foo": test_dir,
        },
    )

    for p in "/test.txt", "/sources/test.txt", "/foo/äöü":
        app_iter, status, headers = run_wsgi_app(app, create_environ(p))
        assert status == "200 OK"
        with closing(app_iter) as app_iter:
            data = b"".join(app_iter).strip()
        assert data == b"FOUND"

    app_iter, status, headers = run_wsgi_app(app, create_environ("/pkg/debugger.js"))
    with closing(app_iter) as app_iter:
        contents = b"".join(app_iter)
    assert b"$(function() {" in contents

    app_iter, status, headers = run_wsgi_app(app, create_environ("/missing"))
    assert status == "404 NOT FOUND"
    assert b"".join(app_iter).strip() == b"NOT FOUND"
开发者ID:auready,项目名称:werkzeug,代码行数:34,代码来源:test_wsgi.py

示例7: send_invitations

 def send_invitations(self):
     """Call each application via our partyline connection protocol."""
     operator = self.operator_class(self)
     for script, application in [('', self.app)] + self.mounts.items():
         base_url = (self.base_url or '/'.rstrip('/')) + script
         environ = create_environ(path=self.invite_path, base_url=base_url)
         environ[self.partyline_key] = operator
         run_wsgi_app(application, environ)
开发者ID:whitmo,项目名称:wsgi_party,代码行数:8,代码来源:wsgi_party.py

示例8: _handle

    def _handle(self, parser):
        parser.add_argument("command", type=str, help="See ReadMe")
        parser.add_argument("-d", action='store_true', default=False, help="Open Debug")
        parser.add_argument("-s", action='store_true', default=False, help="Single Model")
        parser.add_argument("-i", action='store_true', default=False, help="Show Command info")

        self.options, arg = parser.parse_known_args()

        # 是否开启DEBUG模式,会忽略配置中的DEBUG,用于线上调试
        if self.options.d:
            open_debug(True)

        # 单元测试模式
        app = self.options.command.split('/')[0]
        if app in TEST_MODULE:
            argv = sys.argv
            argv.pop(1)
            # if len(argv) == 1:
            #     argv.append('discover')
            unittest.main(module=self.options.command.replace('/', '.'), argv=argv)
            exit()

        # 减少并发,单模式
        # 如果发现之前的还在执行则停止当前
        basedir = os.path.dirname('./tmp/')
        file_name = '%s/%s' % (basedir, self.options.command.replace('/', '.'))

        if self.options.s:
            if os.path.isfile(file_name):
                print 'Process is running'
                exit()
            if not os.path.exists(basedir):
                os.makedirs(basedir)
            with file(file_name, 'w'):
                os.utime(file_name, None)

        param_dict = {}
        for param in arg:
            mat = re.match(r'^--(.*)=(.*)', param)
            if mat and mat.lastindex:
                # 作为参数,通过manager.get_param()获取
                param_dict[mat.group(1)] = mat.group(2)
            else:
                pass

        application = PathDispatcher(create_app=create_app)
        builder = EnvironBuilder(path=self.options.command, method='get')

        builder.query_string = '&'.join(
            ["%s=%s" % (quote_plus(key), quote_plus(value)) for key, value in param_dict.items()])

        try:
            run_wsgi_app(application, builder.get_environ())
            if self.options.s:
                os.remove(file_name)
        except AppNotExist as e:
            return e.code
        return 0
开发者ID:ueffort,项目名称:Flask-Script,代码行数:58,代码来源:core.py

示例9: send_invitations

 def send_invitations(self, apps):
     '''Call each app at the invite route to establish a partyline. Called
     on init.'''
     PATH = '/__invite__/'
     for app_name, app in apps.items():
         environ = create_environ(path=PATH)
         environ[self.partyline_key] = self.operator_class(self)
         # A reference to the handling app. Used to id the app when
         # responding to a handling request.
         environ['partyline_handling_app'] = app_name
         run_wsgi_app(app, environ)
开发者ID:HatemAlSum,项目名称:ckan,代码行数:11,代码来源:middleware.py

示例10: test_run_wsgi_app

def test_run_wsgi_app():
    def foo(environ, start_response):
        start_response("200 OK", [("Content-Type", "text/plain")])
        yield "1"
        yield "2"
        yield "3"

    app_iter, status, headers = run_wsgi_app(foo, {})
    assert status == "200 OK"
    assert list(headers) == [("Content-Type", "text/plain")]
    assert next(app_iter) == "1"
    assert next(app_iter) == "2"
    assert next(app_iter) == "3"
    pytest.raises(StopIteration, partial(next, app_iter))

    got_close = []

    @implements_iterator
    class CloseIter(object):
        def __init__(self):
            self.iterated = False

        def __iter__(self):
            return self

        def close(self):
            got_close.append(None)

        def __next__(self):
            if self.iterated:
                raise StopIteration()
            self.iterated = True
            return "bar"

    def bar(environ, start_response):
        start_response("200 OK", [("Content-Type", "text/plain")])
        return CloseIter()

    app_iter, status, headers = run_wsgi_app(bar, {})
    assert status == "200 OK"
    assert list(headers) == [("Content-Type", "text/plain")]
    assert next(app_iter) == "bar"
    pytest.raises(StopIteration, partial(next, app_iter))
    app_iter.close()

    assert run_wsgi_app(bar, {}, True)[0] == ["bar"]

    assert len(got_close) == 2
开发者ID:dingens,项目名称:werkzeug,代码行数:48,代码来源:test_utils.py

示例11: test_hsts_defaults

def test_hsts_defaults():
    app = sslify(testapp.test_app)
    env = create_environ()
    env['wsgi.url_scheme'] = 'https'
    app_iter, status, headers = run_wsgi_app(app, env)
    assert status == '200 OK'
    assert headers['Strict-Transport-Security'] == 'max-age=31536000'
开发者ID:edmorley,项目名称:wsgi-sslify,代码行数:7,代码来源:test_sslify.py

示例12: test_hsts_subdomains

def test_hsts_subdomains():
    app = sslify(testapp.test_app, subdomains=True)
    env = create_environ()
    env['wsgi.url_scheme'] = 'https'
    app_iter, status, headers = run_wsgi_app(app, env)
    assert status == '200 OK'
    assert headers['Strict-Transport-Security'] == 'max-age=31536000; includeSubDomains'
开发者ID:edmorley,项目名称:wsgi-sslify,代码行数:7,代码来源:test_sslify.py

示例13: test_hsts_off

def test_hsts_off():
    app = sslify(testapp.test_app, hsts=False)
    env = create_environ()
    env['wsgi.url_scheme'] = 'https'
    app_iter, status, headers = run_wsgi_app(app, env)
    assert status == '200 OK'
    assert 'Strict-Transport-Security' not in headers
开发者ID:edmorley,项目名称:wsgi-sslify,代码行数:7,代码来源:test_sslify.py

示例14: test_closing_iterator

def test_closing_iterator():
    class Namespace(object):
        got_close = False
        got_additional = False

    class Response(object):
        def __init__(self, environ, start_response):
            self.start = start_response

        # Return a generator instead of making the object its own
        # iterator. This ensures that ClosingIterator calls close on
        # the iterable (the object), not the iterator.
        def __iter__(self):
            self.start('200 OK', [('Content-Type', 'text/plain')])
            yield 'some content'

        def close(self):
            Namespace.got_close = True

    def additional():
        Namespace.got_additional = True

    def app(environ, start_response):
        return ClosingIterator(Response(environ, start_response), additional)

    app_iter, status, headers = run_wsgi_app(
        app, create_environ(), buffered=True)

    assert ''.join(app_iter) == 'some content'
    assert Namespace.got_close
    assert Namespace.got_additional
开发者ID:brunoais,项目名称:werkzeug,代码行数:31,代码来源:test_wsgi.py

示例15: test_run_wsgi_app

    def test_run_wsgi_app(self):
        def foo(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/plain')])
            yield '1'
            yield '2'
            yield '3'

        app_iter, status, headers = run_wsgi_app(foo, {})
        assert status == '200 OK'
        assert headers == [('Content-Type', 'text/plain')]
        assert app_iter.next() == '1'
        assert app_iter.next() == '2'
        assert app_iter.next() == '3'
        self.assert_raises(StopIteration, app_iter.next)

        got_close = []

        class CloseIter(object):
            def __init__(self):
                self.iterated = False

            def __iter__(self):
                return self

            def close(self):
                got_close.append(None)

            def next(self):
                if self.iterated:
                    raise StopIteration()
                self.iterated = True
                return 'bar'

        def bar(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/plain')])
            return CloseIter()

        app_iter, status, headers = run_wsgi_app(bar, {})
        assert status == '200 OK'
        assert headers == [('Content-Type', 'text/plain')]
        assert app_iter.next() == 'bar'
        self.assert_raises(StopIteration, app_iter.next)
        app_iter.close()

        assert run_wsgi_app(bar, {}, True)[0] == ['bar']

        assert len(got_close) == 2
开发者ID:Mirabis,项目名称:usntssearch,代码行数:47,代码来源:utils.py


注:本文中的werkzeug.test.run_wsgi_app函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。