当前位置: 首页>>代码示例>>Python>>正文


Python Client.put方法代码示例

本文整理汇总了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)
开发者ID:jakobadam,项目名称:letsplantheevent,代码行数:56,代码来源:tests.py

示例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)
开发者ID:tnakamura,项目名称:SilverTask,代码行数:42,代码来源:test_views.py


注:本文中的werkzeug.Client.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。