本文整理汇总了Python中cloudant.document.Document.put_attachment方法的典型用法代码示例。如果您正苦于以下问题:Python Document.put_attachment方法的具体用法?Python Document.put_attachment怎么用?Python Document.put_attachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudant.document.Document
的用法示例。
在下文中一共展示了Document.put_attachment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import put_attachment [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
示例2: test_attachment_put
# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import put_attachment [as 别名]
def test_attachment_put(self):
"""
_test_attachment_put_
"""
doc = Document(self.database, "DUCKUMENT")
doc_id = 'DUCKUMENT'
attachment = 'herpderp.txt'
data = '/path/to/herpderp.txt'
mock_get = mock.Mock()
mock_get.raise_for_status = mock.Mock()
mock_get.status_code = 200
mock_get.json = mock.Mock()
mock_get.json.return_value = {'_id': doc_id, '_rev': '1-abc'}
self.mock_session.get.return_value = mock_get
mock_put = mock.Mock()
mock_put.raise_for_status = mock.Mock()
mock_put.status_code = 201
mock_put.json = mock.Mock()
mock_put.json.return_value = {'id': doc_id, 'rev': '2-def', 'ok': True}
self.mock_session.put.return_value = mock_put
resp = doc.put_attachment(
attachment,
content_type='text/plain',
data=data
)
self.assertEqual(resp['id'], doc_id)
self.assertTrue(self.mock_session.get.called)
self.assertTrue(self.mock_session.put.called)