本文整理汇总了Python中cloudant.document.Document.get方法的典型用法代码示例。如果您正苦于以下问题:Python Document.get方法的具体用法?Python Document.get怎么用?Python Document.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudant.document.Document
的用法示例。
在下文中一共展示了Document.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_document_with_docid_encoded_url
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [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-'))
示例2: test_create_document_with_docid
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [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-'))
示例3: test_create_replication
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [as 别名]
def test_create_replication(self):
"""
Test that the replication document gets created and that the
replication is successful.
"""
self.populate_db_with_documents(3)
repl_id = 'test-repl-{}'.format(unicode_(uuid.uuid4()))
repl_doc = self.replicator.create_replication(
self.db,
self.target_db,
repl_id
)
self.replication_ids.append(repl_id)
# Test that the replication document was created
expected_keys = ['_id', '_rev', 'source', 'target', 'user_ctx']
# If Admin Party mode then user_ctx will not be in the key list
if self.client.admin_party:
expected_keys.pop()
self.assertTrue(all(x in list(repl_doc.keys()) for x in expected_keys))
self.assertEqual(repl_doc['_id'], repl_id)
self.assertTrue(repl_doc['_rev'].startswith('1-'))
# Now that we know that the replication document was created,
# check that the replication occurred.
repl_doc = Document(self.replicator.database, repl_id)
repl_doc.fetch()
if repl_doc.get('_replication_state') not in ('completed', 'error'):
changes = self.replicator.database.changes(
feed='continuous',
heartbeat=1000)
beats = 0
for change in changes:
if beats == 300:
changes.stop()
if not change:
beats += 1
continue
elif change.get('id') == repl_id:
beats = 0
repl_doc = Document(self.replicator.database, repl_id)
repl_doc.fetch()
if repl_doc.get('_replication_state') in ('completed', 'error'):
changes.stop()
self.assertEqual(repl_doc.get('_replication_state'), 'completed')
self.assertEqual(self.db.all_docs(), self.target_db.all_docs())
self.assertTrue(
all(x in self.target_db.keys(True) for x in [
'julia000',
'julia001',
'julia002'
])
)
示例4: test_constructor_with_docid
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [as 别名]
def test_constructor_with_docid(self):
"""
Test instantiating a Document providing an id
"""
doc = Document(self.db, 'julia006')
self.assertIsInstance(doc, Document)
self.assertEqual(doc.r_session, self.db.r_session)
self.assertEqual(doc.get('_id'), 'julia006')
示例5: test_removing_id
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [as 别名]
def test_removing_id(self):
"""
Ensure that proper processing occurs when removing the _id
"""
doc = Document(self.db)
doc['_id'] = 'julia006'
del doc['_id']
self.assertIsNone(doc.get('_id'))
self.assertEqual(doc._document_id, None)
示例6: test_constructor_without_docid
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [as 别名]
def test_constructor_without_docid(self):
"""
Test instantiating a Document without providing an id
"""
doc = Document(self.db)
self.assertIsInstance(doc, Document)
self.assertEqual(doc.r_session, self.db.r_session)
self.assertIsNone(doc.get('_id'))
self.assertIsNone(doc.document_url)
示例7: test_setting_id
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [as 别名]
def test_setting_id(self):
"""
Ensure that proper processing occurs when setting the _id
"""
doc = Document(self.db)
self.assertIsNone(doc.get('_id'))
self.assertEqual(doc._document_id, None)
doc['_id'] = 'julia006'
self.assertEqual(doc['_id'], 'julia006')
self.assertEqual(doc._document_id, 'julia006')
示例8: test_create_replication
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [as 别名]
def test_create_replication(self):
"""
Test that the replication document gets created and that the
replication is successful.
"""
self.populate_db_with_documents(3)
repl_id = 'test-repl-{}'.format(unicode(uuid.uuid4()))
repl_doc = self.replicator.create_replication(
self.db,
self.target_db,
repl_id
)
self.replication_ids.append(repl_id)
# Test that the replication document was created
expected_keys = ['_id', '_rev', 'source', 'target', 'user_ctx']
self.assertTrue(all(x in repl_doc.keys() for x in expected_keys))
self.assertEqual(repl_doc['_id'], repl_id)
self.assertTrue(repl_doc['_rev'].startswith('1-'))
# Now that we know that the replication document was created,
# check that the replication occurred.
repl_doc = Document(self.replicator.database, repl_id)
repl_doc.fetch()
if not (repl_doc.get('_replication_state')
in ('completed', 'error')):
for change in self.replicator.database.changes():
if change.get('id') == repl_id:
repl_doc = Document(self.replicator.database, repl_id)
repl_doc.fetch()
if (repl_doc.get('_replication_state')
in ('completed', 'error')):
break
self.assertEqual(repl_doc['_replication_state'], 'completed')
self.assertEqual(self.db.all_docs(), self.target_db.all_docs())
self.assertTrue(
all(x in self.target_db.keys(True) for x in [
'julia000',
'julia001',
'julia002'
])
)
示例9: test_create_document_using_save
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [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_timeout_in_create_replication
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get [as 别名]
def test_timeout_in_create_replication(self):
"""
Test that a read timeout exception is thrown when creating a
replicator with a timeout value of 500 ms.
"""
# Setup client with a timeout
self.set_up_client(auto_connect=True, timeout=.5)
self.db = self.client[self.test_target_dbname]
self.target_db = self.client[self.test_dbname]
# Construct a replicator with the updated client
self.replicator = Replicator(self.client)
repl_id = 'test-repl-{}'.format(unicode_(uuid.uuid4()))
repl_doc = self.replicator.create_replication(
self.db,
self.target_db,
repl_id
)
self.replication_ids.append(repl_id)
# Test that the replication document was created
expected_keys = ['_id', '_rev', 'source', 'target', 'user_ctx']
# If Admin Party mode then user_ctx will not be in the key list
if self.client.admin_party:
expected_keys.pop()
self.assertTrue(all(x in list(repl_doc.keys()) for x in expected_keys))
self.assertEqual(repl_doc['_id'], repl_id)
self.assertTrue(repl_doc['_rev'].startswith('1-'))
# Now that we know that the replication document was created,
# check that the replication timed out.
repl_doc = Document(self.replicator.database, repl_id)
repl_doc.fetch()
if repl_doc.get('_replication_state') not in ('completed', 'error'):
# assert that a connection error is thrown because the read timed out
with self.assertRaises(ConnectionError) as cm:
changes = self.replicator.database.changes(
feed='continuous')
for change in changes:
continue
self.assertTrue(str(cm.exception).endswith('Read timed out.'))