本文整理汇总了Python中werkzeug.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestWSLoader
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: SessionMiddlewareTestCase
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')
示例3: TestSession
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'
示例4: test_responder
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'
示例5: test_ie7_unc_path
def test_ie7_unc_path():
client = Client(form_data_consumer, Response)
data_file = join(dirname(__file__), 'multipart', 'ie7_full_path_request.txt')
data = get_contents(data_file)
boundary = '---------------------------7da36d1b4a0164'
response = client.post('/?object=cb_file_upload_multiple', data=data, content_type=
'multipart/form-data; boundary="%s"' % boundary, content_length=len(data))
lines = response.data.split('\n', 3)
assert lines[0] == repr(u'Sellersburg Town Council Meeting 02-22-2010doc.doc'), lines[0]
示例6: TasksViewTest
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)
示例7: MaintenanceCheckTestCase
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)
示例8: wrapper
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
示例9: AppStatsMiddlewareTestCase
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)
示例10: setUp
def setUp(self):
self.test_doc_path = mkdtemp()
self.doc = open_document(path.join(self.test_doc_path, 'test_doc.db'))
self.doc.create_note({'desc': 'note 1'})
self.doc.create_note({'desc': 'note 2'})
self.app = server.CorkApp(self.doc)
self.client = Client(self.app, BaseResponse)
示例11: DownloadicsTest
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'])
示例12: open
def open(self, *args, **kwargs):
if self.context_preserved:
_request_ctx_stack.pop()
self.context_preserved = False
kwargs.setdefault('environ_overrides', {}) \
['flask._preserve_context'] = self.preserve_context
as_tuple = kwargs.pop('as_tuple', False)
buffered = kwargs.pop('buffered', False)
follow_redirects = kwargs.pop('follow_redirects', False)
builder = EnvironBuilder(*args, **kwargs)
if self.application.config.get('SERVER_NAME'):
server_name = self.application.config.get('SERVER_NAME')
if ':' not in server_name:
http_host, http_port = server_name, None
else:
http_host, http_port = server_name.split(':', 1)
if builder.base_url == 'http://localhost/':
# Default Generated Base URL
if http_port != None:
builder.host = http_host + ':' + http_port
else:
builder.host = http_host
old = _request_ctx_stack.top
try:
return Client.open(self, builder,
as_tuple=as_tuple,
buffered=buffered,
follow_redirects=follow_redirects)
finally:
self.context_preserved = _request_ctx_stack.top is not old
示例13: CronOnlyTestCase
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)
示例14: setUp
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'])
示例15: ChannelsViewTest
class ChannelsViewTest(unittest.TestCase):
def setUp(self):
self.c = Client(views.handler, BaseResponse)
def test_POSTing_with_create_client_id_header_should_create_new_channel(self):
r = self.c.post(path="/channels/", headers={"Create-Client-Id":"1"})
self.assertEquals(r.status_code, 200)
self.assertTrue("1" in views.clients)