本文整理汇总了Python中cloudant.document.Document.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Document.exists方法的具体用法?Python Document.exists怎么用?Python Document.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudant.document.Document
的用法示例。
在下文中一共展示了Document.exists方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_document_exists
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [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())
示例2: test_document_exists
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [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())
示例3: test_create_document_with_docid_encoded_url
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [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-'))
示例4: test_create_document_with_docid
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [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-'))
示例5: test_delete_document_success_with_encoded_url
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [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'})
示例6: test_delete_document_success
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [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'})
示例7: test_document_exists_raises_httperror
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [as 别名]
def test_document_exists_raises_httperror(self):
"""
Test document exists raises an HTTPError.
"""
# Mock HTTPError when running against CouchDB and Cloudant
resp = requests.Response()
resp.status_code = 400
self.client.r_session.head = mock.Mock(return_value=resp)
doc = Document(self.db)
doc['_id'] = 'julia006'
with self.assertRaises(requests.HTTPError) as cm:
doc.exists()
err = cm.exception
self.assertEqual(err.response.status_code, 400)
self.client.r_session.head.assert_called_with(doc.document_url)
示例8: doc_exist
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [as 别名]
def doc_exist(self, docid):
"""Test if document exists in a database
@param docid: str, document id
@return: boolean, True if document exist
"""
doc = Document(self.cloudant_database, docid)
return doc.exists()
示例9: test_create_document_using_save
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [as 别名]
def test_create_document_using_save(self):
"""
Test that save functionality works. If a document does
not exist remotely then create it.
"""
doc = Document(self.db, 'julia006')
doc['name'] = 'julia'
doc['age'] = 6
self.assertIsNone(doc.get('_rev'))
doc.save()
self.assertTrue(doc.exists())
self.assertTrue(doc['_rev'].startswith('1-'))
remote_doc = Document(self.db, 'julia006')
remote_doc.fetch()
self.assertEqual(remote_doc, doc)
示例10: test_document_context_manager
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [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)
示例11: test_document_crud
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import exists [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)