Example #1
0
def test_with_text_star_accept():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test.iscool'
    environ['HTTP_ACCEPT'] = 'text/*'
    m = MIMETypes(environ)
    eq_(m.mimetype('text/html'), 'text/html')
Example #2
0
 def test_dispatch(self):
     controller = TestController(response.ok, body='test body')
     self.controllers.mount('^/foo/bar/$', [methods.GET], controller)
     environ = util.test_environ(path_info='/foo/bar/')
     self.controllers(environ, Mock())
     self.assertEqual(environ['PATH_INFO'], '')
     self.assertEqual(environ['SCRIPT_NAME'], '/foo/bar/')
Example #3
0
def test_root_path():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/'
    environ['HTTP_ACCEPT'] = 'text/html, application/xml'
    m = MIMETypes(environ)
    eq_(m.mimetype('text/html'), 'text/html')
Example #4
0
def test_with_star_star_accept():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test.iscool'
    environ['HTTP_ACCEPT'] = '*/*'
    m = MIMETypes(environ)
    eq_(m.mimetype('application/xml'), 'application/xml')
Example #5
0
 def test_response_return(self):
     body = 'test body'
     controller = TestController(response.ok, body=body)
     self.controllers.mount('^/test/$', [methods.GET], controller)
     environ = util.test_environ(path_info='/test/')
     value = self.controllers(environ, Mock())
     self.assertIs(body, value)
Example #6
0
 def test_regex_args(self):
     controller = TestController(response.ok, body='test body')
     self.controllers.mount('^/([^/]+)/([^/]+)/$', [methods.GET], controller)
     environ = util.test_environ(path_info='/arg1/arg2/')
     value = self.controllers(environ, Mock())
     self.assertIn('arg1', controller.args)
     self.assertIn('arg2', controller.args)
Example #7
0
def test_with_star_star_accept():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test.iscool'
    environ['HTTP_ACCEPT'] = '*/*'
    m = MIMETypes(environ)
    eq_(m.mimetype('application/xml'), 'application/xml')
Example #8
0
def test_with_text_star_accept():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test.iscool'
    environ['HTTP_ACCEPT'] = 'text/*'
    m = MIMETypes(environ)
    eq_(m.mimetype('text/html'), 'text/html')
Example #9
0
def test_root_path():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/'
    environ['HTTP_ACCEPT'] = 'text/html, application/xml'
    m = MIMETypes(environ)
    eq_(m.mimetype('text/html'), 'text/html')
Example #10
0
def test_with_no_extention():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test'
    environ['HTTP_ACCEPT'] = 'application/xml'
    m = MIMETypes(environ)
    eq_(m.mimetype('text/html'), False)
    eq_(m.mimetype('application/xml'), 'application/xml')
Example #11
0
 def test_start_response_status(self):
     controller = TestController(response.ok, body='test body')
     self.controllers.mount('^/test/$', [methods.GET], controller)
     environ = util.test_environ(path_info='/test/')
     start_response = TestStartResponse()
     self.controllers(environ, start_response)
     expected_status = '%d %s' % (httplib.OK, httplib.responses[httplib.OK])
     self.assertEqual(start_response.status, expected_status)
Example #12
0
def test_with_no_extention():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test'
    environ['HTTP_ACCEPT'] = 'application/xml'
    m = MIMETypes(environ)
    eq_(m.mimetype('text/html'), False)
    eq_(m.mimetype('application/xml'), 'application/xml')
Example #13
0
 def test_start_response_headers(self):
     body = 'this is a longer test body to test content length'
     controller = TestController(response.ok, body=body)
     self.controllers.mount('^/test/$', [methods.GET], controller)
     environ = util.test_environ(path_info='/test/')
     start_response = TestStartResponse()
     self.controllers(environ, start_response)
     self.assertIn('content-length', start_response.headers)
     self.assertEqual(len(body), int(start_response.headers['content-length']))
Example #14
0
 def test_regex(self):
     environ = util.test_environ('/foo/bar/baz/')
     self.tree.mount('^/foo/[^/]+', Mock())
     self.tree(environ, Mock())
     self.assertEqual(environ['PATH_INFO'], '/baz/')
     self.assertEqual(environ['SCRIPT_NAME'], '/foo/bar/')
Example #15
0
def test_with_no_extention_and_no_accept():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test'
    m = MIMETypes(environ)
    eq_(m.mimetype('html'), 'text/html')
Example #16
0
def test_with_no_extention_and_no_accept():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test'
    m = MIMETypes(environ)
    eq_(m.mimetype('html'), 'text/html')
Example #17
0
 def test_not_found(self):
     controller = TestController(response.ok, body='test body')
     self.controllers.mount('^/found/$', [methods.GET], controller)
     environ = util.test_environ(path_info='/found/not/')
     self.assertRaises(HttpNotFound, self.controllers, environ, Mock())
Example #18
0
def test_usage():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test.html'
    m = MIMETypes(environ)
    eq_(m.mimetype('html'), 'text/html')
Example #19
0
 def test_method_not_allowed(self):
     controller = TestController(response.ok, body='test body')
     self.controllers.mount('^/found/$', [methods.GET], controller)
     environ = util.test_environ(path_info='/found/', method=methods.POST)
     self.assertRaises(HttpMethodNotAllowed, self.controllers, environ, Mock())
Example #20
0
 def test_double_match(self):
     environ = util.test_environ(path_info='/foo/foo/')
     self.tree.mount('^/foo', Mock())
     self.tree(environ, Mock())
     self.assertEqual(environ['PATH_INFO'], '/foo/')
     self.assertEqual(environ['SCRIPT_NAME'], '/foo/')
Example #21
0
 def test_request_fields(self):
     controller = TestController(response.ok, body='test body')
     self.controllers.mount('^/test/$', [methods.GET], controller)
     environ = util.test_environ(path_info='/test/')
     self.controllers(environ, Mock())
Example #22
0
 def test_not_found(self):
     environ = util.test_environ()
     start_response = Mock()
     self.assertRaises(HttpNotFound, self.tree, environ, start_response)
Example #23
0
def test_usage():
    _check_webob_dependency()
    environ = test_environ()
    environ['PATH_INFO'] = '/test.html'
    m = MIMETypes(environ)
    eq_(m.mimetype('html'), 'text/html')