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


Python Client.delete方法代码示例

本文整理汇总了Python中werkzeug.Client.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Client.delete方法的具体用法?Python Client.delete怎么用?Python Client.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.Client的用法示例。


在下文中一共展示了Client.delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TasksViewTest

# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import delete [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 delete [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

示例3: WebTestCase

# 需要导入模块: from werkzeug import Client [as 别名]
# 或者: from werkzeug.Client import delete [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)
开发者ID:mgax,项目名称:notespace,代码行数:98,代码来源:webapi.py


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