• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python server.Server类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.testserver.server.Server的典型用法代码示例。如果您正苦于以下问题:Python Server类的具体用法?Python Server怎么用?Python Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_basic_response

 def test_basic_response(self):
     """the basic response server returns an empty http response"""
     with Server.basic_response_server() as (host, port):
         r = requests.get('http://{}:{}'.format(host, port))
         assert r.status_code == 200
         assert r.text == u''
         assert r.headers['Content-Length'] == '0'
开发者ID:antoniojosue,项目名称:requests,代码行数:7,代码来源:test_testserver.py


示例2: test_server_finishes_when_no_connections

    def test_server_finishes_when_no_connections(self):
        """the server thread exits even if there are no connections"""
        server = Server.basic_response_server()
        with server:
            pass

        assert len(server.handler_results) == 0
开发者ID:antoniojosue,项目名称:requests,代码行数:7,代码来源:test_testserver.py


示例3: test_basic_response

 def test_basic_response(self):
     """the basic response server returns an empty http response"""
     with Server.basic_response_server() as (host, port):
         r = requests.get("http://{0}:{1}".format(host, port))
         assert r.status_code == 200
         assert r.text == u""
         assert r.headers["Content-Length"] == "0"
开发者ID:21hub,项目名称:requests,代码行数:7,代码来源:test_testserver.py


示例4: test_server_finishes_on_error

    def test_server_finishes_on_error(self):
        """the server thread exits even if an exception exits the context manager"""
        server = Server.basic_response_server()
        with pytest.raises(Exception):
            with server:
                raise Exception()

        assert len(server.handler_results) == 0
开发者ID:antoniojosue,项目名称:requests,代码行数:8,代码来源:test_testserver.py


示例5: test_text_response

    def test_text_response(self):
        """the text_response_server sends the given text"""
        server = Server.text_response_server("HTTP/1.1 200 OK\r\n" + "Content-Length: 6\r\n" + "\r\nroflol")

        with server as (host, port):
            r = requests.get("http://{0}:{1}".format(host, port))

            assert r.status_code == 200
            assert r.text == u"roflol"
            assert r.headers["Content-Length"] == "6"
开发者ID:21hub,项目名称:requests,代码行数:10,代码来源:test_testserver.py


示例6: test_basic_waiting_server

    def test_basic_waiting_server(self):
        """the server waits for the block_server event to be set before closing"""
        block_server = threading.Event()

        with Server.basic_response_server(wait_to_close_event=block_server) as (host, port):
            sock = socket.socket()
            sock.connect((host, port))
            sock.sendall(b'send something')
            time.sleep(2.5)
            sock.sendall(b'still alive')
            block_server.set()  # release server block
开发者ID:antoniojosue,项目名称:requests,代码行数:11,代码来源:test_testserver.py


示例7: test_server_closes

    def test_server_closes(self):
        """the server closes when leaving the context manager"""
        with Server.basic_response_server() as (host, port):
            sock = socket.socket()
            sock.connect((host, port))

            sock.close()

        with pytest.raises(socket.error):
            new_sock = socket.socket()
            new_sock.connect((host, port))
开发者ID:antoniojosue,项目名称:requests,代码行数:11,代码来源:test_testserver.py


示例8: test_requests_after_timeout_are_not_received

    def test_requests_after_timeout_are_not_received(self):
        """the basic response handler times out when receiving requests"""
        server = Server.basic_response_server(request_timeout=1)

        with server as address:
            sock = socket.socket()
            sock.connect(address)
            time.sleep(1.5)
            sock.sendall(b'hehehe, not received')
            sock.close()

        assert server.handler_results[0] == b''
开发者ID:antoniojosue,项目名称:requests,代码行数:12,代码来源:test_testserver.py


示例9: test_request_recovery_with_bigger_timeout

    def test_request_recovery_with_bigger_timeout(self):
        """a biggest timeout can be specified"""
        server = Server.basic_response_server(request_timeout=3)
        data = b'bananadine'

        with server as address:
            sock = socket.socket()
            sock.connect(address)
            time.sleep(1.5)
            sock.sendall(data)
            sock.close()

        assert server.handler_results[0] == data
开发者ID:antoniojosue,项目名称:requests,代码行数:13,代码来源:test_testserver.py


示例10: test_chunked_upload

def test_chunked_upload():
    """can safely send generators"""
    close_server = threading.Event()
    server = Server.basic_response_server(wait_to_close_event=close_server)
    data = iter([b'a', b'b', b'c'])

    with server as (host, port):
        url = 'http://{0}:{1}/'.format(host, port)
        r = requests.post(url, data=data, stream=True)
        close_server.set()  # release server block

    assert r.status_code == 200
    assert r.request.headers['Transfer-Encoding'] == 'chunked'
开发者ID:Khan,项目名称:requests,代码行数:13,代码来源:test_lowlevel.py


示例11: test_multiple_requests

    def test_multiple_requests(self):
        """multiple requests can be served"""
        requests_to_handle = 5

        server = Server.basic_response_server(requests_to_handle=requests_to_handle)

        with server as (host, port):
            server_url = 'http://{}:{}'.format(host, port)
            for _ in range(requests_to_handle):
                r = requests.get(server_url)
                assert r.status_code == 200

            # the (n+1)th request fails
            with pytest.raises(requests.exceptions.ConnectionError):
                r = requests.get(server_url)
开发者ID:antoniojosue,项目名称:requests,代码行数:15,代码来源:test_testserver.py


示例12: test_request_recovery

    def test_request_recovery(self):
        """can check the requests content"""
        server = Server.basic_response_server(requests_to_handle=2)
        first_request = b'put your hands up in the air'
        second_request = b'put your hand down in the floor'

        with server as address:
            sock1 = socket.socket()
            sock2 = socket.socket()

            sock1.connect(address)
            sock1.sendall(first_request)
            sock1.close()

            sock2.connect(address)
            sock2.sendall(second_request)
            sock2.close()

        assert server.handler_results[0] == first_request
        assert server.handler_results[1] == second_request
开发者ID:GriMel,项目名称:requests,代码行数:20,代码来源:test_testserver.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testutils.TestUtils类代码示例发布时间:2022-05-27
下一篇:
Python testingutils.autospec_method函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap