當前位置: 首頁>>代碼示例>>Python>>正文


Python testing.create_environ方法代碼示例

本文整理匯總了Python中falcon.testing.create_environ方法的典型用法代碼示例。如果您正苦於以下問題:Python testing.create_environ方法的具體用法?Python testing.create_environ怎麽用?Python testing.create_environ使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在falcon.testing的用法示例。


在下文中一共展示了testing.create_environ方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_whole_serializer_validation_as_hhtp_bad_request

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_whole_serializer_validation_as_hhtp_bad_request(req):

    class TestSerializer(BaseSerializer):
        one = StringField("one different than two")
        two = StringField("two different than one")

        def validate(self, object_dict, partial=False):
            super().validate(object_dict, partial)
            # possible use case: kind of uniqueness relationship
            if object_dict['one'] == object_dict['two']:
                raise ValidationError("one must be different than two")

    class TestResource(Resource):
        serializer = TestSerializer()

    resource = TestResource()

    env = create_environ(
        body=json.dumps({'one': 'foo', 'two': 'foo'}),
        headers={'Content-Type': 'application/json'},
    )

    with pytest.raises(errors.HTTPBadRequest):
        resource.require_validated(Request(env)) 
開發者ID:swistakm,項目名稱:graceful,代碼行數:26,代碼來源:test_resources.py

示例2: test_require_representation_application_json

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_require_representation_application_json():
    resource = TestResource()

    # simple application/json content type
    env = create_environ(
        body=json.dumps({'one': 'foo', 'two': 'foo'}),
        headers={'Content-Type': 'application/json'},
    )

    representation = resource.require_representation(Request(env))
    assert isinstance(representation, dict)

    # application/json content type with charset param
    env = create_environ(
        body=json.dumps({'one': 'foo', 'two': 'foo'}),
        headers={'Content-Type': 'application/json; charset=UTF-8'},
    )

    representation = resource.require_representation(Request(env))
    assert isinstance(representation, dict) 
開發者ID:swistakm,項目名稱:graceful,代碼行數:22,代碼來源:test_resources.py

示例3: test_ignore_case_role_check

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_ignore_case_role_check(self):
        lowercase_action = "example:lowercase_monasca_user"
        uppercase_action = "example:uppercase_monasca_user"

        monasca_user_context = request.Request(
            testing.create_environ(
                path="/",
                headers={
                    "X_USER_ID": "monasca_user",
                    "X_PROJECT_ID": "fake",
                    "X_ROLES": "MONASCA_user"
                }
            )
        )
        self.assertTrue(policy.authorize(monasca_user_context.context,
                                         lowercase_action,
                                         {}))
        self.assertTrue(policy.authorize(monasca_user_context.context,
                                         uppercase_action,
                                         {})) 
開發者ID:openstack,項目名稱:monasca-log-api,代碼行數:22,代碼來源:test_policy.py

示例4: test_use_context_from_request

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_use_context_from_request(self):
        req = request.Request(
            testing.create_environ(
                path='/',
                headers={
                    'X_AUTH_TOKEN': '111',
                    'X_USER_ID': '222',
                    'X_PROJECT_ID': '333',
                    'X_ROLES': 'terminator,predator'
                }
            )
        )

        self.assertEqual('111', req.context.auth_token)
        self.assertEqual('222', req.user_id)
        self.assertEqual('333', req.project_id)
        self.assertEqual(['terminator', 'predator'], req.roles) 
開發者ID:openstack,項目名稱:monasca-log-api,代碼行數:19,代碼來源:test_request.py

示例5: test_validate_context_type

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_validate_context_type(self):
        with mock.patch.object(validation,
                               'validate_content_type') as vc_type, \
                mock.patch.object(validation,
                                  'validate_payload_size') as vp_size, \
                mock.patch.object(validation,
                                  'validate_cross_tenant') as vc_tenant:
            req = request.Request(testing.create_environ())
            vc_type.side_effect = Exception()

            try:
                req.validate(['test'])
            except Exception as ex:
                self.assertEqual(1, vc_type.call_count)
                self.assertEqual(0, vp_size.call_count)
                self.assertEqual(0, vc_tenant.call_count)

                self.assertIsInstance(ex, Exception) 
開發者ID:openstack,項目名稱:monasca-log-api,代碼行數:20,代碼來源:test_request.py

示例6: test_validate_payload_size

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_validate_payload_size(self):
        with mock.patch.object(validation,
                               'validate_content_type') as vc_type, \
                mock.patch.object(validation,
                                  'validate_payload_size') as vp_size, \
                mock.patch.object(validation,
                                  'validate_cross_tenant') as vc_tenant:

            req = request.Request(testing.create_environ())
            vp_size.side_effect = Exception()

            try:
                req.validate(['test'])
            except Exception as ex:
                self.assertEqual(1, vc_type.call_count)
                self.assertEqual(1, vp_size.call_count)
                self.assertEqual(0, vc_tenant.call_count)

                self.assertIsInstance(ex, Exception) 
開發者ID:openstack,項目名稱:monasca-log-api,代碼行數:21,代碼來源:test_request.py

示例7: test_validate_cross_tenant

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_validate_cross_tenant(self):
        with mock.patch.object(validation,
                               'validate_content_type') as vc_type, \
                mock.patch.object(validation,
                                  'validate_payload_size') as vp_size, \
                mock.patch.object(validation,
                                  'validate_cross_tenant') as vc_tenant:

            req = request.Request(testing.create_environ())
            vc_tenant.side_effect = Exception()

            try:
                req.validate(['test'])
            except Exception as ex:
                self.assertEqual(1, vc_type.call_count)
                self.assertEqual(1, vp_size.call_count)
                self.assertEqual(1, vc_tenant.call_count)

                self.assertIsInstance(ex, Exception) 
開發者ID:openstack,項目名稱:monasca-log-api,代碼行數:21,代碼來源:test_request.py

示例8: create_req

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def create_req(ctx, body):
    '''creates a falcon request'''
    env = testing.create_environ(
        path='/',
        query_string='',
        protocol='HTTP/1.1',
        scheme='http',
        host='falconframework.org',
        port=None,
        headers={'Content-Type': 'application/json'},
        app='',
        body=body,
        method='POST',
        wsgierrors=None,
        file_wrapper=None)
    req = falcon.Request(env)
    req.context = ctx
    return req 
開發者ID:airshipit,項目名稱:shipyard,代碼行數:20,代碼來源:test_actions_api.py

示例9: environ_factory

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def environ_factory():
    def create_env(method, path, server_name):
        return create_environ(
            host=server_name,
            path=path,
        )
    return create_env 
開發者ID:p1c2u,項目名稱:openapi-core,代碼行數:9,代碼來源:conftest.py

示例10: req

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def req():
    """Simple GET Request fixture."""
    env = create_environ()
    return Request(env) 
開發者ID:swistakm,項目名稱:graceful,代碼行數:6,代碼來源:fixtures.py

示例11: test_options

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_options(resp):
    """
    Test that options is a json serialized output of resource.describe()

    Args:
        req (falcon.Request): request instance object provided by ``req``
            pytest fixture
        resp (falcon.Response): responce instance provided by ``resp`` pytest
            fixture
    """
    # note: creating request is optional here since we bypass whole falcon
    #       routing and dispatching procedure
    env = create_environ(method="OPTIONS")
    req = Request(env)   # noqa
    resource = Resource()

    resource.on_options(req, resp)

    assert all([
        'OPTIONS' in _retrieve_header(resp, 'allow'),
        'GET' in _retrieve_header(resp, 'allow'),
    ])
    assert resp.status == falcon.HTTP_200
    assert json.loads(resp.body)
    # assert this is obviously the same
    assert resource.describe(req, resp) == json.loads(resp.body) 
開發者ID:swistakm,項目名稱:graceful,代碼行數:28,代碼來源:test_resources.py

示例12: test_options_with_additional_args

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_options_with_additional_args(req, resp):
    """
    Test that requesting OPTIONS will succeed even if not expected additional
    kwargs are passed.

    Note: this is a case when OPTIONS are requested on resource that is routed
        with URL template.
    """
    # note: creating request is optional here since we bypass whole falcon
    #       routing and dispatching procedure
    env = create_environ(method="OPTIONS")
    req = Request(env)   # noqa
    resource = Resource()

    resource.on_options(req, resp, additionnal_kwarg="foo") 
開發者ID:swistakm,項目名稱:graceful,代碼行數:17,代碼來源:test_resources.py

示例13: test_parameter_with_many_and_required

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_parameter_with_many_and_required():
    class SomeResource(Resource):
        foo = IntParam(details="give me foo", required=True, many=True)

    env = create_environ(query_string="foo=1&foo=2")
    resource = SomeResource()
    params = resource.require_params(Request(env))

    assert isinstance(params['foo'], Iterable)
    assert set(params['foo']) == {1, 2} 
開發者ID:swistakm,項目名稱:graceful,代碼行數:12,代碼來源:test_resources.py

示例14: test_parameter_with_validation_enabled_passes

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_parameter_with_validation_enabled_passes(query_string):
    class SomeResource(Resource):
        number = IntParam(
            details="number with min/max bounds",
            validators=[min_validator(10), max_validator(20)]
        )

    env = create_environ(query_string=query_string)
    resource = SomeResource()
    params = resource.require_params(Request(env))

    assert isinstance(params['number'], int) 
開發者ID:swistakm,項目名稱:graceful,代碼行數:14,代碼來源:test_resources.py

示例15: test_parameter_with_many_and_default

# 需要導入模塊: from falcon import testing [as 別名]
# 或者: from falcon.testing import create_environ [as 別名]
def test_parameter_with_many_and_default(req):
    class SomeResource(Resource):
        foo = StringParam(details="give me foo", default='baz', many=True)

    resource = SomeResource()
    params = resource.require_params(req)

    assert isinstance(params['foo'], Iterable)
    assert params['foo'] == ['baz']

    env = create_environ(query_string="foo=bar")
    params = resource.require_params(Request(env))

    assert isinstance(params['foo'], Iterable)
    assert params['foo'] == ['bar'] 
開發者ID:swistakm,項目名稱:graceful,代碼行數:17,代碼來源:test_resources.py


注:本文中的falcon.testing.create_environ方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。