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


Python Client.open方法代码示例

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


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

示例1: test_check_login

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
def test_check_login():
    from glashammer.bundles.auth import setup_auth, login
    from glashammer.bundles.sessions import get_session

    called = []

    def check(u, p):
        called.append((u, p))
        return u == p

    def view(req):
        login('a')
        return Response()

    def setup_app(app):
        app.add_setup(setup_auth)
        app.connect_event('password-check', check)
        app.add_url('/', 'a/b', view=view)

    app = make_app(setup_app, 'test_output')
    c = Client(app)
    c.open()

    session = get_session()
    token_key = get_app().conf['auth/token_key']
    assert token_key in session
    assert session[token_key] == 'a'
开发者ID:passy,项目名称:glashammer-rdrei,代码行数:29,代码来源:test_all.py

示例2: TestJsonRestService

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
class TestJsonRestService(object):

    def setup(self):
        def _setup_json(app):
            app.add_url('/', '', view=_Service())

        app = make_app(_setup_json, 'test_output')

        self.client = Client(app)

    def test_get(self):
        ai, st, h = self.client.open(method='GET')
        s = list(ai)[0]
        assert 'GET' in s

    def test_post(self):
        ai, st, h = self.client.open(method='POST')
        s = list(ai)[0]
        assert 'POST' in s

    def test_put(self):
        ai, st, h = self.client.open(method='PUT')
        s = list(ai)[0]
        assert 'PUT' in s

    def test_delete(self):
        ai, st, h = self.client.open(method='DELETE')
        s = list(ai)[0]
        assert 'DELETE' in s
开发者ID:passy,项目名称:glashammer-rdrei,代码行数:31,代码来源:test_all.py

示例3: TestJsonRest

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
class TestJsonRest(object):

    def setup(self):
        app = load_app_from_path('examples/jsonrest/run.py')
        self.c = Client(app)

    def test_index(self):
        iter, status, headers = self.c.open()
        s = ''.join(iter)
        assert  """
    <a href="#" id="get_link">GET</a>
    <a href="#" id="post_link">POST</a>
    <a href="#" id="put_link">PUT</a>
    <a href="#" id="delete_link">DELETE</a>
""".strip('\n') in s

    def test_get(self):
        iter, status, headers = self.c.open('/svc')
        d = loads(''.join(iter))
        assert d['type'] == 'GET'

    def test_put(self):
        iter, status, headers = self.c.put('/svc')
        d = loads(''.join(iter))
        assert d['type'] == 'PUT'

    def test_delete(self):
        iter, status, headers = self.c.delete('/svc')
        d = loads(''.join(iter))
        assert d['type'] == 'DELETE'

    def test_post(self):
        iter, status, headers = self.c.post('/svc')
        d = loads(''.join(iter))
        assert d['type'] == 'POST'
开发者ID:passy,项目名称:glashammer-rdrei,代码行数:37,代码来源:test_all.py

示例4: test_context_error_propagates

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
def test_context_error_propagates(app, environ):
    # The Protector relies on any errors being raised by a request 
    # context manager being propagated all the way to the application
    # error handler. Should these test cases fail, then the Protector
    # will fail to do its job.
    class CustomErrorClass(Exception):
        pass

    err = CustomErrorClass()
    tracked = []

    @app.context
    def error_func():
        raise err
        yield

    @app.error_handler.register(CustomErrorClass)
    def track_error(e):
        tracked.append(e)
        return BaseResponse("Foo")

    client = Client(app)
    client.open(environ)

    assert tracked == [err]
开发者ID:geniphi,项目名称:findig,代码行数:27,代码来源:test_app.py

示例5: WsgiAPIClient

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
class WsgiAPIClient(BaseAPIClient):
    wsgi_app = None
    server_cosmos = None

    def __init__(self, *args, **kwargs):
        self.client = WerkzeugTestClient(self.wsgi_app, response_wrapper=Response)
        spec = self.call(SpecEndpoint())
        super(WsgiAPIClient, self).__init__(*args, spec=spec, **kwargs)

    def make_request(self, endpoint, request):
        kwargs = {
            "method": request.method,
            "data": request.data,
            "headers": request.headers
        }
        # Content-Type should be provided as kwarg because otherwise we can't
        # access request.mimetype
        if 'Content-Type' in request.headers:
            kwargs['content_type'] = request.headers.pop('Content-Type')

        if self.server_cosmos is None:
            r = self.client.open(path=request.url, **kwargs)
        else:
            with cosmos.swap(self.server_cosmos):
                r = self.client.open(path=request.url, **kwargs)


        resp = requests.Response()
        resp._content = r.data
        resp.headers = CaseInsensitiveDict(r.headers)
        resp.status_code = r.status_code

        return resp
开发者ID:cosmic-api,项目名称:cosmic.py,代码行数:35,代码来源:client.py

示例6: test_resent_cookie

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
def test_resent_cookie():
    """Test that the client resends cookies on subsequent requests
    """
    c = Client(cookie_app)
    c.open()
    appiter, code, headers = c.open()
    assert ''.join(appiter) == 'test=test'
开发者ID:AndryulE,项目名称:kitsune,代码行数:9,代码来源:test_test.py

示例7: test_disable_cookies

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
def test_disable_cookies():
    """Ensure that cookies are not stored when use_cookies is False in the
    client
    """
    c = Client(cookie_app, use_cookies=False)
    c.open()
    appiter, code, headers = c.open()
    assert ''.join(appiter) == 'No Cookie'
开发者ID:AndryulE,项目名称:kitsune,代码行数:10,代码来源:test_test.py

示例8: test_cookie_for_different_path

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
def test_cookie_for_different_path():
    """Test that the client resends cookies on subsequent requests for
    different paths
    """
    c = Client(cookie_app)
    c.open('/path1')
    appiter, code, headers = c.open('/path2')
    assert ''.join(appiter) == 'test=test'
开发者ID:AndryulE,项目名称:kitsune,代码行数:10,代码来源:test_test.py

示例9: test_autorules_client

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
def test_autorules_client():
    app = gh_app(_setup)
    c = Client(app)

    i, s, h = c.open('/')
    assert '404' in s

    i, s, h = c.open('/pages/')
    print i, s, h
    assert '200' in s
    assert 'hello' in ''.join(i)
开发者ID:passy,项目名称:glashammer-rdrei,代码行数:13,代码来源:test_appliance.py

示例10: test_session_setup

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
def test_session_setup():

    def _setup_sessions(app):
        from glashammer.bundles.sessions import setup_app
        app.add_setup(setup_app)

        app.add_url('/', '', view=_sessioned_view)

    app = make_app(_setup_sessions, 'test_output')

    c = Client(app)
    c.open()
开发者ID:passy,项目名称:glashammer-rdrei,代码行数:14,代码来源:test_all.py

示例11: test_event_log_handler

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
def test_event_log_handler():
    
    logs = []

    def log(level, record):
        logs.append((level, record))

    def setup_app(app):
        app.connect_event('log', log)

    app = make_app(setup_app, 'test_output')
    c = Client(app)
    c.open()
    assert len(logs) > 5
开发者ID:passy,项目名称:glashammer-rdrei,代码行数:16,代码来源:test_all.py

示例12: _test_finalized

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
def _test_finalized():

    def _bview(req):
        app = get_app()
        assert_raises((RuntimeError,), app.add_config_var, 'a', str, 'a')
        return Response('hello')

    def _setup_app(app):
        app.add_url('/', 'hoo', _bview)

    app = make_app(_setup_app, 'test_output')

    c = Client(app)
    c.open()
开发者ID:passy,项目名称:glashammer-rdrei,代码行数:16,代码来源:test_all.py

示例13: TestHelloWorld

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
class TestHelloWorld(object):

    def setup(self):
        app = load_app_from_path('examples/helloworld/run.py')
        self.c = Client(app)

    def test_index(self):
        iter, status, headers = self.c.open()
        assert ' '.join(iter) == '<h1>Hello World</h1>'
        assert status == '200 OK'

    def test_notfound(self):
        iter, status, headers = self.c.open('/blah')
        assert status == '404 NOT FOUND'
        assert '404 Not Found' in ' '.join(iter)
开发者ID:passy,项目名称:glashammer-rdrei,代码行数:17,代码来源:test_all.py

示例14: test_vote_page_check_scope

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
	def test_vote_page_check_scope(self):
		cache = StrictRedis(db=config.tokens_cache_redis_db)

		h = Headers()
		h.add('Authorization',
			  'Basic ' + base64.b64encode(config.test_token + ':'))
		rv = Client.open(self.client, path='/people/v1/vote/hhauer',
						 headers=h)
		self.assert_200(rv)
		
		cache.srem(config.people_scope_vote, '[email protected]')

		rv = Client.open(self.client, path='/people/v1/vote/hhauer',
						 headers=h)
		self.assert_403(rv)
		cache.sadd(config.people_scope_vote, '[email protected]')
开发者ID:fterdalpdx,项目名称:finti,代码行数:18,代码来源:test_vote_auth.py

示例15: test_admin_page_rejects_bad_password

# 需要导入模块: from werkzeug.test import Client [as 别名]
# 或者: from werkzeug.test.Client import open [as 别名]
 def test_admin_page_rejects_bad_password(self):
     """ Check that incorrect password won't allow access """
     h = Headers()
     auth = '{0}:foo'.format(Config.USERNAME).encode('ascii')
     h.add('Authorization', b'Basic ' + base64.b64encode(auth))
     rv = Client.open(self.client, path='/', headers=h)
     self.assert_401(rv)
开发者ID:jmcarp,项目名称:cg-quotas-db,代码行数:9,代码来源:tests.py


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