本文整理汇总了Python中werkzeug.Client.put方法的典型用法代码示例。如果您正苦于以下问题:Python Client.put方法的具体用法?Python Client.put怎么用?Python Client.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.Client
的用法示例。
在下文中一共展示了Client.put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TasksViewTest
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import put [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)
示例2: TaskViewTest
# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import put [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)