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