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


Python StubTreq.content方法代码示例

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


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

示例1: test_mismatched_request_causes_failure

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import content [as 别名]
    def test_mismatched_request_causes_failure(self):
        """
        If a request is made that is not expected as the next request,
        causes a failure.
        """
        sequence = RequestSequence(
            [
                (
                    (b"get", "https://anything/", {b"1": [b"2"]}, HasHeaders({b"1": [b"1"]}), b"what"),
                    (418, {}, b"body"),
                ),
                ((b"get", "http://anything", {}, HasHeaders({b"2": [b"1"]}), b"what"), (202, {}, b"deleted")),
            ],
            async_failure_reporter=self.async_failures.append,
        )

        stub = StubTreq(StringStubbingResource(sequence))
        get = partial(stub.get, "https://anything?1=2", data=b"what", headers={b"1": b"1"})

        resp = self.successResultOf(get())

        self.assertEqual(418, resp.code)
        self.assertEqual(b"body", self.successResultOf(stub.content(resp)))
        self.assertEqual([], self.async_failures)

        resp = self.successResultOf(get())
        self.assertEqual(500, resp.code)
        self.assertEqual(1, len(self.async_failures))
        self.assertIn("Expected the next request to be", self.async_failures[0])

        self.assertFalse(sequence.consumed())
开发者ID:twisted,项目名称:treq,代码行数:33,代码来源:test_testing.py

示例2: test_mismatched_request_causes_failure

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import content [as 别名]
    def test_mismatched_request_causes_failure(self):
        """
        If a request is made that is not expected as the next request,
        causes a failure.
        """
        sequence = RequestSequence(
            [(('get', 'https://anything/', {'1': ['2']},
               HasHeaders({'1': ['1']}), 'what'),
              (418, {}, 'body')),
             (('get', 'http://anything', {}, HasHeaders({'2': ['1']}), 'what'),
              (202, {}, 'deleted'))],
            async_failure_reporter=self.async_failures.append)

        stub = StubTreq(StringStubbingResource(sequence))
        get = partial(stub.get, 'https://anything?1=2', data='what',
                      headers={'1': '1'})

        resp = self.successResultOf(get())
        self.assertEqual(418, resp.code)
        self.assertEqual('body', self.successResultOf(stub.content(resp)))
        self.assertEqual([], self.async_failures)

        resp = self.successResultOf(get())
        self.assertEqual(500, resp.code)
        self.assertEqual(1, len(self.async_failures))
        self.assertIn("Expected the next request to be",
                      self.async_failures[0])

        self.assertFalse(sequence.consumed())
开发者ID:cyli,项目名称:treq,代码行数:31,代码来源:test_testing.py

示例3: test_works_with_mock_any

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import content [as 别名]
    def test_works_with_mock_any(self):
        """
        :obj:`mock.ANY` can be used with the request parameters.
        """
        sequence = RequestSequence(
            [((ANY, ANY, ANY, ANY, ANY), (418, {}, b"body"))], async_failure_reporter=self.async_failures.append
        )
        stub = StubTreq(StringStubbingResource(sequence))

        with sequence.consume(sync_failure_reporter=self.fail):
            d = stub.get("https://anything", data=b"what", headers={b"1": b"1"})
            resp = self.successResultOf(d)
            self.assertEqual(418, resp.code)
            self.assertEqual(b"body", self.successResultOf(stub.content(resp)))

        self.assertEqual([], self.async_failures)

        # the expected requests have all been made
        self.assertTrue(sequence.consumed())
开发者ID:twisted,项目名称:treq,代码行数:21,代码来源:test_testing.py

示例4: test_interacts_successfully_with_istub

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import content [as 别名]
    def test_interacts_successfully_with_istub(self):
        """
        The :obj:`IStringResponseStubs` is passed the correct parameters with
        which to evaluate the response, and the response is returned.
        """
        resource = StringStubbingResource(
            self._get_response_for(
                (b"DELETE", "http://what/a/thing", {b"page": [b"1"]}, {b"x-header": [b"eh"]}, b"datastr"),
                (418, {b"x-response": b"responseheader"}, b"response body"),
            )
        )

        stub = StubTreq(resource)

        d = stub.delete("http://what/a/thing", headers={b"x-header": b"eh"}, params={b"page": b"1"}, data=b"datastr")
        resp = self.successResultOf(d)
        self.assertEqual(418, resp.code)
        self.assertEqual([b"responseheader"], resp.headers.getRawHeaders(b"x-response"))
        self.assertEqual(b"response body", self.successResultOf(stub.content(resp)))
开发者ID:twisted,项目名称:treq,代码行数:21,代码来源:test_testing.py

示例5: test_interacts_successfully_with_istub

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import content [as 别名]
    def test_interacts_successfully_with_istub(self):
        """
        The :obj:`IStringResponseStubs` is passed the correct parameters with
        which to evaluate the response, and the response is returned.
        """
        resource = StringStubbingResource(self._get_response_for(
            ('DELETE', 'http://what/a/thing', {'page': ['1']},
             {'x-header': ['eh']}, 'datastr'),
            (418, {'x-response': 'responseheader'}, 'response body')))

        stub = StubTreq(resource)

        d = stub.delete('http://what/a/thing', headers={'x-header': 'eh'},
                        params={'page': '1'}, data='datastr')
        resp = self.successResultOf(d)
        self.assertEqual(418, resp.code)
        self.assertEqual(['responseheader'],
                         resp.headers.getRawHeaders('x-response'))
        self.assertEqual('response body',
                         self.successResultOf(stub.content(resp)))
开发者ID:cyli,项目名称:treq,代码行数:22,代码来源:test_testing.py

示例6: test_providing_resource_to_stub_treq

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import content [as 别名]
    def test_providing_resource_to_stub_treq(self):
        """
        The resource provided to StubTreq responds to every request no
        matter what the URI or parameters or data.
        """
        verbs = ('GET', 'PUT', 'HEAD', 'PATCH', 'DELETE', 'POST')
        urls = (
            'http://supports-http.com',
            'https://supports-https.com',
            'http://this/has/a/path/and/invalid/domain/name'
            'https://supports-https.com:8080',
            'http://supports-http.com:8080',
        )
        params = (None, {}, {'page': [1]})
        headers = (None, {}, {'x-random-header': ['value', 'value2']})
        data = (None, "", 'some data', '{"some": "json"}')

        stub = StubTreq(_StaticTestResource())

        combos = (
            (verb, {"url": url, "params": p, "headers": h, "data": d})
            for verb in verbs
            for url in urls
            for p in params
            for h in headers
            for d in data
        )
        for combo in combos:
            verb, kwargs = combo
            deferreds = (stub.request(verb, **kwargs),
                         getattr(stub, verb.lower())(**kwargs))
            for d in deferreds:
                resp = self.successResultOf(d)
                self.assertEqual(418, resp.code)
                self.assertEqual(['teapot!'],
                                 resp.headers.getRawHeaders('x-teapot'))
                self.assertEqual("" if verb == "HEAD" else "I'm a teapot",
                                 self.successResultOf(stub.content(resp)))
开发者ID:cyli,项目名称:treq,代码行数:40,代码来源:test_testing.py

示例7: test_providing_resource_to_stub_treq

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import content [as 别名]
    def test_providing_resource_to_stub_treq(self):
        """
        The resource provided to StubTreq responds to every request no
        matter what the URI or parameters or data.
        """
        verbs = ("GET", "PUT", "HEAD", "PATCH", "DELETE", "POST")
        urls = (
            "http://supports-http.com",
            "https://supports-https.com",
            "http://this/has/a/path/and/invalid/domain/name",
            "https://supports-https.com:8080",
            "http://supports-http.com:8080",
        )
        params = (None, {}, {b"page": [1]})
        headers = (None, {}, {b"x-random-header": [b"value", b"value2"]})
        data = (None, b"", b"some data", b'{"some": "json"}')

        stub = StubTreq(_StaticTestResource())

        combos = (
            (verb, {"url": url, "params": p, "headers": h, "data": d})
            for verb in verbs
            for url in urls
            for p in params
            for h in headers
            for d in data
        )
        for combo in combos:
            verb, kwargs = combo
            deferreds = (stub.request(verb, **kwargs), getattr(stub, verb.lower())(**kwargs))
            for d in deferreds:
                resp = self.successResultOf(d)
                self.assertEqual(418, resp.code)
                self.assertEqual([b"teapot!"], resp.headers.getRawHeaders(b"x-teapot"))
                self.assertEqual(b"" if verb == "HEAD" else b"I'm a teapot", self.successResultOf(stub.content(resp)))
开发者ID:twisted,项目名称:treq,代码行数:37,代码来源:test_testing.py


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