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


Python Document.create方法代码示例

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


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

示例1: test_document_exists

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_document_exists(self):
     """
     Test whether a document exists remotely
     """
     doc = Document(self.db)
     self.assertFalse(doc.exists())
     doc['_id'] = 'julia006'
     self.assertFalse(doc.exists())
     doc.create()
     self.assertTrue(doc.exists())
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:12,代码来源:document_tests.py

示例2: test_fetch_existing_document_with_docid

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_fetch_existing_document_with_docid(self):
     """
     Test fetching document content from an existing document
     """
     doc = Document(self.db, 'julia006')
     doc['name'] = 'julia'
     doc['age'] = 6
     doc.create()
     new_doc = Document(self.db, 'julia006')
     new_doc.fetch()
     self.assertEqual(new_doc, doc)
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:13,代码来源:document_tests.py

示例3: test_create_existing_document

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_create_existing_document(self):
     """
     Test creating an already existing document
     """
     doc = Document(self.db, 'julia006')
     doc.create()
     try:
         doc.create()
         self.fail('Above statement should raise an Exception')
     except requests.HTTPError as err:
         self.assertEqual(err.response.status_code, 409)
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:13,代码来源:document_tests.py

示例4: test_document_exists

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_document_exists(self):
     """
     Tests that the result of True is expected when the document exists,
     and False is expected when the document is nonexistent remotely.
     """
     doc = Document(self.db)
     self.assertFalse(doc.exists())
     doc['_id'] = 'julia006'
     self.assertFalse(doc.exists())
     doc.create()
     self.assertTrue(doc.exists())
开发者ID:cloudant,项目名称:python-cloudant,代码行数:13,代码来源:document_tests.py

示例5: test_fetch_existing_document_with_docid_encoded_url

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_fetch_existing_document_with_docid_encoded_url(self):
     """
     Test fetching document content from an existing document where the
     document id requires an encoded url
     """
     doc = Document(self.db, 'http://example.com')
     doc['name'] = 'julia'
     doc['age'] = 6
     doc.create()
     new_doc = Document(self.db, 'http://example.com')
     new_doc.fetch()
     self.assertEqual(new_doc, doc)
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:14,代码来源:document_tests.py

示例6: test_create_document_with_docid_encoded_url

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_create_document_with_docid_encoded_url(self):
     """
     Test creating a document providing an id that has an encoded url
     """
     doc = Document(self.db, 'http://example.com')
     doc['name'] = 'julia'
     doc['age'] = 6
     self.assertFalse(doc.exists())
     self.assertIsNone(doc.get('_rev'))
     doc.create()
     self.assertTrue(doc.exists())
     self.assertTrue(doc.get('_rev').startswith('1-'))
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:14,代码来源:document_tests.py

示例7: test_create_document_with_docid

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_create_document_with_docid(self):
     """
     Test creating a document providing an id
     """
     doc = Document(self.db, 'julia006')
     doc['name'] = 'julia'
     doc['age'] = 6
     self.assertFalse(doc.exists())
     self.assertIsNone(doc.get('_rev'))
     doc.create()
     self.assertTrue(doc.exists())
     self.assertTrue(doc.get('_rev').startswith('1-'))
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:14,代码来源:document_tests.py

示例8: test_create_existing_document

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_create_existing_document(self):
     """
     Test creating an already existing document
     """
     doc = Document(self.db, 'julia006')
     doc.create()
     with self.assertRaises(requests.HTTPError) as cm:
         doc.create()
     err = cm.exception
     self.assertEqual(
         err.response.status_code,
         409
     )
开发者ID:cloudant,项目名称:python-cloudant,代码行数:15,代码来源:document_tests.py

示例9: test_delete_document_success_with_encoded_url

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_delete_document_success_with_encoded_url(self):
     """
     Test that we can remove a document from the remote
     database successfully when the document id requires an encoded url.
     """
     doc = Document(self.db, 'http://example.com')
     doc['name'] = 'julia'
     doc['age'] = 6
     doc['pets'] = ['cat', 'dog']
     doc.create()
     self.assertTrue(doc.exists())
     doc.delete()
     self.assertFalse(doc.exists())
     self.assertEqual(doc, {'_id': 'http://example.com'})
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:16,代码来源:document_tests.py

示例10: test_delete_document_success

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_delete_document_success(self):
     """
     Test that we can remove a document from the remote
     database successfully.
     """
     doc = Document(self.db, 'julia006')
     doc['name'] = 'julia'
     doc['age'] = 6
     doc['pets'] = ['cat', 'dog']
     doc.create()
     self.assertTrue(doc.exists())
     doc.delete()
     self.assertFalse(doc.exists())
     self.assertEqual(doc, {'_id': 'julia006'})
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:16,代码来源:document_tests.py

示例11: post

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
    def post(self):
        body = load_body(scrap_schema)
        db = get_scraps_db()

        doc = Document(db)
        data = scrap_schema.dump(body).data

        body = data.pop('body')
        content_type = data.pop('content_type')

        doc.update(**data)
        doc.create()
        doc.put_attachment('body', content_type, body)
        return doc
开发者ID:aqualove,项目名称:api,代码行数:16,代码来源:resources.py

示例12: test_update_field

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_update_field(self):
     """
     Test that we can update a single field remotely using the
     update_field method.
     """
     doc = Document(self.db, 'julia006')
     doc['name'] = 'julia'
     doc['age'] = 6
     doc['pets'] = ['cat', 'dog']
     doc.create()
     self.assertTrue(doc['_rev'].startswith('1-'))
     self.assertEqual(doc['pets'], ['cat', 'dog'])
     doc.update_field(doc.list_field_append, 'pets', 'fish')
     self.assertTrue(doc['_rev'].startswith('2-'))
     self.assertEqual(doc['pets'], ['cat', 'dog', 'fish'])
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:17,代码来源:document_tests.py

示例13: test_document_context_manager

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
 def test_document_context_manager(self):
     """
     Test that the __enter__ and __exit__ methods perform as expected
     when initiated through a document context manager.
     """
     new_doc = Document(self.db, 'julia006')
     new_doc.create()
     self.assertTrue(new_doc.exists())
     del new_doc
     with Document(self.db, 'julia006') as doc:
         self.assertTrue(all(x in list(doc.keys()) for x in ['_id', '_rev']))
         self.assertTrue(doc['_rev'].startswith('1-'))
         doc['name'] = 'julia'
         doc['age'] = 6
     self.assertTrue(doc['_rev'].startswith('2-'))
     self.assertEqual(self.db['julia006'], doc)
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:18,代码来源:document_tests.py

示例14: test_document_crud

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import create [as 别名]
    def test_document_crud(self):
        """test basic crud operations with mocked backend"""
        doc = Document(self.database, "DUCKUMENT")
        # exists
        mock_resp = mock.Mock()
        mock_resp.status_code = 200
        self.mock_session.get.return_value = mock_resp
        self.assertTrue(doc.exists())
        self.assertTrue(self.mock_session.get.called)
        self.mock_session.get.assert_has_calls(
            [ mock.call('https://bob.cloudant.com/unittest/DUCKUMENT') ]
        )
        self.mock_session.get.reset_mock()

        # create
        mock_resp = mock.Mock()
        mock_resp.raise_for_status = mock.Mock()
        mock_resp.status_code = 200
        mock_resp.json = mock.Mock()
        mock_resp.json.return_value = {'id': 'DUCKUMENT', 'rev': 'DUCK2'}
        self.mock_session.post.return_value = mock_resp

        doc.create()
        self.assertEqual(doc['_rev'], 'DUCK2')
        self.assertEqual(doc['_id'], 'DUCKUMENT')
        self.assertTrue(self.mock_session.post.called)
        self.mock_session.post.reset_mock()

        # fetch
        mock_resp = mock.Mock()
        mock_resp.status_code = 200
        mock_resp.raise_for_status = mock.Mock()
        mock_resp.json = mock.Mock()
        mock_resp.json.return_value = {
            '_id': 'DUCKUMENT', '_rev': 'DUCK2',
            'herp': 'HERP', 'derp': 'DERP'
        }
        self.mock_session.get.return_value = mock_resp
        doc.fetch()
        self.assertTrue('herp' in doc)
        self.assertTrue('derp' in doc)
        self.assertEqual(doc['herp'], 'HERP')
        self.assertEqual(doc['derp'], 'DERP')

        self.assertTrue(self.mock_session.get.called)
        self.mock_session.get.assert_has_calls(
            [ mock.call('https://bob.cloudant.com/unittest/DUCKUMENT') ]
        )
        self.mock_session.get.reset_mock()

        # save
        mock_put_resp = mock.Mock()
        mock_put_resp.status_code = 200
        mock_put_resp.raise_for_status = mock.Mock()
        mock_put_resp.json = mock.Mock()
        mock_put_resp.json.return_value = {'id': 'DUCKUMENT', 'rev': 'DUCK3'}
        self.mock_session.put.return_value = mock_put_resp
        mock_get_resp = mock.Mock()
        mock_get_resp.status_code = 200
        self.mock_session.get.return_value = mock_get_resp

        doc.save()
        self.assertEqual(doc['_rev'], 'DUCK3')
        self.assertEqual(doc['_id'], 'DUCKUMENT')
        self.assertTrue(self.mock_session.get.called)
        self.assertTrue(self.mock_session.put.called)

        self.mock_session.get.assert_has_calls(
            [ mock.call('https://bob.cloudant.com/unittest/DUCKUMENT') ]
        )
        self.mock_session.put.assert_has_calls(
            [ mock.call(
                  'https://bob.cloudant.com/unittest/DUCKUMENT',
                  headers={'Content-Type': 'application/json'},
                  data=mock.ANY
            ) ]
        )
        self.mock_session.get.reset_mock()
        self.mock_session.put.reset_mock()

        # delete
        mock_resp = mock.Mock()
        mock_resp.status_code = 200
        mock_resp.raise_for_status = mock.Mock()
        self.mock_session.delete.return_value = mock_resp
        doc.delete()

        self.assertTrue(self.mock_session.delete.called)
        self.mock_session.delete.assert_has_calls(
            [ mock.call(
                  'https://bob.cloudant.com/unittest/DUCKUMENT',
                  params={'rev': 'DUCK3'}
            ) ]
        )
        self.mock_session.delete.reset_mock()
        # test delete with no rev explodes as expected
        self.assertRaises(CloudantException, doc.delete)
开发者ID:iblis17,项目名称:python-cloudant,代码行数:99,代码来源:document_test.py


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