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


Python Request.blank方法代码示例

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


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

示例1: test_custom_json_encoder

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_custom_json_encoder():
    policy = JWTAuthenticationPolicy("secret")
    principal_id = uuid.uuid4()
    claim_value = uuid.uuid4()
    with pytest.raises(TypeError):
        token = policy.create_token("subject", uuid_value=claim_value)
    policy = JWTAuthenticationPolicy("secret", json_encoder=MyCustomJsonEncoder)

    request = Request.blank("/")
    request.authorization = (
        "JWT",
        policy.create_token(principal_id, uuid_value=claim_value),
    )
    request.jwt_claims = policy.get_claims(request)
    assert policy.unauthenticated_userid(request) == str(principal_id)
    assert request.jwt_claims.get("uuid_value") == str(claim_value) 
开发者ID:wichert,项目名称:pyramid_jwt,代码行数:18,代码来源:test_policy.py

示例2: test_ctx_cross_request

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_ctx_cross_request(self):
        def peek_ctx():
            print("peek_ctx", ctx.__dict__)
            ctx.count = getattr(ctx, "count", 0) + 1
            return ctx.count

        app = Firefly()
        app.add_route("/", peek_ctx)

        request = Request.blank("/", POST='{}')
        response = app.process_request(request)
        assert response.status == '200 OK'
        assert response.json == 1

        # Subsequent requests should not have count in the context
        request = Request.blank("/", POST='{}')
        response = app.process_request(request)
        assert response.status == '200 OK'
        assert response.json == 1 
开发者ID:rorodata,项目名称:firefly,代码行数:21,代码来源:test_app.py

示例3: test_process_request_with_body

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_process_request_with_body(self, mock_create_token):
        req = Request.blank(self.ordered_url)
        req.method = 'POST'
        old_body = {'fake_key': 'fake_value'}
        req.body = jsonutils.dump_as_bytes(old_body)

        self.alarmrc.process_request(req)

        body_dict = jsonutils.loads(req.body)
        self.assertDictEqual(old_body,
                             body_dict['trigger']['params']['data'])
        self.assertEqual(self.alarm_url['05_key'],
                         body_dict['trigger']['params']['credential'])
        self.assertEqual(self.alarm_url['03_monitoring_policy_name'],
                         body_dict['trigger']['policy_name'])
        self.assertEqual(self.alarm_url['04_action_name'],
                         body_dict['trigger']['action_name']) 
开发者ID:openstack,项目名称:tacker,代码行数:19,代码来源:test_alarm_receiver.py

示例4: test_user

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_user():
    assert c.user.url() .endswith('/u/test-admin/')
    assert c.user.script_name .endswith('/u/test-admin/')
    assert_equal(set(p.shortname for p in c.user.my_projects()),
                 set(['test', 'test2', 'u/test-admin', 'adobe-1', '--init--']))
    # delete one of the projects and make sure it won't appear in my_projects()
    p = M.Project.query.get(shortname='test2')
    p.deleted = True
    ThreadLocalORMSession.flush_all()
    assert_equal(set(p.shortname for p in c.user.my_projects()),
                 set(['test', 'u/test-admin', 'adobe-1', '--init--']))
    u = M.User.register(dict(
        username='nosetest-user'))
    ThreadLocalORMSession.flush_all()
    assert_equal(u.private_project().shortname, 'u/nosetest-user')
    roles = g.credentials.user_roles(
        u._id, project_id=u.private_project().root_project._id)
    assert len(roles) == 3, roles
    u.set_password('foo')
    provider = plugin.LocalAuthenticationProvider(Request.blank('/'))
    assert provider._validate_password(u, 'foo')
    assert not provider._validate_password(u, 'foobar')
    u.set_password('foobar')
    assert provider._validate_password(u, 'foobar')
    assert not provider._validate_password(u, 'foo') 
开发者ID:apache,项目名称:allura,代码行数:27,代码来源:test_auth.py

示例5: disable_project_users

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def disable_project_users(self, project, reason=None):
        provider = AuthenticationProvider.get(Request.blank('/'))
        users = project.admins() + project.users_with_role('Developer')
        for user in users:
            if user.disabled:
                log.info('User %s is already disabled', user.username)
                continue
            provider.disable_user(user, audit=False)
            msg = 'Account disabled because project {}{} is deleted. Reason: {}'.format(
                project.neighborhood.url_prefix,
                project.shortname,
                reason)
            auditlog = h.auditlog_user(msg, user=user)
            if auditlog:
                session(auditlog).flush(auditlog)
            else:
                log.error('For some reason no auditlog written in disable_project_users for: %s %s', user, msg)
            # `users` can contain duplicates. Make sure changes are visible
            # to next iterations, so that `user.disabled` check works.
            session(user).expunge(user) 
开发者ID:apache,项目名称:allura,代码行数:22,代码来源:plugin.py

示例6: execute

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def execute(cls, options):
        provider = ProjectRegistrationProvider.get()
        auth_provider = AuthenticationProvider.get(Request.blank('/'))
        for proj in options.projects:
            proj = cls.get_project(proj)
            if proj:
                if proj.is_user_project:
                    # disable user as well
                    user = proj.user_project_of
                    if user:
                        auth_provider.disable_user(user, audit=False)
                        msg = 'Account disabled because user-project was specified for deletion. Reason: {}'.format(
                            options.reason)
                        log_entry = h.auditlog_user(msg, user=user)
                        session(log_entry).flush(log_entry)
                    else:
                        log.info('Could not find associated user for user-project %s', proj.shortname)

                log.info('Purging %s Reason: %s', proj.url(), options.reason)
                provider.purge_project(proj, disable_users=options.disable_users, reason=options.reason) 
开发者ID:apache,项目名称:allura,代码行数:22,代码来源:delete_projects.py

示例7: get

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def get(self, url, **extra):
        request = Request.blank(url, method="GET", **extra)
        context = self.settings.pop("context", request)
        response = GraphQLView(
            request=request, schema=self.schema, context=context, **self.settings
        )
        return response.dispatch_request(request) 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:9,代码来源:app.py

示例8: post

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def post(self, url, **extra):
        extra["POST"] = extra.pop("data")
        request = Request.blank(url, method="POST", **extra)
        context = self.settings.pop("context", request)
        response = GraphQLView(
            request=request, schema=self.schema, context=context, **self.settings
        )
        return response.dispatch_request(request) 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:10,代码来源:app.py

示例9: put

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def put(self, url, **extra):
        request = Request.blank(url, method="PUT", **extra)
        context = self.settings.pop("context", request)
        response = GraphQLView(
            request=request, schema=self.schema, context=context, **self.settings
        )
        return response.dispatch_request(request) 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:9,代码来源:app.py

示例10: make_request

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def make_request(body, method='POST'):
    """
    Helper to make a request
    """
    request = Request.blank('/')
    request.method = 'POST'
    request.body = body.encode('utf-8')
    request.method = method
    return request 
开发者ID:edx,项目名称:xblock-lti-consumer,代码行数:11,代码来源:test_utils.py

示例11: test_minimal_roundtrip

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_minimal_roundtrip():
    policy = JWTAuthenticationPolicy("secret")
    request = Request.blank("/")
    request.authorization = ("JWT", policy.create_token(15))
    request.jwt_claims = policy.get_claims(request)
    assert policy.unauthenticated_userid(request) == 15 
开发者ID:wichert,项目名称:pyramid_jwt,代码行数:8,代码来源:test_policy.py

示例12: test_audience_valid

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_audience_valid():
    policy = JWTAuthenticationPolicy("secret", audience="example.org")
    token = policy.create_token(15, name="Jöhn", admin=True, audience="example.org")
    request = Request.blank("/")
    request.authorization = ("JWT", token)
    jwt_claims = policy.get_claims(request)
    assert jwt_claims["aud"] == "example.org" 
开发者ID:wichert,项目名称:pyramid_jwt,代码行数:9,代码来源:test_policy.py

示例13: test_audience_invalid

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_audience_invalid():
    policy = JWTAuthenticationPolicy("secret", audience="example.org")
    token = policy.create_token(15, name="Jöhn", admin=True, audience="example.com")
    request = Request.blank("/")
    request.authorization = ("JWT", token)
    jwt_claims = policy.get_claims(request)
    assert jwt_claims == {} 
开发者ID:wichert,项目名称:pyramid_jwt,代码行数:9,代码来源:test_policy.py

示例14: test_extra_claims

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_extra_claims():
    policy = JWTAuthenticationPolicy("secret")
    token = policy.create_token(15, name="Jöhn", admin=True)
    request = Request.blank("/")
    request.authorization = ("JWT", token)
    jwt_claims = policy.get_claims(request)
    assert jwt_claims["name"] == "Jöhn"
    assert jwt_claims["admin"] 
开发者ID:wichert,项目名称:pyramid_jwt,代码行数:10,代码来源:test_policy.py

示例15: test_wrong_auth_scheme

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_wrong_auth_scheme():
    policy = JWTAuthenticationPolicy("secret")
    request = Request.blank("/")
    request.authorization = ("Other", policy.create_token(15))
    request.jwt_claims = policy.get_claims(request)
    assert policy.unauthenticated_userid(request) is None 
开发者ID:wichert,项目名称:pyramid_jwt,代码行数:8,代码来源:test_policy.py


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