diff --git a/src/calibre/srv/tests/auth.py b/src/calibre/srv/tests/auth.py index 231a600b26..adfa0aa88a 100644 --- a/src/calibre/srv/tests/auth.py +++ b/src/calibre/srv/tests/auth.py @@ -100,7 +100,7 @@ class TestAuth(BaseTest): conn.request('GET', '/closed') r = conn.getresponse() self.ae(r.status, http_client.UNAUTHORIZED) - self.ae(r.getheader('WWW-Authenticate'), b'Basic realm="%s"' % bytes(REALM)) + self.ae(r.getheader('WWW-Authenticate'), 'Basic realm="%s"' % REALM) self.assertFalse(r.read()) conn.request('GET', '/closed', headers={'Authorization': b'Basic ' + as_base64_bytes(b'testuser:testpw')}) r = conn.getresponse() @@ -180,11 +180,13 @@ class TestAuth(BaseTest): return {normalize_header_name(k):v for k, v in r.getheaders()} conn = server.connect() test(conn, '/open', body=b'open') - auth = parse_http_dict(test(conn, '/closed', status=http_client.UNAUTHORIZED)['WWW-Authenticate'].partition(b' ')[2]) + auth = parse_http_dict(test(conn, '/closed', status=http_client.UNAUTHORIZED)['WWW-Authenticate'].partition(' ')[2]) nonce = auth['nonce'] - auth = parse_http_dict(test(conn, '/closed', status=http_client.UNAUTHORIZED)['WWW-Authenticate'].partition(b' ')[2]) + auth = parse_http_dict(test(conn, '/closed', status=http_client.UNAUTHORIZED)['WWW-Authenticate'].partition(' ')[2]) self.assertNotEqual(nonce, auth['nonce'], 'nonce was re-used') - self.ae(auth[b'realm'], bytes(REALM)), self.ae(auth[b'algorithm'], b'MD5'), self.ae(auth[b'qop'], b'auth') + self.ae(auth['realm'], REALM) + self.ae(auth['algorithm'], 'MD5') + self.ae(auth['qop'], 'auth') self.assertNotIn('stale', auth) args = auth.copy() args['un'], args['pw'], args['uri'] = 'testuser', 'testpw', '/closed' @@ -202,7 +204,7 @@ class TestAuth(BaseTest): # Check stale nonces orig, r.auth_controller.max_age_seconds = r.auth_controller.max_age_seconds, -1 auth = parse_http_dict(test(conn, '/closed', headers={ - 'Authorization':digest(**args)},status=http_client.UNAUTHORIZED)['WWW-Authenticate'].partition(b' ')[2]) + 'Authorization':digest(**args)},status=http_client.UNAUTHORIZED)['WWW-Authenticate'].partition(' ')[2]) self.assertIn('stale', auth) r.auth_controller.max_age_seconds = orig ok_test(conn, digest(**args)) diff --git a/src/calibre/srv/tests/http.py b/src/calibre/srv/tests/http.py index a434990ef4..87836d22d6 100644 --- a/src/calibre/srv/tests/http.py +++ b/src/calibre/srv/tests/http.py @@ -34,20 +34,20 @@ class TestHTTP(BaseTest): self.assertSetEqual(set(p.hdict.items()), {(k.replace('_', '-').title(), v) for k, v in iteritems(kwargs)}, name + ' failed') test('Continuation line parsing', - 'a: one', - 'b: two', - ' 2', - '\t3', - 'c:three', - '\r\n', a='one', b='two 2 3', c='three') + b'a: one', + b'b: two', + b' 2', + b'\t3', + b'c:three', + b'\r\n', a='one', b='two 2 3', c='three') test('Non-ascii headers parsing', - 'a:mūs\r'.encode('utf-8'), '\r\n', a='mūs') + 'a:mūs\r'.encode('utf-8'), b'\r\n', a='mūs') test('Comma-separated parsing', - 'Accept-Encoding: one', - 'accept-Encoding: two', - '\r\n', accept_encoding='one, two') + b'Accept-Encoding: one', + b'accept-Encoding: two', + b'\r\n', accept_encoding='one, two') def parse(*lines): lines = list(lines) @@ -98,7 +98,7 @@ class TestHTTP(BaseTest): r = conn.getresponse() self.ae(r.status, http_client.OK) q += getattr(get_translator(q)[-1], 'gettext' if ispy3 else 'ugettext')('Unknown') - self.ae(r.read(), q) + self.ae(r.read(), q.encode('utf-8')) test('en', 'en') test('eng', 'en') @@ -317,7 +317,7 @@ class TestHTTP(BaseTest): return conn.generate_static_output('test', lambda : ''.join(conn.path)) with NamedTemporaryFile(suffix='test.epub') as f, open(P('localization/locales.zip'), 'rb') as lf, \ TestServer(handler, timeout=1, compress_min_size=0) as server: - fdata = string.ascii_letters * 100 + fdata = (string.ascii_letters * 100).encode('ascii') f.write(fdata), f.seek(0) # Test ETag @@ -326,7 +326,7 @@ class TestHTTP(BaseTest): r = conn.getresponse() self.ae(r.status, http_client.OK), self.ae(r.read(), b'an_etagged_path') etag = r.getheader('ETag') - self.ae(etag, '"%s"' % hashlib.sha1('an_etagged_path').hexdigest()) + self.ae(etag, '"%s"' % hashlib.sha1(b'an_etagged_path').hexdigest()) conn.request('GET', '/an_etagged_path', headers={'If-None-Match':etag}) r = conn.getresponse() self.ae(r.status, http_client.NOT_MODIFIED) @@ -353,7 +353,7 @@ class TestHTTP(BaseTest): r = conn.getresponse() self.ae(r.status, http_client.OK), self.ae(r.read(), b'data') etag = r.getheader('ETag') - self.ae(etag, b'"xxx"') + self.ae(etag, '"xxx"') self.ae(r.getheader('Content-Length'), '4') conn.request('GET', '/an_etagged_path', headers={'If-None-Match':etag}) r = conn.getresponse()