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
Provenance
- Commit
03743b1- Tree
ddc9990- Author
Braulio Valdivielso Martínez <brlvldvlsmrtnz@gmail.com>- Committer
Braulio Valdivielso Martínez <brlvldvlsmrtnz@gmail.com>- Parent
0dff06a
1 file changed+9 added−0 removed
modified:tests/test_testserver.py+9 added
6 unmodified lines7 from testserver.server import Server8 9 class 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 lines24 assert text == answer25 sock.close()26 27 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 lines36 new_sock = socket.socket()37 new_sock.connect((host, port))38 39 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 lines51 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'61 62 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()65 66 with Server.basic_response_server(wait_to_close_event=block_server) as (host, port):67 sock = socket.socket()3 unmodified lines71 sock.sendall(b'still alive')72 block_server.set() # release server block73 74 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 lines87 with pytest.raises(requests.exceptions.ConnectionError):88 r = requests.get(server_url)89 90 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 lines108 assert server.handler_results[0] == first_request109 assert server.handler_results[1] == second_request110 111 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)114 115 with server as address:116 sock = socket.socket()5 unmodified lines122 assert server.handler_results[0] == ''123 124 125 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"129 130 with server as address:7 unmodified lines