Skip to content
Myr

Updated tests relying on the old testserver and added basic test for chunked uploads

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 6551c29 · Browse files · 1 file+32 added−2 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+32 added−2 removed

  • other:+32 added−2 removed

1 file+32 added−2 removed

modified:test_requests.py+32 added-2 removed
29 unmodified lines
30from requests.models import urlencode31from requests.hooks import default_hooks32from testserver.server import Server33import socket34import threading35import time3637try:38 import StringIO39except ImportError:
1140 unmodified lines
1180 '''.strip()1181 encodings = requests.utils.get_encodings_from_content(content)1182 assert encodings == ['HTML5', 'HTML4', 'XML']11831184 def test_chunked_upload(self):1185 """ can safely send generators """1186 block_server = threading.Event()1187 server = Server.basic_response_server(wait_to_close_event=block_server)1188 data = (i for i in [b'a', b'b', b'c']) 11891190 with server as (host, port):1191 url = 'http://{}:{}/'.format(host, port)1192 r = requests.post(url, data=data, stream=True)1193 block_server.set() # release server block11941195 assert r.status_code == 2001196 assert r.request.headers['Transfer-Encoding'] == 'chunked'11971198 1199 1200120112021203class TestCaseInsensitiveDict(unittest.TestCase):12041205 def test_mapping_init(self):1206 cid = CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'})
554 unmodified lines
1761class TestTestServer(unittest.TestCase):1762 def test_basic(self):1763 question = b"sucess?"1764 answer = b"yeah, success"1745 def handler(server_sock):1746 sock, _ = server_sock.accept()1765 def handler(sock):1766 text = sock.recv(1000)1767 assert text == question 1768 sock.send(answer)1769
21 unmodified lines
1791 assert r.status_code == 2001792 assert r.text == ''1793 assert r.headers['Content-Length'] == '0'17941795 def test_basic_waiting_server(self):1796 block_server = threading.Event()17971798 with Server.basic_response_server(wait_to_close_event=block_server) as (host, port):1799 sock = socket.socket()1800 sock.connect((host, port))1801 sock.send(b'send something')1802 time.sleep(2.5)1803 sock.send(b'still alive')1804 block_server.set() # release server block18051806if __name__ == '__main__':1807 unittest.main()