Skip to content
Myr

Added basic_response_server classmethod and tested it

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 2ad3f07 · Browse files · 2 files+20 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

2 files+20 added−0 removed

  • other:+20 added−0 removed

2 files+20 added−0 removed

modified:testserver/server.py+13 added
11 unmodified lines
12 self.port = port13 self.ready_event = threading.Event()14 self.stop_event = threading.Event()1516 @classmethod17 def basic_response_server(cls, host='localhost', port=0):18 def basic_response_handler(server_sock):19 sock, _ = server_sock.accept()20 sock.send(21 b'HTTP/1.1 200 OK\r\n'22 b'Content-Length: 0\r\n'23 b'\r\n'24 )2526 server = Server(basic_response_handler, host=host, port=port)27 return server2829 def run(self):30 try:31 sock = self._create_socket_and_bind()32 # in case self.port = 0
25 unmodified lines
modified:test_requests.py+7 added
1754 unmodified lines
1755 text = sock.recv(1000)1756 assert text == answer1757 sock.close()17581759 def test_basic_response(self):1760 with Server.basic_response_server() as (host, port):1761 r = requests.get('http://{}:{}'.format(host, port))1762 assert r.status_code == 2001763 assert r.text == ''1764 assert r.headers['Content-Length'] == '0'17651766if __name__ == '__main__':1767 unittest.main()