def testItemCopy(self):
    origItem = self._createItem(self.publicFolder['_id'], 'test_for_copy', 'fake description', self.users[0])
    metadata = {'foo': 'value1', 'test': 2}
    resp = self.request(path=('/item/%s/metadata' % origItem['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    self.assertStatusOk(resp)
    self._testUploadFileToItem(origItem, 'file_1', self.users[0], 'foobar')
    self._testUploadFileToItem(origItem, 'file_2', self.users[0], 'foobz')
    params = {'parentType': 'item', 'parentId': origItem['_id'], 'name': 'link_file', 'linkUrl': 'http://www.google.com'}
    resp = self.request(path='/file', method='POST', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    params = {'name': 'copied_item'}
    resp = self.request(path=('/item/%s/copy' % origItem['_id']), method='POST', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json['size'], 11)
    self.request(path=('/item/%s' % resp.json['_id']), user=self.users[0], type='application/json')
    self.assertStatusOk(resp)
    newItem = resp.json
    self.assertEqual(newItem['name'], 'copied_item')
    self.assertEqual(newItem['meta']['foo'], metadata['foo'])
    self.assertEqual(newItem['meta']['test'], metadata['test'])
    resp = self.request(path=('/item/%s/files' % newItem['_id']), method='GET', user=self.users[0])
    self.assertStatusOk(resp)
    newFiles = resp.json
    self.assertEqual(newFiles[0]['name'], 'file_1')
    self.assertEqual(newFiles[1]['name'], 'file_2')
    self.assertEqual(newFiles[2]['name'], 'link_file')
    self.assertEqual(newFiles[0]['size'], 6)
    self.assertEqual(newFiles[1]['size'], 5)
    self._testDownloadMultiFileItem(newItem, self.users[0], {'file_1': 'foobar', 'file_2': 'foobz', 'link_file': 'http://www.google.com'})
    resp = self.request(path='/item', method='GET', user=self.users[0], params={'folderId': self.publicFolder['_id'], 'text': 'test_for_copy'})
    self.assertStatusOk(resp)
    self.assertEqual(origItem['_id'], resp.json[0]['_id'])
    resp = self.request(path='/item', method='GET', user=self.users[0], params={'folderId': self.publicFolder['_id'], 'text': 'copied_item'})
    self.assertStatusOk(resp)
    self.assertEqual(newItem['_id'], resp.json[0]['_id'])
    self.assertEqual(newItem['copyOfItem'], origItem['_id'])
    resp = self.request(path=('/item/%s/files' % origItem['_id']), method='GET', user=self.users[0])
    self.assertStatusOk(resp)
    origFiles = resp.json
    self._testDownloadMultiFileItem(origItem, self.users[0], {'file_1': 'foobar', 'file_2': 'foobz', 'link_file': 'http://www.google.com'})
    for (index, file) in enumerate(origFiles):
        self.assertNotEqual(origFiles[index]['_id'], newFiles[index]['_id'])
def testItemCopy(self):
    origItem = self._createItem(self.publicFolder['_id'], 'test_for_copy', 'fake description', self.users[0])
    metadata = {'foo': 'value1', 'test': 2}
    resp = self.request(path=('/item/%s/metadata' % origItem['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    self.assertStatusOk(resp)
    self._testUploadFileToItem(origItem, 'file_1', self.users[0], 'foobar')
    self._testUploadFileToItem(origItem, 'file_2', self.users[0], 'foobz')
    params = {'parentType': 'item', 'parentId': origItem['_id'], 'name': 'link_file', 'linkUrl': 'http://www.google.com'}
    resp = self.request(path='/file', method='POST', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    params = {'name': 'copied_item'}
    resp = self.request(path=('/item/%s/copy' % origItem['_id']), method='POST', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json['size'], 11)
    self.request(path=('/item/%s' % resp.json['_id']), user=self.users[0], type='application/json')
    self.assertStatusOk(resp)
    newItem = resp.json
    self.assertEqual(newItem['name'], 'copied_item')
    self.assertEqual(newItem['meta']['foo'], metadata['foo'])
    self.assertEqual(newItem['meta']['test'], metadata['test'])
    resp = self.request(path=('/item/%s/files' % newItem['_id']), method='GET', user=self.users[0])
    self.assertStatusOk(resp)
    newFiles = resp.json
    self.assertEqual(newFiles[0]['name'], 'file_1')
    self.assertEqual(newFiles[1]['name'], 'file_2')
    self.assertEqual(newFiles[2]['name'], 'link_file')
    self.assertEqual(newFiles[0]['size'], 6)
    self.assertEqual(newFiles[1]['size'], 5)
    self._testDownloadMultiFileItem(newItem, self.users[0], {'file_1': 'foobar', 'file_2': 'foobz', 'link_file': 'http://www.google.com'})
    resp = self.request(path='/item', method='GET', user=self.users[0], params={'folderId': self.publicFolder['_id'], 'text': 'test_for_copy'})
    self.assertStatusOk(resp)
    self.assertEqual(origItem['_id'], resp.json[0]['_id'])
    resp = self.request(path='/item', method='GET', user=self.users[0], params={'folderId': self.publicFolder['_id'], 'text': 'copied_item'})
    self.assertStatusOk(resp)
    self.assertEqual(newItem['_id'], resp.json[0]['_id'])
    self.assertEqual(newItem['copyOfItem'], origItem['_id'])
    resp = self.request(path=('/item/%s/files' % origItem['_id']), method='GET', user=self.users[0])
    self.assertStatusOk(resp)
    origFiles = resp.json
    self._testDownloadMultiFileItem(origItem, self.users[0], {'file_1': 'foobar', 'file_2': 'foobz', 'link_file': 'http://www.google.com'})
    for (index, file) in enumerate(origFiles):
        self.assertNotEqual(origFiles[index]['_id'], newFiles[index]['_id'])