1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
import threading
import time
import unittest
import web
try: # PY 3
from urllib.parse import unquote_to_bytes as unquote
except ImportError: # PY 2
from urllib import unquote
class WSGITest(unittest.TestCase):
def test_layers_unicode(self):
urls = ("/", "uni")
class uni:
def GET(self):
return u"\u0C05\u0C06"
app = web.application(urls, locals())
thread = threading.Thread(target=app.run)
thread.start()
time.sleep(0.5)
b = web.browser.AppBrowser(app)
r = b.open("/").read()
s = r.decode("utf8")
self.assertEqual(s, u"\u0C05\u0C06")
app.stop()
thread.join()
def test_layers_bytes(self):
urls = ("/", "bytes")
class bytes:
def GET(self):
return b"abcdef"
app = web.application(urls, locals())
thread = threading.Thread(target=app.run)
thread.start()
time.sleep(0.5)
b = web.browser.AppBrowser(app)
r = b.open("/")
self.assertEqual(r.read(), b"abcdef")
app.stop()
thread.join()
def test_unicode_url(self):
urls = ("/([^/]+)", "url_passthrough")
class url_passthrough:
def GET(self, arg):
return arg
app = web.application(urls, locals())
thread = threading.Thread(target=app.run)
thread.start()
time.sleep(0.5)
b = web.browser.AppBrowser(app)
r = b.open("/%E2%84%A6")
s = unquote(r.read())
self.assertEqual(s, b"\xE2\x84\xA6")
app.stop()
thread.join()
|