def test_upload(self):
self.client.post.return_value = mock_upload_response('/files/content',
httplib.CREATED,
None,
'files', 'POST_response.json')
file_name = 'upload.jpg'
file_path = path.join(path.dirname(__file__), '..', 'fixtures', 'files', file_name)
folder_id = 'folder-id'
@mock.patch('orangecloud_client.files.guess_type', return_value=('image/jpeg', 'binary'))
@mock.patch('__builtin__.open', spec=open, return_value=MockFile())
@mock.patch('orangecloud_client.files.MultipartEncoder', return_value=mock.Mock())
def fire_test(mock_multipart_encoder, mock_open, _):
data = mock_multipart_encoder()
data.content_type = 'upload content type'
response_file = self.files.upload(file_path, folder_id)
self.client.post.assert_called_with(self.client.post.return_value.url,
data=data,
headers={'Content-Type': data.content_type})
self.assertEqual('file-id', response_file.fileId)
self.assertEqual('file-name', response_file.fileName)
fire_test()
评论列表
文章目录