Skip to content
Myr

Added docstrings to tests in test_testserver.py

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Braulio Valdivielso Martínez · committed by Braulio Valdivielso Martínez · parent 0dff06a · Browse files · 1 file+9 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−0 removed

  • tests:+9 added−0 removed

1 file+9 added−0 removed

modified:tests/test_testserver.py+9 added
6 unmodified lines
7from testserver.server import Server89class TestTestServer:10 def test_basic(self):11 """messages are sent and received properly"""12 question = b"sucess?"13 answer = b"yeah, success"14 def handler(sock):15 text = sock.recv(1000)
8 unmodified lines
24 assert text == answer25 sock.close()2627 def test_server_closes(self):28 """the server closes when leaving the context manager"""29 with Server.basic_response_server() as (host, port):30 sock = socket.socket()31 sock.connect((host, port))32
3 unmodified lines
36 new_sock = socket.socket()37 new_sock.connect((host, port))3839 def test_text_response(self):40 """the text_response_server sends the given text"""41 server = Server.text_response_server(42 "HTTP/1.1 200 OK\r\n" + 43 "Content-Length: 6\r\n" +44 "\r\nroflol"
6 unmodified lines
51 assert r.text == u'roflol'52 assert r.headers['Content-Length'] == '6' 53 54 def test_basic_response(self):55 """the basic response server returns an empty http response"""56 with Server.basic_response_server() as (host, port):57 r = requests.get('http://{0}:{1}'.format(host, port))58 assert r.status_code == 20059 assert r.text == u''60 assert r.headers['Content-Length'] == '0'6162 def test_basic_waiting_server(self):63 """the server waits for the block_server event to be set before closing"""64 block_server = threading.Event()6566 with Server.basic_response_server(wait_to_close_event=block_server) as (host, port):67 sock = socket.socket()
3 unmodified lines
71 sock.sendall(b'still alive')72 block_server.set() # release server block7374 def test_multiple_requests(self):75 """multiple requests can be served"""76 requests_to_handle = 577 78 server = Server.basic_response_server(requests_to_handle=requests_to_handle)79
7 unmodified lines
87 with pytest.raises(requests.exceptions.ConnectionError):88 r = requests.get(server_url)8990 def test_request_recovery(self):91 """can check the requests content"""92 server = Server.basic_response_server(requests_to_handle=2)93 first_request = "put your hands up in the air"94 second_request = "put your hand down in the floor"95
12 unmodified lines
108 assert server.handler_results[0] == first_request109 assert server.handler_results[1] == second_request110111 def test_requests_after_timeout_are_not_received(self):112 """the basic response handler times out when receiving requests"""113 server = Server.basic_response_server(request_timeout=1)114115 with server as address:116 sock = socket.socket()
5 unmodified lines
122 assert server.handler_results[0] == ''123124125 def test_request_recovery_with_bigger_timeout(self):126 """a biggest timeout can be specified"""127 server = Server.basic_response_server(request_timeout=3)128 data = "bananadine"129130 with server as address:
7 unmodified lines