本文整理汇总了Python中cloudant.document.Document.field_set方法的典型用法代码示例。如果您正苦于以下问题:Python Document.field_set方法的具体用法?Python Document.field_set怎么用?Python Document.field_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudant.document.Document
的用法示例。
在下文中一共展示了Document.field_set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_list_field_remove_failure
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import field_set [as 别名]
def test_list_field_remove_failure(self):
"""
Test the static helper method to remove from a list
field errors as expected.
"""
doc = Document(self.db)
doc.field_set(doc, 'name', 'julia')
try:
doc.list_field_remove(doc, 'name', 'julia')
self.fail('Above statement should raise an Exception')
except CloudantException, err:
self.assertEqual(str(err), 'The field name is not a list.')
示例2: test_update_actions
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import field_set [as 别名]
def test_update_actions(self):
"""
_test_update_actions_
"""
doc = {
"foo": "bar",
"baz": [1, 2, 3, 4, 5]
}
c_doc = Document(self.database, "HOWARD")
c_doc.list_field_append(doc, "baz", 10)
c_doc.list_field_remove(doc, "baz", 3)
c_doc.field_set(doc, "foo", "qux")
self.assertTrue(10 in doc['baz'])
self.assertFalse(3 in doc['baz'])
self.assertEqual(doc['foo'], "qux")
示例3: test_field_set_and_replace
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import field_set [as 别名]
def test_field_set_and_replace(self):
"""
Test the static helper method to set or replace a field value.
"""
doc = Document(self.db)
self.assertEqual(doc, {})
doc.field_set(doc, 'name', 'julia')
self.assertEqual(doc, {'name': 'julia'})
doc.field_set(doc, 'name', 'jules')
self.assertEqual(doc, {'name': 'jules'})
doc.field_set(doc, 'pets', ['cat', 'dog'])
self.assertEqual(doc, {'name': 'jules', 'pets': ['cat', 'dog']})
doc.field_set(doc, 'pets', None)
self.assertEqual(doc, {'name': 'jules'})