comparison test/test_liveserver.py @ 6569:3ae0c0fb2d08

Fix test_new_file_via_rest This test was failing under python2. The cgi.py module was calling readline(1<<16). I was using the wasgiref/validate.py validator to make sure the wsgi protocol was correct. The validator replaces the normal readline with it's own wrapper. The wrapper doesn't support the max bytes to read value. The same module/wrapper in python 3 fixed this bug. So fixed this by disabling the validator under python2. Keeping it on python3 so we get its benefit.
author John Rouillard <rouilj@ieee.org>
date Tue, 21 Dec 2021 02:28:25 -0500
parents 59eebe55ca1d
children 198875530c04
comparison
equal deleted inserted replaced
6568:59eebe55ca1d 6569:3ae0c0fb2d08
29 skip_zstd = lambda func, *args, **kwargs: func 29 skip_zstd = lambda func, *args, **kwargs: func
30 except ImportError: 30 except ImportError:
31 from .pytest_patcher import mark_class 31 from .pytest_patcher import mark_class
32 skip_zstd = mark_class(pytest.mark.skip( 32 skip_zstd = mark_class(pytest.mark.skip(
33 reason='Skipping zstd tests: zstd library not available')) 33 reason='Skipping zstd tests: zstd library not available'))
34
35 import sys
36
37 _py3 = sys.version_info[0] > 2
34 38
35 @skip_requests 39 @skip_requests
36 class SimpleTest(LiveServerTestCase): 40 class SimpleTest(LiveServerTestCase):
37 # have chicken and egg issue here. Need to encode the base_url 41 # have chicken and egg issue here. Need to encode the base_url
38 # in the config file but we don't know it until after 42 # in the config file but we don't know it until after
84 except OSError as error: 88 except OSError as error:
85 if error.errno not in (errno.ENOENT, errno.ESRCH): raise 89 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
86 90
87 def create_app(self): 91 def create_app(self):
88 '''The wsgi app to start''' 92 '''The wsgi app to start'''
89 return validator(RequestDispatcher(self.dirname)) 93 if _py3:
94 return validator(RequestDispatcher(self.dirname))
95 else:
96 # wsgiref/validator.py InputWrapper::readline is broke and
97 # doesn't support the max bytes to read argument.
98 return RequestDispatcher(self.dirname)
99
90 100
91 def test_start_page(self): 101 def test_start_page(self):
92 """ simple test that verifies that the server can serve a start page. 102 """ simple test that verifies that the server can serve a start page.
93 """ 103 """
94 f = requests.get(self.url_base()) 104 f = requests.get(self.url_base())
917 # download file and verify content 927 # download file and verify content
918 f = session.get(self.url_base()+'/file1/text1.txt') 928 f = session.get(self.url_base()+'/file1/text1.txt')
919 self.assertEqual(f.text, file_content) 929 self.assertEqual(f.text, file_content)
920 print(f.text) 930 print(f.text)
921 931
922 @pytest.mark.xfail(reason="Work in progress")
923 def test_new_file_via_rest(self): 932 def test_new_file_via_rest(self):
924 933
925 session = requests.Session() 934 session = requests.Session()
926 session.auth = ('admin', 'sekrit') 935 session.auth = ('admin', 'sekrit')
927 936

Roundup Issue Tracker: http://roundup-tracker.org/