Beispiel #1
0
 def test_options_star(self):
     def app(environ, start_response):
         assert False, 'application was called'
     
     def start_response(status, headers, exc_info=None):
         assert exc_info is None
         assert status.startswith('200 '), repr(status)
     
     router([
         (re.compile(r'/'), ['GET'], app)
     ])(environ('OPTIONS', '*'), start_response)
Beispiel #2
0
 def test_404(self):
     def start_response(status, headers, exc_info=None):
         assert exc_info is None
         assert status.startswith('404 '), repr(status)
     
     def app(environ, start_response):
         assert False, 'application was called'
     
     router([
         (re.compile(r'/something'), ['GET', 'HEAD'], app)
     ])(environ(), start_response)
Beispiel #3
0
 def test_get(self):
     called = []
     
     def app(environ, start_response):
         called.append(True)
     
     def start_response(status, headers, exc_info=None):
         assert False, 'start_response was called'
     
     router([
         (re.compile(r'/'), ['GET'], app)
     ])(environ(), start_response)
     
     assert called
Beispiel #4
0
 def test_script_name(self):
     called = []
     
     def app(environ, start_response):
         called.append(True)
         assert environ['SCRIPT_NAME'] == '/something', repr(environ['SCRIPT_NAME'])
         assert environ['PATH_INFO'] == '/else', repr(environ['PATH_INFO'])
     
     def start_response(status, headers, exc_info=None):
         assert False, 'start_response was called'
     
     router([
         (re.compile(r'/something'), ['GET'], app)
     ])(environ(uri='/something/else'), start_response)
     
     assert called
Beispiel #5
0
 def test_options_with_methods(methods):
     def start_response(status, headers, exc_info=None):
         assert exc_info is None
         assert status.startswith('200 '), repr(status)
         for name, value in headers:
             if name.lower() == 'allow':
                 if methods:
                     assert set(m.strip() for m in value.split(',')) == set(methods), repr(value)
                 else:
                     assert value == '', repr(value)
                 break
         else:
             assert False, 'allow header not present'
     
     def app(environ, start_response):
         assert False, 'application was called'
     
     router([
         (re.compile(r'/'), methods, app)
     ])(environ('OPTIONS'), start_response)
Beispiel #6
0
 def test_method_not_allowed(self):
     methods = ['GET', 'HEAD']
     
     def start_response(status, headers, exc_info=None):
         assert exc_info is None
         assert status.startswith('405 '), repr(status)
         for name, value in headers:
             if name.lower() == 'allow':
                 if methods:
                     assert set(m.strip() for m in value.split(',')) == set(methods), repr(value)
                 else:
                     assert value == '', repr(value)
                 break
         else:
             assert False, 'allow header not present'
     
     def app(environ, start_response):
         assert False, 'application was called'
     
     router([
         (re.compile(r'/'), methods, app)
     ])(environ('POST'), start_response)
Beispiel #7
0
 def test_empty(self):
     def start_response(status, headers, exc_info=None):
         assert exc_info is None
         assert status.startswith('404 '), repr(status)
     
     router()(environ(), start_response)