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


Python StubTreq.get方法代码示例

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


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

示例1: test_handles_invalid_schemes

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
 def test_handles_invalid_schemes(self):
     """
     Invalid URLs errback with a :obj:`SchemeNotSupported` failure, and does
     so even after a successful request.
     """
     stub = StubTreq(_StaticTestResource())
     self.failureResultOf(stub.get(""), SchemeNotSupported)
     self.successResultOf(stub.get("http://url.com"))
     self.failureResultOf(stub.get(""), SchemeNotSupported)
开发者ID:twisted,项目名称:treq,代码行数:11,代码来源:test_testing.py

示例2: test_consume_context_manager_fails_on_remaining_requests

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
    def test_consume_context_manager_fails_on_remaining_requests(self):
        """
        If the `consume` context manager is used, if there are any remaining
        expecting requests, the test case will be failed.
        """
        sequence = RequestSequence(
            [((ANY, ANY, ANY, ANY, ANY), (418, {}, 'body'))] * 2,
            async_failure_reporter=self.async_failures.append)
        stub = StubTreq(StringStubbingResource(sequence))

        consume_failures = []
        with sequence.consume(sync_failure_reporter=consume_failures.append):
            self.successResultOf(stub.get('https://anything', data='what',
                                          headers={'1': '1'}))

        self.assertEqual(1, len(consume_failures))
        self.assertIn(
            "Not all expected requests were made.  Still expecting:",
            consume_failures[0])
        self.assertIn(
            "{0}(url={0}, params={0}, headers={0}, data={0})".format(
                repr(ANY)),
            consume_failures[0])

        # no asynchronous failures (mismatches, etc.)
        self.assertEqual([], self.async_failures)
开发者ID:cyli,项目名称:treq,代码行数:28,代码来源:test_testing.py

示例3: test_content_type

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
 def test_content_type(self):
     client = StubTreq(StaticResource(content=b'hello', content_type='text/plain'))
     response = self.successResultOf(client.get('http://an.example/'))
     self.assertEqual(200, response.code)
     self.assertEqual([b'text/plain'], response.headers.getRawHeaders(b'Content-Type'))
     body = self.successResultOf(response.content())
     self.assertEqual(b'hello', body)
开发者ID:twm,项目名称:yarrharr,代码行数:9,代码来源:test_fetch.py

示例4: test_content

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
 def test_content(self):
     client = StubTreq(StaticResource(content=b'abcd'))
     response = self.successResultOf(client.get('http://an.example/'))
     self.assertEqual(200, response.code)
     self.assertEqual([b'application/xml'], response.headers.getRawHeaders(b'Content-Type'))
     body = self.successResultOf(response.content())
     self.assertEqual(b'abcd', body)
开发者ID:twm,项目名称:yarrharr,代码行数:9,代码来源:test_fetch.py

示例5: test_match

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
 def test_match(self):
     client = StubTreq(StaticEtagResource(b'abcd', b'"abcd"'))
     response = self.successResultOf(client.get('http://an.example/', headers={
         'if-none-match': ['"abcd"'],
     }))
     self.assertEqual(304, response.code)
     self.assertEqual(['application/xml'], response.headers.getRawHeaders('Content-Type'))
     self.assertEqual(['"abcd"'], response.headers.getRawHeaders('Etag'))
     body = self.successResultOf(response.content())
     self.assertEqual(b'', body)
开发者ID:twm,项目名称:yarrharr,代码行数:12,代码来源:test_fetch.py

示例6: test_no_match

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
 def test_no_match(self):
     client = StubTreq(StaticLastModifiedResource(
         content=b'abcd',
         last_modified=u'Mon, 6 Feb 2017 00:00:00 GMT',
     ))
     response = self.successResultOf(client.get('http://an.example/'))
     self.assertEqual(200, response.code)
     self.assertEqual([u'Mon, 6 Feb 2017 00:00:00 GMT'],
                      response.headers.getRawHeaders(u'Last-Modified'))
     body = self.successResultOf(response.content())
     self.assertEqual(b'abcd', body)
开发者ID:twm,项目名称:yarrharr,代码行数:13,代码来源:test_fetch.py

示例7: test_start_responding

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
    def test_start_responding(self, token):
        """
        Calling ``start_responding`` makes an appropriate resource available.
        """
        challenge = challenges.HTTP01(token=token)
        response = challenge.response(RSA_KEY_512)

        responder = HTTP01Responder()

        challenge_resource = Resource()
        challenge_resource.putChild(b'acme-challenge', responder.resource)
        root = Resource()
        root.putChild(b'.well-known', challenge_resource)
        client = StubTreq(root)

        encoded_token = challenge.encode('token')
        challenge_url = URL(host=u'example.com', path=[
            u'.well-known', u'acme-challenge', encoded_token]).asText()

        self.assertThat(client.get(challenge_url),
                        succeeded(MatchesStructure(code=Equals(404))))

        responder.start_responding(u'example.com', challenge, response)
        self.assertThat(client.get(challenge_url), succeeded(MatchesAll(
            MatchesStructure(
                code=Equals(200),
                headers=AfterPreprocessing(
                    methodcaller('getRawHeaders', b'content-type'),
                    Equals([b'text/plain']))),
            AfterPreprocessing(methodcaller('content'), succeeded(
                Equals(response.key_authorization.encode('utf-8'))))
        )))

        # Starting twice before stopping doesn't break things
        responder.start_responding(u'example.com', challenge, response)
        self.assertThat(client.get(challenge_url),
                        succeeded(MatchesStructure(code=Equals(200))))

        responder.stop_responding(u'example.com', challenge, response)
        self.assertThat(client.get(challenge_url),
                        succeeded(MatchesStructure(code=Equals(404))))
开发者ID:mithrandi,项目名称:txacme,代码行数:43,代码来源:test_challenges.py

示例8: test_async_failures_logged

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
    def test_async_failures_logged(self):
        """
        When no `async_failure_reporter` is passed async failures are logged by
        default.
        """
        sequence = RequestSequence([])
        stub = StubTreq(StringStubbingResource(sequence))

        with sequence.consume(self.fail):
            self.successResultOf(stub.get('https://example.com'))

        [failure] = self.flushLoggedErrors()
        self.assertIsInstance(failure.value, AssertionError)
开发者ID:twisted,项目名称:treq,代码行数:15,代码来源:test_testing.py

示例9: test_unexpected_number_of_request_causes_failure

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
    def test_unexpected_number_of_request_causes_failure(self):
        """
        If there are no more expected requests, making a request causes a
        failure.
        """
        sequence = RequestSequence([], async_failure_reporter=self.async_failures.append)
        stub = StubTreq(StringStubbingResource(sequence))
        d = stub.get("https://anything", data=b"what", headers={b"1": b"1"})
        resp = self.successResultOf(d)
        self.assertEqual(500, resp.code)
        self.assertEqual(1, len(self.async_failures))
        self.assertIn("No more requests expected, but request", self.async_failures[0])

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

示例10: test_works_with_mock_any

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [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

示例11: TestMarathonAcmeServer

# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import get [as 别名]
class TestMarathonAcmeServer(object):
    def setup_method(self):
        self.responder_resource = Resource()
        self.server = MarathonAcmeServer(self.responder_resource)
        self.client = StubTreq(self.server.app.resource())

    def test_responder_resource_empty(self):
        """
        When a GET request is made to the ACME challenge path, but the
        responder resource is empty, a 404 response code should be returned.
        """
        response = self.client.get(
            'http://localhost/.well-known/acme-challenge/foo')
        assert_that(response, succeeded(MatchesStructure(code=Equals(404))))

    def test_responder_resource_child(self):
        """
        When a GET request is made to the ACME challenge path, and the
        responder resource has a child resource at the correct path, the value
        of the resource should be returned.
        """
        self.responder_resource.putChild(b'foo', Data(b'bar', 'text/plain'))

        response = self.client.get(
            'http://localhost/.well-known/acme-challenge/foo')
        assert_that(response, succeeded(MatchesAll(
            MatchesStructure(
                code=Equals(200),
                headers=HasHeader('Content-Type', ['text/plain'])),
            After(methodcaller('content'), succeeded(Equals(b'bar')))
        )))

        # Sanity check that a request to a different subpath does not succeed
        response = self.client.get(
            'http://localhost/.well-known/acme-challenge/baz')
        assert_that(response, succeeded(MatchesStructure(code=Equals(404))))

    def test_acme_challenge_ping(self):
        """
        When a GET request is made to the ACME challenge path ping endpoint,
        a pong message should be returned.
        """
        response = self.client.get(
            'http://localhost/.well-known/acme-challenge/ping')
        assert_that(response, succeeded(MatchesAll(
            IsJsonResponseWithCode(200),
            After(json_content, succeeded(Equals({'message': 'pong'})))
        )))

    def test_health_healthy(self):
        """
        When a GET request is made to the health endpoint, and the health
        handler reports that the service is healthy, a 200 status code should
        be returned together with the JSON message from the handler.
        """
        self.server.set_health_handler(
            lambda: Health(True, {'message': "I'm 200/OK!"}))

        response = self.client.get('http://localhost/health')
        assert_that(response, succeeded(MatchesAll(
            IsJsonResponseWithCode(200),
            After(json_content, succeeded(Equals({'message': "I'm 200/OK!"})))
        )))

    def test_health_unhealthy(self):
        """
        When a GET request is made to the health endpoint, and the health
        handler reports that the service is unhealthy, a 503 status code should
        be returned together with the JSON message from the handler.
        """
        self.server.set_health_handler(
            lambda: Health(False, {'error': "I'm sad :("}))

        response = self.client.get('http://localhost/health')
        assert_that(response, succeeded(MatchesAll(
            IsJsonResponseWithCode(503),
            After(json_content, succeeded(Equals({'error': "I'm sad :("})))
        )))

    def test_health_handler_unset(self):
        """
        When a GET request is made to the health endpoint, and the health
        handler hasn't been set, a 501 status code should be returned together
        with a JSON message that explains that the handler is not set.
        """
        response = self.client.get('http://localhost/health')
        assert_that(response, succeeded(MatchesAll(
            IsJsonResponseWithCode(501),
            After(json_content, succeeded(Equals({
                'error': 'Cannot determine service health: no handler set'
            })))
        )))

    def test_health_handler_unicode(self):
        """
        When a GET request is made to the health endpoint, and the health
        handler reports that the service is unhealthy, a 503 status code should
        be returned together with the JSON message from the handler.
        """
        self.server.set_health_handler(
#.........这里部分代码省略.........
开发者ID:praekeltfoundation,项目名称:marathon-acme,代码行数:103,代码来源:test_server.py


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