本文整理汇总了Python中werkzeug.Client.get方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get方法的具体用法?Python Client.get怎么用?Python Client.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.Client
的用法示例。
在下文中一共展示了Client.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestWSLoader
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class TestWSLoader(unittest.TestCase):
def setUp(self):
app = wsloader.WSLoader(confdir = os.getcwd() + '/conf/')
self.client = Client(app, BaseResponse)
def test_service_check(self):
response = self.client.get("/greeter/service_check")
print response.data
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, "OK")
def test_defaults(self):
response = self.client.get("/greeter/say_hello")
self.assertEqual(response.status_code, 200)
body = json.loads(response.data)
self.assertEqual(body['response'], "Hello World!")
def test_aliased_class(self):
response = self.client.get('/helloworld/say_hello?greeting="Hola"&to_whom="Amigos!"')
try:
body = json.loads(response.data)
except Exception, e:
print e
print response.data
return
self.assertEqual(body['response'], "Hola Amigos!")
示例2: TestSession
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class TestSession(unittest.TestCase):
def setUp(self):
self.app = make_wsgi('Testruns')
self.client = Client(self.app, BaseResponse)
def tearDown(self):
self.client = None
self.app = None
def test_session_persist(self):
r = self.client.get('/sessiontests/setfoo')
self.assertEqual(r.status, '200 OK')
self.assertEqual(r.data, b'foo set')
r = self.client.get('/sessiontests/getfoo')
self.assertEqual(r.status, '200 OK')
self.assertEqual(r.data, b'bar')
def test_session_regen_id(self):
ta = TestApp(self.app)
r = ta.get('/sessiontests/setfoo', status=200)
assert r.session['foo'] == 'bar'
sid = r.session.id
assert sid in r.headers['Set-Cookie']
r = ta.get('/sessiontests/regenid', status=200)
assert r.session.id != sid
assert r.session.id in r.headers['Set-Cookie']
r = ta.get('/sessiontests/getfoo', status=200)
assert r.body == b'bar'
示例3: SessionMiddlewareTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class SessionMiddlewareTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
def setUp(self):
s = LazySettings(settings_module='kay.tests.settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def tearDown(self):
pass
def test_countup(self):
response = self.client.get('/countup')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, '1')
response = self.client.get('/countup')
self.assertEqual(response.data, '2')
response = self.client.get('/countup')
self.assertEqual(response.data, '3')
response = self.client.get('/countup')
self.assertEqual(response.data, '4')
response = self.client.get('/countup')
self.assertEqual(response.data, '5')
示例4: TasksViewTest
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class TasksViewTest(unittest.TestCase):
def setUp(self):
self.c = Client(views.handler, BaseResponse)
# clear state
views.TASKS = {}
views.clients = {}
views.subscriptions = {}
def test_POST(self):
t = models.Task(name='Task1')
r = self.c.post(path='/tasks/', headers={'Content-Type':tubes.JSON}, data=t.to_json_str())
# check response
self.assertEquals(r.status_code, 201)
task = json.loads(r.data)
self.assertEquals(task['name'], 'Task1')
self.assertTrue('/tasks/0' in r.headers.get('Location'))
# back-end
task = views.TASKS['0']
self.assertTrue(task != None)
self.assertEquals(task.name, 'Task1')
def test_PUT(self):
views.TASKS['0'] = models.Task()
r = self.c.put(path='/tasks/0',
headers={'Content-Type':tubes.JSON},
data=models.Task(name='Task_0').to_json_str())
self.assertEquals(r.status_code, 200)
# check response
task = json.loads(r.data)
self.assertEquals(task['name'], 'Task_0')
# back-end
task = views.TASKS['0']
self.assertEquals(task.name, 'Task_0')
def test_DELETE(self):
views.TASKS['0'] = models.Task()
r = self.c.delete(path='/tasks/0')
self.assertEquals(r.status_code, 204)
self.assertTrue(views.TASKS.get('0') == None)
def test_GET_tasks(self):
views.TASKS['0'] = models.Task(name='foo')
r = self.c.get(path='/tasks/')
self.assertTrue('foo' in r.data)
def test_GET_task(self):
views.TASKS['0'] = models.Task(name='foo')
r = self.c.get(path='/tasks/0')
self.assertTrue('foo' in r.data)
示例5: MaintenanceCheckTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class MaintenanceCheckTestCase(unittest.TestCase):
def setUp(self):
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
stub = datastore_file_stub.DatastoreFileStub('test','/dev/null',
'/dev/null')
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)
apiproxy_stub_map.apiproxy.RegisterStub(
'user', user_service_stub.UserServiceStub())
apiproxy_stub_map.apiproxy.RegisterStub(
'memcache', memcache_stub.MemcacheServiceStub())
apiproxy_stub_map.apiproxy.RegisterStub(
'urlfetch', urlfetch_stub.URLFetchServiceStub())
s = LazySettings(settings_module='kay.tests.settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
if apiproxy_stub_map.apiproxy\
._APIProxyStubMap__stub_map.has_key('capability_service'):
del(apiproxy_stub_map.apiproxy\
._APIProxyStubMap__stub_map['capability_service'])
def tearDown(self):
pass
def test_success(self):
"""Test with normal CapabilityServiceStub"""
apiproxy_stub_map.apiproxy.RegisterStub(
'capability_service',
capability_stub.CapabilityServiceStub())
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
def test_failure(self):
"""Test with DisabledCapabilityServiceStub
"""
apiproxy_stub_map.apiproxy.RegisterStub(
'capability_service',
mocked_capability_stub.DisabledCapabilityServiceStub())
response = self.client.get('/')
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers['Location'],
'http://localhost/maintenance_page')
response = self.client.get('/index2')
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers['Location'],
'http://localhost/no_decorator')
response = self.client.get('/no_decorator')
self.assertEqual(response.status_code, 200)
示例6: DownloadicsTest
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class DownloadicsTest(GAETestBase):
def setUp(self):
app = get_application()
self.client = Client(app, BaseResponse)
self.test_values = {
'date': datetime.datetime(2016, 5, 20, 15, 0),
'title': 'THIS IS TITLE',
'description': 'THIS IS TITLE',
}
eve = Event(
event_date=self.test_values['date'],
title=self.test_values['title'],
description=self.test_values['description'],
)
eve.put()
events = Event.all().fetch(100)
self.assertEquals(len(events), 1)
self.assertEquals(events[0].title, 'THIS IS TITLE')
self.event_key = str(events[0].key())
def test_download_individual_icsfile(self):
target_url = urlparse.urljoin('/ical/', self.event_key)
res = self.client.get(target_url)
self.assertEquals(res.status_code, 200)
downloaded = res.get_data()
reparsed = icalendar.Calendar.from_ical(downloaded)
reparsed_eve = reparsed.walk('VEVENT')[0]
stringfied = self.test_values['date'].strftime('%Y%m%dT%H%M%S')
self.assertEquals(reparsed_eve['summary'].to_ical(), self.test_values['title'])
self.assertEquals(reparsed_eve['dtstart'].to_ical(), stringfied)
self.assertEquals(reparsed_eve['description'].to_ical(), self.test_values['description'])
示例7: CronOnlyTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class CronOnlyTestCase(GAETestBase):
def setUp(self):
s = LazySettings(settings_module='kay.tests.settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def test_cron_only(self):
response = self.client.get("/cron",
headers=(('X-AppEngine-Cron', 'true'),))
self.assertEqual(response.status_code, 200)
self.assertTrue(response.data == "OK")
def test_cron_only_failure(self):
response = self.client.get("/cron")
self.assertEqual(response.status_code, 403)
示例8: AppStatsMiddlewareTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class AppStatsMiddlewareTestCase(GAETestBase):
KIND_NAME_UNSWAPPED = False
USE_PRODUCTION_STUBS = True
CLEANUP_USED_KIND = True
def setUp(self):
from google.appengine.api import memcache
memcache.flush_all()
s = LazySettings(settings_module='kay.tests.appstats_settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def tearDown(self):
pass
def test_appstats_middleware(self):
request = Request({})
middleware = AppStatsMiddleware()
r = middleware.process_request(request)
self.assertTrue(r is None)
r = middleware.process_response(request, BaseResponse("", 200))
self.assertTrue(isinstance(r, BaseResponse))
summary = recording.load_summary_protos()
self.assert_(summary)
def test_appstats_middleware_request(self):
response = self.client.get('/no_decorator')
summary = recording.load_summary_protos()
self.assert_(summary)
示例9: test_responder
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
def test_responder():
"""Responder decorator"""
def foo(environ, start_response):
return BaseResponse('Test')
client = Client(responder(foo), BaseResponse)
response = client.get('/')
assert response.status_code == 200
assert response.data == 'Test'
示例10: MaintenanceCheckTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class MaintenanceCheckTestCase(unittest.TestCase):
def setUp(self):
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
stub = datastore_file_stub.DatastoreFileStub("test", "/dev/null", "/dev/null")
apiproxy_stub_map.apiproxy.RegisterStub("datastore_v3", stub)
apiproxy_stub_map.apiproxy.RegisterStub("user", user_service_stub.UserServiceStub())
apiproxy_stub_map.apiproxy.RegisterStub("memcache", memcache_stub.MemcacheServiceStub())
apiproxy_stub_map.apiproxy.RegisterStub("urlfetch", urlfetch_stub.URLFetchServiceStub())
s = LazySettings(settings_module="kay.tests.settings")
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
if apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map.has_key("capability_service"):
del (apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map["capability_service"])
def tearDown(self):
pass
def test_success(self):
"""Test with normal CapabilityServiceStub"""
apiproxy_stub_map.apiproxy.RegisterStub("capability_service", capability_stub.CapabilityServiceStub())
response = self.client.get("/")
self.assertEqual(response.status_code, 200)
def test_failure(self):
"""Test with DisabledCapabilityServiceStub
"""
apiproxy_stub_map.apiproxy.RegisterStub(
"capability_service", mocked_capability_stub.DisabledCapabilityServiceStub()
)
response = self.client.get("/")
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], "http://localhost/maintenance_page")
response = self.client.get("/index2")
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers["Location"], "http://localhost/no_decorator")
response = self.client.get("/no_decorator")
self.assertEqual(response.status_code, 200)
示例11: CronOnlyDebugTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class CronOnlyDebugTestCase(GAETestBase):
def setUp(self):
s = LazySettings(settings_module='kay.tests.settings')
s.DEBUG = True
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def test_cron_only_failure(self):
from kay.utils import is_dev_server
response = self.client.get("/cron")
if is_dev_server():
self.assertEqual(response.status_code, 200)
else:
self.assertEqual(response.status_code, 403)
def test_cron_only(self):
response = self.client.get("/cron",
headers=(('X-AppEngine-Cron', 'true'),))
self.assertEqual(response.status_code, 200)
self.assertTrue(response.data == "OK")
示例12: test_View_index
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class test_View_index(GAETestBase):
CLEANUP_USED_KIND = True
USE_PRODUCTION_STUBS = True
def setUp(self):
init_recording()
app = get_application()
self.client = Client(app, BaseResponse)
def tearDown(self):
disable_recording()
def test_base(self):
response = self.client.get('/')
self.assertEquals(response.status_code, 404)
def test_client_get(self):
response = self.client.get('/client')
self.assertEquals(response.status_code, 301)
def test_client_head(self):
self.fail('test_View_index.test_client_head not yet written')
def test_client_post(self):
self.fail('test_View_index.test_client_post not yet written')
def test_client_put(self):
self.fail('test_View_index.test_client_put not yet written')
def test_client_delete(self):
self.fail('test_View_index.test_client_delete not yet written')
def test_client_options(self):
self.fail('test_View_index.test_client_options not yet written')
def test_client_trace(self):
self.fail('test_View_index.test_client_trace not yet written')
def test_client_connect(self):
self.fail('test_View_index.test_client_connect not yet written')
示例13: wrapper
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
def wrapper(self):
client = Client(Application(), BaseResponse)
response = client.get(url, headers={'Accept': accept})
eq_(response.status_code, status_code)
if template:
assert response.template ==template
f(self, response, response.context, PyQuery(response.data))
# Validate after other tests so we know everything else works.
# Hacky piggybacking on --verbose so tests go faster.
if '--verbose' in sys.argv:
validator = post_multipart('validator.w3.org', '/check',
{'fragment': response.data})
assert PyQuery(validator)('#congrats').size() == 1
示例14: MaintenanceCheckTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class MaintenanceCheckTestCase(unittest.TestCase):
def setUp(self):
s = LazySettings(settings_module='kay.tests.settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
if apiproxy_stub_map.apiproxy\
._APIProxyStubMap__stub_map.has_key('capability_service'):
del(apiproxy_stub_map.apiproxy\
._APIProxyStubMap__stub_map['capability_service'])
def tearDown(self):
pass
def test_success(self):
"""Test with normal CapabilityServiceStub"""
apiproxy_stub_map.apiproxy.RegisterStub(
'capability_service',
capability_stub.CapabilityServiceStub())
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
def test_failure(self):
"""Test with DisabledCapabilityServiceStub
"""
apiproxy_stub_map.apiproxy.RegisterStub(
'capability_service',
mocked_capability_stub.DisabledCapabilityServiceStub())
response = self.client.get('/')
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers['Location'],
'http://localhost/_kay/maintenance_page')
response = self.client.get('/index2')
self.assertEqual(response.status_code, 302)
self.assertEqual(response.headers['Location'],
'http://localhost/no_decorator')
response = self.client.get('/no_decorator')
self.assertEqual(response.status_code, 200)
示例15: MaintenanceCheckTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import get [as 别名]
class MaintenanceCheckTestCase(unittest.TestCase):
def setUp(self):
s = LazySettings(settings_module='kay.tests.settings')
app = get_application(settings=s)
self.client = Client(app, BaseResponse)
def tearDown(self):
pass
def test_redirect(self):
"""Test with normal CapabilityServiceStub"""
response = self.client.get('/oldpage', follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, "New")