@@ -31,59 +31,69 @@ def _chunk(response, split, extra=b""):
3131 return chunked
3232
3333
34+ def do_test_get_text (extra = b"" ):
35+ pool = mocket .MocketPool ()
36+ pool .getaddrinfo .return_value = ((None , None , None , None , (ip , 80 )),)
37+ c = _chunk (text , 33 , extra )
38+ print (c )
39+ sock = mocket .Mocket (headers + c )
40+ pool .socket .return_value = sock
41+
42+ s = adafruit_requests .Session (pool )
43+ r = s .get ("http://" + host + path )
44+
45+ sock .connect .assert_called_once_with ((ip , 80 ))
46+
47+ sock .send .assert_has_calls (
48+ [
49+ mock .call (b"GET" ),
50+ mock .call (b" /" ),
51+ mock .call (b"testwifi/index.html" ),
52+ mock .call (b" HTTP/1.1\r \n " ),
53+ ]
54+ )
55+ sock .send .assert_has_calls (
56+ [mock .call (b"Host: " ), mock .call (b"wifitest.adafruit.com" ),]
57+ )
58+ assert r .text == str (text , "utf-8" )
59+
3460def test_get_text ():
35- for extra in (b"" , b";blahblah; blah" ):
36- pool = mocket .MocketPool ()
37- pool .getaddrinfo .return_value = ((None , None , None , None , (ip , 80 )),)
38- c = _chunk (text , 33 , extra )
39- print (c )
40- sock = mocket .Mocket (headers + c )
41- pool .socket .return_value = sock
42-
43- s = adafruit_requests .Session (pool )
44- r = s .get ("http://" + host + path )
45-
46- sock .connect .assert_called_once_with ((ip , 80 ))
47-
48- sock .send .assert_has_calls (
49- [
50- mock .call (b"GET" ),
51- mock .call (b" /" ),
52- mock .call (b"testwifi/index.html" ),
53- mock .call (b" HTTP/1.1\r \n " ),
54- ]
55- )
56- sock .send .assert_has_calls (
57- [mock .call (b"Host: " ), mock .call (b"wifitest.adafruit.com" ),]
58- )
59- assert r .text == str (text , "utf-8" )
61+ do_test_get_text ()
6062
63+ def test_get_text_extra ():
64+ do_test_get_text (b';blahblah; blah' )
6165
62- def test_close_flush ():
66+
67+ def do_test_close_flush (extra = b'' ):
6368 """Test that a chunked response can be closed even when the request contents were not accessed."""
64- for extra in (b"" , b";blahblah; blah" ):
65- pool = mocket .MocketPool ()
66- pool .getaddrinfo .return_value = ((None , None , None , None , (ip , 80 )),)
67- c = _chunk (text , 33 , extra )
68- print (c )
69- sock = mocket .Mocket (headers + c )
70- pool .socket .return_value = sock
71-
72- s = adafruit_requests .Session (pool )
73- r = s .get ("http://" + host + path )
74-
75- sock .connect .assert_called_once_with ((ip , 80 ))
76-
77- sock .send .assert_has_calls (
78- [
79- mock .call (b"GET" ),
80- mock .call (b" /" ),
81- mock .call (b"testwifi/index.html" ),
82- mock .call (b" HTTP/1.1\r \n " ),
83- ]
84- )
85- sock .send .assert_has_calls (
86- [mock .call (b"Host: " ), mock .call (b"wifitest.adafruit.com" ),]
87- )
69+ pool = mocket .MocketPool ()
70+ pool .getaddrinfo .return_value = ((None , None , None , None , (ip , 80 )),)
71+ c = _chunk (text , 33 , extra )
72+ print (c )
73+ sock = mocket .Mocket (headers + c )
74+ pool .socket .return_value = sock
75+
76+ s = adafruit_requests .Session (pool )
77+ r = s .get ("http://" + host + path )
78+
79+ sock .connect .assert_called_once_with ((ip , 80 ))
80+
81+ sock .send .assert_has_calls (
82+ [
83+ mock .call (b"GET" ),
84+ mock .call (b" /" ),
85+ mock .call (b"testwifi/index.html" ),
86+ mock .call (b" HTTP/1.1\r \n " ),
87+ ]
88+ )
89+ sock .send .assert_has_calls (
90+ [mock .call (b"Host: " ), mock .call (b"wifitest.adafruit.com" ),]
91+ )
92+
93+ r .close ()
94+
95+ def test_close_flush ():
96+ do_test_close_flush ()
8897
89- r .close ()
98+ def test_close_flush_extra ():
99+ do_test_close_flush (b';blahblah; blah' )
0 commit comments