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


Python tests.SimpleDoc类代码示例

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


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

示例1: test_patch_subresource

    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,代码行数:27,代码来源:test_patch.py

示例2: test_find_all_projection

 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,代码行数:9,代码来源:test_get.py

示例3: test_find_one

 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,代码行数:11,代码来源:test_get.py

示例4: wrapper

 def wrapper(self):
     response = self.client.post('/simpledoc/',
                                 data='{"a": "jimmy", "b": 23}',
                                 content_type='application/json')
     json_data = response.get_json()
     self.url = '/simpledoc/%s' % json_data[config.ID_FIELD]
     response = self.client.get(self.url).get_json()
     self.etag = response[config.ETAG]
     self._id = response[config.ID_FIELD]
     self.updated = response[config.LAST_UPDATED]
     f(self)
     SimpleDoc.objects().delete()
开发者ID:Arable,项目名称:eve-mongoengine,代码行数:12,代码来源:test_patch.py

示例5: test_reference_field

 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,代码行数:13,代码来源:test_fields.py

示例6: test_find_one_projection

 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,代码行数:13,代码来源:test_get.py

示例7: test_patch_overwrite_subset

 def test_patch_overwrite_subset(self):
     # test what was really updated
     raw = SimpleDoc._get_collection().find_one({"_id": ObjectId(self._id)})
     response = self.do_patch(data='{"a": "greg"}')
     self.assert_correct_etag(response)
     expected = dict(raw)
     expected['a'] = 'greg'
     real = SimpleDoc._get_collection().find_one({"_id": ObjectId(self._id)})
     self.assertDictEqual(real, expected)
     # test if GET response returns corrent response
     response = self.client.get(self.url).get_json()
     self.assertIn('a', response)
     self.assertEqual(response['a'], "greg")
     self.assertIn('b', response)
     self.assertEqual(response['b'], 23)
开发者ID:satyanani40,项目名称:eve-mongoengine,代码行数:15,代码来源:test_patch.py

示例8: test_find_all

 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,代码行数:15,代码来源:test_get.py

示例9: test_embedded_resource_serialization

 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,代码行数:15,代码来源:test_get.py

示例10: test_datasource_projection

 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,代码行数:16,代码来源:test_get.py

示例11: test_delete_subresource

    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,代码行数:16,代码来源:test_delete.py

示例12: test_delete_subresource_item

    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,代码行数:17,代码来源:test_delete.py

示例13: test_find_all_default_sort

    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,代码行数:39,代码来源:test_get.py

示例14: test_find_all_sorting

    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,代码行数:24,代码来源:test_get.py

示例15: test_find_all_filtering

 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,代码行数:11,代码来源:test_get.py


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