當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。