本文整理汇总了Python中werkzeug.Client.post方法的典型用法代码示例。如果您正苦于以下问题:Python Client.post方法的具体用法?Python Client.post怎么用?Python Client.post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.Client
的用法示例。
在下文中一共展示了Client.post方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ie7_unc_path
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import post [as 别名]
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]
示例2: ChannelsViewTest
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import post [as 别名]
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)
示例3: test_multipart
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import post [as 别名]
def test_multipart():
"""Tests multipart parsing against data collected from webbrowsers"""
resources = join(dirname(__file__), 'multipart')
client = Client(form_data_consumer, Response)
repository = [
('firefox3-2png1txt', '---------------------------186454651713519341951581030105', [
(u'anchor.png', 'file1', 'image/png', 'file1.png'),
(u'application_edit.png', 'file2', 'image/png', 'file2.png')
], u'example text'),
('firefox3-2pnglongtext', '---------------------------14904044739787191031754711748', [
(u'accept.png', 'file1', 'image/png', 'file1.png'),
(u'add.png', 'file2', 'image/png', 'file2.png')
], u'--long text\r\n--with boundary\r\n--lookalikes--'),
('opera8-2png1txt', '----------zEO9jQKmLc2Cq88c23Dx19', [
(u'arrow_branch.png', 'file1', 'image/png', 'file1.png'),
(u'award_star_bronze_1.png', 'file2', 'image/png', 'file2.png')
], u'blafasel öäü'),
('webkit3-2png1txt', '----WebKitFormBoundaryjdSFhcARk8fyGNy6', [
(u'gtk-apply.png', 'file1', 'image/png', 'file1.png'),
(u'gtk-no.png', 'file2', 'image/png', 'file2.png')
], u'this is another text with ümläüts'),
('ie6-2png1txt', '---------------------------7d91b03a20128', [
(u'file1.png', 'file1', 'image/x-png', 'file1.png'),
(u'file2.png', 'file2', 'image/x-png', 'file2.png')
], u'ie6 sucks :-/')
]
for name, boundary, files, text in repository:
folder = join(resources, name)
data = get_contents(join(folder, 'request.txt'))
for filename, field, content_type, fsname in files:
response = client.post('/?object=' + field, data=data, content_type=
'multipart/form-data; boundary="%s"' % boundary,
content_length=len(data))
lines = response.data.split('\n', 3)
assert lines[0] == repr(filename)
assert lines[1] == repr(field)
assert lines[2] == repr(content_type)
assert lines[3] == get_contents(join(folder, fsname))
response = client.post('/?object=text', data=data, content_type=
'multipart/form-data; boundary="%s"' % boundary,
content_length=len(data))
assert response.data == repr(text)
示例4: TasksViewTest
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import post [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: TaskViewTest
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import post [as 别名]
class TaskViewTest(GAETestBase):
CLEANUP_USED_KIND = True
def setUp(self):
init_recording()
app = get_application()
self.client = Client(app, BaseResponse)
def tearDown(self):
disable_recording()
def test_post(self):
data = {
"name": "foo",
}
response = self.client.post('/tasks', data=data, follow_redirects=True)
actual = Task.all().get()
self.assertEquals("foo", actual.name)
def test_delete(self):
key = Task(name="fuga").put()
tasks = Task.all().fetch(100)
self.assertEquals(1, len(tasks))
response = self.client.delete('/tasks/%s' % key, follow_redirects=True)
tasks = Task.all().fetch(100)
self.assertEquals(0, len(tasks))
def test_put(self):
key = Task(name="hoge").put()
tasks = Task.all().fetch(100)
self.assertEquals(1, len(tasks))
input_stream = StringIO('{ "name" : "fuga" }')
response = self.client.put('/tasks/%s' % key,
input_stream=input_stream,
follow_redirects=True)
actual = Task.get(key)
self.assertEquals("fuga", actual.name)
示例6: WebTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import post [as 别名]
class WebTestCase(unittest.TestCase):
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)
def tearDown(self):
rmtree(self.test_doc_path)
def failUnlessJsonResponse(self, resp, json_data):
self.failUnlessEqual(resp.status_code, 200)
self.failUnlessEqual(resp.headers['Content-Type'], 'application/json')
self.failUnlessEqual(json.loads(resp.data), json_data)
def test_notes_listing(self):
self.failUnlessJsonResponse(self.client.get('/notes'), [0, 1, 2])
def test_get_note(self):
self.failUnlessJsonResponse(self.client.get('/notes/0'), {
'props': {'desc': 'ROOT'},
'children': [1, 2],
})
def test_change_note(self):
test_props = {'desc': 'new content here', 'a': 'b'}
resp = self.client.post('/notes/1', data={'props': json.dumps(test_props)})
self.doc.abort() # checking if transaction was committed
self.failUnlessEqual(dict(self.doc.notes[1]), test_props)
self.failUnlessJsonResponse(resp, {'props': test_props, 'children': []})
def test_create_note(self):
resp = self.client.post('/notes', data={
'parent_id': 1, 'props': json.dumps({'f': 'g'})})
self.failUnlessJsonResponse(resp, 3)
self.doc.abort() # checking if transaction was committed
self.failUnlessEqual(len(self.doc.notes), 4)
self.failUnlessEqual(dict(self.doc.notes[3]), {'f': 'g'})
self.failUnlessEqual(list(self.doc.notes[1].children_ids()), [3])
self.failUnlessEqual(list(self.doc.notes[0].children_ids()), [1, 2])
def test_set_parent(self):
resp = self.client.post('/notes/2/parent', data={'parent_id': 1})
self.failUnlessEqual(resp.status_code, 200)
self.doc.abort() # checking if transaction was committed
self.failUnlessEqual(list(self.doc.notes[1].children_ids()), [2])
self.failUnlessEqual(list(self.doc.notes[0].children_ids()), [1])
def test_remove_note(self):
self.client.post('/notes/2/parent', data={'parent_id': 1})
self.failUnless(1 in self.doc.notes)
self.failUnless(1 in list(self.doc.notes[0].children_ids()))
self.failUnless(2 in self.doc.notes)
self.failUnless(2 in list(self.doc.notes[1].children_ids()))
resp = self.client.delete('/notes/1')
self.failUnlessJsonResponse(resp, 'ok')
self.failIf(1 in self.doc.notes)
self.failIf(1 in list(self.doc.notes[0].children_ids()))
self.failIf(2 in self.doc.notes)
def test_custom_html(self):
gsm = component.getGlobalSiteManager()
def customViewAdapter(note):
if note.id == test_note_id:
return CustomView(note)
gsm.registerSubscriptionAdapter(customViewAdapter,
required=[INote], provided=INoteView)
test_note_id = self.doc.create_note({'a': 'b'}).id
self.failUnlessJsonResponse(self.client.get('/notes/%d' % test_note_id), {
'props': {'a': 'b'},
'children': [],
'html': '<em>hello custom!</em>',
})
gsm.unregisterSubscriptionAdapter(customViewAdapter,
required=[INote], provided=INoteView)
def test_ajax(self):
gsm = component.getGlobalSiteManager()
def customViewAdapter(note):
if note.id == test_note_id:
return CustomView(note)
gsm.registerSubscriptionAdapter(customViewAdapter,
required=[INote], provided=INoteView)
test_note_id = self.doc.create_note({}).id
resp = self.client.post('/notes/3/ajax', data={'args': json.dumps({'token': 'asdf'})})
self.failUnlessJsonResponse(resp, '-asdf-')
gsm.unregisterSubscriptionAdapter(customViewAdapter,
required=[INote], provided=INoteView)
示例7: SolaceTestCase
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import post [as 别名]
class SolaceTestCase(unittest.TestCase):
"""Subclass of the standard test case that creates and drops the database."""
def setUp(self):
from solace import database, settings, templating
from solace.application import application
self.__old_settings = dict(settings.__dict__)
settings.revert_to_default()
settings.DATABASE_URI = 'sqlite:///' + TEST_DATABASE
settings.TRACK_QUERIES = True
settings.DATABASE_ECHO = False
settings.MAIL_LOG_FILE = tempfile.NamedTemporaryFile()
database.refresh_engine()
database.init()
self.client = Client(application, TestResponse)
self.is_logged_in = False
def get_session(self):
from solace import settings
for cookie in self.client.cookie_jar:
if cookie.name == settings.COOKIE_NAME:
value = unquote_header_value(cookie.value)
return SecureCookie.unserialize(value, settings.SECRET_KEY)
def get_exchange_token(self):
return loads(self.client.get('/_request_exchange_token').data)['token']
def get_mails(self):
from solace import settings
pos = settings.MAIL_LOG_FILE.tell()
settings.MAIL_LOG_FILE.seek(0)
mails = settings.MAIL_LOG_FILE.read().split('\n%s\n\n' % ('-' * 79))
settings.MAIL_LOG_FILE.seek(pos)
return [message_from_string(x) for x in mails if x]
def normalize_local_path(self, path):
if path in ('', '.'):
path = path
elif path.startswith(BASE_URL):
path = path[len(BASE_URL) - 1:]
return path
def submit_form(self, path, data, follow_redirects=False):
response = self.client.get(path)
try:
tree = html.fromstring(response.data)
form = tree.xpath('//form')[0]
#was: form = response.html.xpath('//form')[0]
except IndexError:
raise RuntimeError('no form on page')
csrf_token = form.xpath('//input[@name="_csrf_token"]')[0]
data['_csrf_token'] = csrf_token.attrib['value']
action = self.normalize_local_path(form.attrib['action'])
return self.client.post(action, method=form.attrib['method'].upper(),
data=data, follow_redirects=follow_redirects)
def login(self, username, password):
try:
return self.submit_form('/login', {
'username': username,
'password': password
})
finally:
self.is_logged_in = True
def logout(self):
self.is_logged_in = False
return self.client.get('/logout?_xt=%s' % self.get_exchange_token())
def tearDown(self):
from solace import database, settings
database.refresh_engine()
try:
os.remove(TEST_DATABASE)
except OSError:
pass
settings.__dict__.clear()
settings.__dict__.update(self.__old_settings)
del self.is_logged_in
示例8: test_multipart
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import post [as 别名]
def test_multipart():
"""Tests multipart parsing against data collected from webbrowsers"""
resources = join(dirname(__file__), "multipart")
client = Client(form_data_consumer, Response)
repository = [
(
"firefox3-2png1txt",
"---------------------------186454651713519341951581030105",
[
(u"anchor.png", "file1", "image/png", "file1.png"),
(u"application_edit.png", "file2", "image/png", "file2.png"),
],
u"example text",
),
(
"firefox3-2pnglongtext",
"---------------------------14904044739787191031754711748",
[(u"accept.png", "file1", "image/png", "file1.png"), (u"add.png", "file2", "image/png", "file2.png")],
u"--long text\r\n--with boundary\r\n--lookalikes--",
),
(
"opera8-2png1txt",
"----------zEO9jQKmLc2Cq88c23Dx19",
[
(u"arrow_branch.png", "file1", "image/png", "file1.png"),
(u"award_star_bronze_1.png", "file2", "image/png", "file2.png"),
],
u"blafasel öäü",
),
(
"webkit3-2png1txt",
"----WebKitFormBoundaryjdSFhcARk8fyGNy6",
[(u"gtk-apply.png", "file1", "image/png", "file1.png"), (u"gtk-no.png", "file2", "image/png", "file2.png")],
u"this is another text with ümläüts",
),
(
"ie6-2png1txt",
"---------------------------7d91b03a20128",
[(u"file1.png", "file1", "image/x-png", "file1.png"), (u"file2.png", "file2", "image/x-png", "file2.png")],
u"ie6 sucks :-/",
),
]
for name, boundary, files, text in repository:
folder = join(resources, name)
data = get_contents(join(folder, "request.txt"))
for filename, field, content_type, fsname in files:
response = client.post(
"/?object=" + field,
data=data,
content_type='multipart/form-data; boundary="%s"' % boundary,
content_length=len(data),
)
lines = response.data.split("\n", 3)
assert lines[0] == repr(filename)
assert lines[1] == repr(field)
assert lines[2] == repr(content_type)
assert lines[3] == get_contents(join(folder, fsname))
response = client.post(
"/?object=text",
data=data,
content_type='multipart/form-data; boundary="%s"' % boundary,
content_length=len(data),
)
assert response.data == repr(text)