本文整理汇总了Python中cloudant.document.Document._encoder方法的典型用法代码示例。如果您正苦于以下问题:Python Document._encoder方法的具体用法?Python Document._encoder怎么用?Python Document._encoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudant.document.Document
的用法示例。
在下文中一共展示了Document._encoder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_document_edit_context
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import _encoder [as 别名]
def test_document_edit_context(self):
"""test the editing context"""
mock_fetch_resp = mock.Mock()
mock_fetch_resp.status_code = 200
mock_fetch_resp.raise_for_status = mock.Mock()
mock_fetch_resp.json = mock.Mock()
mock_fetch_resp.json.return_value = {
'herp': 'HERP', 'derp': 'DERP'
}
self.mock_session.get.return_value = mock_fetch_resp
mock_save_resp = mock.Mock()
mock_save_resp.status_code = 200
mock_save_resp.raise_for_status = mock.Mock()
mock_save_resp.json = mock.Mock()
mock_save_resp.json.return_value = {'id': "ID", "rev": "updated"}
self.mock_session.put.return_value = mock_save_resp
mock_encode = mock.Mock()
mock_encode.encode = mock.Mock()
doc = Document(self.database, "DUCKUMENT")
doc._encoder = mock.Mock()
doc._encoder.return_value = mock_encode
with doc as d:
d['new_field'] = "NARP"
self.assertTrue(self.mock_session.get.called)
self.assertTrue(self.mock_session.put.called)
self.assertTrue(mock_encode.encode.called)
payload = mock_encode.encode.call_args[0][0]
for k, v in payload.iteritems():
self.assertTrue(k in doc)
self.assertEqual(doc[k], v)