def test_copy_item(self):
new_parent = resources.ItemReference.build(id='123abc', path='/foo/bar')
new_name = '456.doc'
with requests_mock.Mocker() as mock:
def callback(request, context):
# Verify that necessary headers are properly set.
headers = request.headers
self.assertIn('Content-Type', headers)
self.assertEqual('application/json', headers['Content-Type'])
self.assertIn('Prefer', headers)
self.assertEqual('respond-async', headers['Prefer'])
# Verify that request body is correct.
body = request.json()
self.assertEqual(new_name, body['name'])
self.assertDictEqual(new_parent.data, body['parentReference'])
# Set response.
context.status_code = codes.accepted
context.headers['Location'] = 'https://foo.bar/monitor'
return None
mock.post(self.drive.get_item_uri(None, '123') + ':/action.copy', content=callback)
session = self.drive.copy_item(new_parent, item_path='123', new_name=new_name)
self.assertIsInstance(session, resources.AsyncCopySession)
评论列表
文章目录