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


Python SimpleDoc.delete方法代码示例

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


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

示例1: test_patch_subresource

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
    def test_patch_subresource(self):
        # create new resource and subresource
        s = SimpleDoc(a="Answer to everything", b=42).save()
        d = ComplexDoc(l=['a', 'b'], n=999, r=s).save()

        response = self.client.get('/simpledoc/%s/complexdoc/%s' % (s.id, d.id))
        etag = response.get_json()[config.ETAG]
        headers = [('If-Match', etag)]

        # patch document
        patch_data = {'l': ['x', 'y', 'z'], 'r': str(s.id)}
        patch_url = '/simpledoc/%s/complexdoc/%s' % (s.id, d.id)
        response = self.client.patch(patch_url, data=json.dumps(patch_data),
                                     content_type='application/json', headers=headers)
        self.assertEqual(response.status_code, 200)
        resp_json = response.get_json()
        self.assertEqual(resp_json[config.STATUS], "OK")

        # check, if really edited
        response = self.client.get('/simpledoc/%s/complexdoc/%s' % (s.id, d.id))
        json_data = response.get_json()
        self.assertListEqual(json_data['l'], ['x', 'y', 'z'])
        self.assertEqual(json_data['n'], 999)

        # cleanup
        s.delete()
        d.delete()
开发者ID:satyanani40,项目名称:eve-mongoengine,代码行数:29,代码来源:test_patch.py

示例2: test_find_all_projection

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
 def test_find_all_projection(self):
     d = SimpleDoc(a='Tom', b=223).save()
     response = self.client.get('/simpledoc?projection={"a": 1}')
     self.assertNotIn('b', response.get_json()['_items'][0])
     response = self.client.get('/simpledoc?projection={"a": 1, "b": 1}')
     data = response.get_json()['_items'][0]
     self.assertIn('b', data)
     self.assertIn('a', data)
     d.delete()
开发者ID:Arable,项目名称:eve-mongoengine,代码行数:11,代码来源:test_get.py

示例3: test_find_all_filtering

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
 def test_find_all_filtering(self):
     d = SimpleDoc(a='x', b=987).save()
     d2 = SimpleDoc(a='y', b=123).save()
     response = self.client.get('/simpledoc?where={"a": "y"}')
     json_data = response.get_json()
     try:
         self.assertEqual(len(json_data['_items']), 1)
         self.assertEqual(json_data['_items'][0]['b'], 123)
     finally:
         d.delete()
         d2.delete()
开发者ID:kcaylor,项目名称:eve-mongoengine,代码行数:13,代码来源:test_get.py

示例4: test_find_one

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
 def test_find_one(self):
     d = SimpleDoc(a='Tom', b=223).save()
     response = self.client.get('/simpledoc/%s' % d.id)
     # has to return one record
     json_data = response.get_json()
     self.assertIn(config.LAST_UPDATED, json_data)
     self.assertIn(config.DATE_CREATED, json_data)
     self.assertEqual(json_data['_id'], str(d.id))
     self.assertEqual(json_data['a'], 'Tom')
     self.assertEqual(json_data['b'], 223)
     d.delete()
开发者ID:kcaylor,项目名称:eve-mongoengine,代码行数:13,代码来源:test_get.py

示例5: test_reference_field

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
 def test_reference_field(self):
     s = SimpleDoc(a="samurai", b=911)
     s.save()
     d = ComplexDoc(r=s)
     d.save()
     response = self.client.get('/complexdoc')
     try:
         json_data = response.get_json()[config.ITEMS][0]
         self.assertEqual(json_data['r'], str(s.id))
     finally:
         # cleanup
         d.delete()
         s.delete()
开发者ID:Algorhythm-IO,项目名称:eve-mongoengine,代码行数:15,代码来源:test_fields.py

示例6: test_find_one_projection

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
 def test_find_one_projection(self):
     # XXX: this it not eve's standard!
     self.skipTest('Projection on one document not supported')
     d = SimpleDoc(a='Tom', b=223).save()
     response = self.client.get('/simpledoc/%s?projection={"a":1}' % d.id)
     # has to return one record
     json_data = response.get_json()
     self.assertIn(config.LAST_UPDATED, json_data)
     self.assertIn(config.DATE_CREATED, json_data)
     self.assertNotIn('b', json_data)
     self.assertEqual(json_data['_id'], str(d.id))
     self.assertEqual(json_data['a'], 'Tom')
     d.delete()
开发者ID:Arable,项目名称:eve-mongoengine,代码行数:15,代码来源:test_get.py

示例7: test_find_all

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
 def test_find_all(self):
     _all = []
     for data in ({'a': "Hello", 'b':1},
                  {'a': "Hi", 'b': 2},
                  {'a': "Seeya", 'b': 3}):
         d = SimpleDoc(**data).save()
         _all.append(d)
     response = self.client.get('/simpledoc')
     self.assertEqual(response.status_code, 200)
     data = response.get_json()
     s = set([item['a'] for item in data['_items']])
     self.assertSetEqual(set(['Hello', 'Hi', 'Seeya']), s)
     # delete records
     for d in _all:
         d.delete()
开发者ID:kcaylor,项目名称:eve-mongoengine,代码行数:17,代码来源:test_get.py

示例8: test_embedded_resource_serialization

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
 def test_embedded_resource_serialization(self):
     s = SimpleDoc(a="Answer to everything", b=42).save()
     d = ComplexDoc(r=s).save()
     response = self.client.get('/complexdoc?embedded={"r":1}')
     json_data = response.get_json()
     expected = {'a': "Answer to everything", 'b': 42}
     try:
         emb = json_data['_items'][0]['r']
         self.assertEqual(emb['a'], expected['a'])
         self.assertEqual(emb['b'], expected['b'])
         self.assertIn(config.DATE_CREATED, emb)
         self.assertIn(config.LAST_UPDATED, emb)
     finally:
         d.delete()
         s.delete()
开发者ID:kcaylor,项目名称:eve-mongoengine,代码行数:17,代码来源:test_get.py

示例9: test_datasource_projection

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
 def test_datasource_projection(self):
     SETTINGS['DOMAIN'] = {'eve-mongoengine':{}}
     app = Eve(settings=SETTINGS)
     app.debug = True
     ext = EveMongoengine(app)
     ext.add_model(SimpleDoc, datasource={'projection': {'b': 0}})
     client = app.test_client()
     d = SimpleDoc(a='Tom', b=223).save()
     response = client.get('/simpledoc/%s' % d.id)
     try:
         self.assertNotIn('b', response.get_json().keys())
         # here it should return the field, but sadly, does not
         #response = client.get('/simpledoc/%s?projection={"b":1}' % d.id)
         #self.assertIn('b', response.get_json().keys())
     finally:
         d.delete()
开发者ID:Algorhythm-IO,项目名称:eve-mongoengine,代码行数:18,代码来源:test_get.py

示例10: test_delete_subresource

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
    def test_delete_subresource(self):
        # more subresources -> delete them all
        s = SimpleDoc(a="James Bond", b=7).save()
        c1 = ComplexDoc(l=['p', 'q', 'r'], n=1, r=s).save()
        c2 = ComplexDoc(l=['s', 't', 'u'], n=2, r=s).save()

        # delete subresources
        del_url = '/simpledoc/%s/complexdoc' % s.id
        response = self.client.delete(del_url)
        self.assertEqual(response.status_code, 200)
        # check, if really deleted
        response = self.client.get('/simpledoc/%s/complexdoc' % s.id)
        json_data = response.get_json()
        self.assertEqual(json_data[config.ITEMS], [])
        # cleanup
        s.delete()
开发者ID:Arable,项目名称:eve-mongoengine,代码行数:18,代码来源:test_delete.py

示例11: test_delete_subresource_item

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
    def test_delete_subresource_item(self):
        # create new resource and subresource
        s = SimpleDoc(a="Answer to everything", b=42).save()
        d = ComplexDoc(l=['a', 'b'], n=999, r=s).save()

        response = self.client.get('/simpledoc/%s/complexdoc/%s' % (s.id, d.id))
        etag = response.get_json()[config.ETAG]
        headers = [('If-Match', etag)]

        # delete subresource
        del_url = '/simpledoc/%s/complexdoc/%s' % (s.id, d.id)
        response = self.client.delete(del_url, headers=headers)
        self.assertEqual(response.status_code, 200)
        # check, if really deleted
        response = self.client.get('/simpledoc/%s/complexdoc/%s' % (s.id, d.id))
        self.assertEqual(response.status_code, 404)
        s.delete()
开发者ID:Arable,项目名称:eve-mongoengine,代码行数:19,代码来源:test_delete.py

示例12: test_find_all_default_sort

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
    def test_find_all_default_sort(self):
        s = self.app.config['DOMAIN']['simpledoc']['datasource']
        d = SimpleDoc(a='abz', b=3).save()
        d2 = SimpleDoc(a='abc', b=-7).save()

        # set default sort to 'b', desc.
        if 'default_sort' in s:
            default = s['default_sort']
        else:
            default = []
        s['default_sort'] = [('b', -1)]
        self.app.set_defaults()
        response = self.client.get('/simpledoc')
        json_data = response.get_json()
        real = [x['b'] for x in json_data['_items']]
        expected = [3, -7]
        try:
            self.assertListEqual(real, expected)
        except Exception as e:
            # reset
            s['default_sort'] = default
            d.delete()
            d2.delete()
            raise

        # set default sort to 'b', asc.
        s['default_sort'] = [('b', 1)]
        self.app.set_defaults()
        response = self.client.get('/simpledoc')
        json_data = response.get_json()
        real = [x['b'] for x in json_data['_items']]
        expected = [-7, 3]
        try:        
            self.assertListEqual(real, expected)
        finally:
            # reset
            s['default_sort'] = default
            d.delete()
            d2.delete()
开发者ID:kcaylor,项目名称:eve-mongoengine,代码行数:41,代码来源:test_get.py

示例13: test_find_all_sorting

# 需要导入模块: from tests import SimpleDoc [as 别名]
# 或者: from tests.SimpleDoc import delete [as 别名]
    def test_find_all_sorting(self):
        d = SimpleDoc(a='abz', b=3).save()
        d2 = SimpleDoc(a='abc', b=-7).save()
        response = self.client.get('/simpledoc?sort={"a":1}')
        json_data = response.get_json()
        real = [x['a'] for x in json_data['_items']]
        expected = ['abc', 'abz']
        try:
            self.assertListEqual(real, expected)
        except Exception as e:
            # reset
            d.delete()
            d2.delete()
            raise

        response = self.client.get('/simpledoc?sort={"b":-1}')
        json_data = response.get_json()
        real = [x['b'] for x in json_data['_items']]
        expected = [3, -7]
        try:
            self.assertListEqual(real, expected)
        finally:
            d.delete()
            d2.delete()
开发者ID:kcaylor,项目名称:eve-mongoengine,代码行数:26,代码来源:test_get.py


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