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')
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/')
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')
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')
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)
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)
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')
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)
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']))
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/')
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')
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())
def test_usage(): _check_webob_dependency() environ = test_environ() environ['PATH_INFO'] = '/test.html' m = MIMETypes(environ) eq_(m.mimetype('html'), 'text/html')
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())
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/')
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())
def test_not_found(self): environ = util.test_environ() start_response = Mock() self.assertRaises(HttpNotFound, self.tree, environ, start_response)