def testItemCrud(self):
    '\n        Test Create, Read, Update, and Delete of items.\n        '
    self.ensureRequiredParams(path='/item', method='POST', required=('folderId',), user=self.users[1])
    params = {'name': ' ', 'description': ' a description ', 'folderId': self.publicFolder['_id']}
    resp = self.request(path='/item', method='POST', params=params, user=self.users[1])
    self.assertStatus(resp, 403)
    resp = self.request(path='/item', method='POST', params=params, user=self.users[0])
    self.assertValidationError(resp, 'name')
    params['name'] = ' my item name'
    params['folderId'] = self.privateFolder['_id']
    resp = self.request(path='/item', method='POST', params=params, user=self.users[0])
    self.assertStatusOk(resp)
    item = resp.json
    self.assertEqual(item['name'], params['name'].strip())
    self.assertEqual(item['description'], params['description'].strip())
    params = {'folderId': self.privateFolder['_id']}
    resp = self.request(path='/item', method='GET', user=self.users[1], params=params)
    self.assertStatus(resp, 403)
    resp = self.request(path=('/item/%s' % str(item['_id'])), method='GET', user=self.users[1])
    self.assertStatus(resp, 403)
    resp = self.request(path=('/item/%s' % str(item['_id'])), method='GET', user=self.users[0])
    self.assertStatusOk(resp)
    self.assertEqual(resp.json['_id'], item['_id'])
    self.assertEqual(resp.json['_modelType'], 'item')
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json[0]['_id'], item['_id'])
    params['text'] = 'my item name'
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json[0]['_id'], item['_id'])
    del params['folderId']
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json[0]['_id'], item['_id'])
    params['limit'] = 1
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json[0]['_id'], item['_id'])
    params['offset'] = 1
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(len(resp.json), 0)
    resp = self.request(path='/item', method='GET', user=self.users[0], params={})
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid search mode.')
    params = {'name': 'changed name', 'description': 'new description'}
    resp = self.request(path=('/item/%s' % item['_id']), method='PUT', params=params, user=self.users[0])
    self.assertStatusOk(resp)
    self.assertEqual(resp.json['name'], params['name'])
    self.assertEqual(resp.json['description'], params['description'])
    item = Item().load(item['_id'], force=True)
    self.assertFalse(Item().hasAccess(item))
    resp = self.request(path=('/item/%s' % item['_id']), method='PUT', user=self.users[0], params={'folderId': self.publicFolder['_id']})
    self.assertStatusOk(resp)
    item = Item().load(resp.json['_id'], force=True)
    self.assertTrue(Item().hasAccess(item))
    self.publicFolder = Folder().setUserAccess(self.publicFolder, self.users[1], AccessType.WRITE, save=True)
    resp = self.request(path=('/item/%s' % item['_id']), method='PUT', user=self.users[1], params={'folderId': self.privateFolder['_id']})
    self.assertStatus(resp, 403)
    self.assertTrue(resp.json['message'].startswith('Write access denied for folder'))
    resp = self.request(path='/item/', method='PUT', params=params, user=self.users[0])
    self.assertStatus(resp, 400)
    resp = self.request(path=('/item/%s/blurgh' % item['_id']), method='GET', user=self.users[1])
    self.assertStatus(resp, 400)
    resp = self.request(path='/item/', method='DELETE', user=self.users[1])
    self.assertStatus(resp, 400)
    self.publicFolder = Folder().setUserAccess(self.publicFolder, self.users[1], AccessType.READ, save=True)
    resp = self.request(path=('/item/%s' % str(item['_id'])), method='DELETE', user=self.users[1])
    self.assertStatus(resp, 403)
    self.publicFolder = Folder().setUserAccess(self.publicFolder, self.users[1], AccessType.WRITE, save=True)
    resp = self.request(path=('/item/%s' % str(item['_id'])), method='DELETE', user=self.users[1])
    self.assertStatusOk(resp)
    item = Item().load(item['_id'])
    self.assertEqual(item, None)
Test Create, Read, Update, and Delete of items.
def testItemCrud(self):
    '\n        \n        '
    self.ensureRequiredParams(path='/item', method='POST', required=('folderId',), user=self.users[1])
    params = {'name': ' ', 'description': ' a description ', 'folderId': self.publicFolder['_id']}
    resp = self.request(path='/item', method='POST', params=params, user=self.users[1])
    self.assertStatus(resp, 403)
    resp = self.request(path='/item', method='POST', params=params, user=self.users[0])
    self.assertValidationError(resp, 'name')
    params['name'] = ' my item name'
    params['folderId'] = self.privateFolder['_id']
    resp = self.request(path='/item', method='POST', params=params, user=self.users[0])
    self.assertStatusOk(resp)
    item = resp.json
    self.assertEqual(item['name'], params['name'].strip())
    self.assertEqual(item['description'], params['description'].strip())
    params = {'folderId': self.privateFolder['_id']}
    resp = self.request(path='/item', method='GET', user=self.users[1], params=params)
    self.assertStatus(resp, 403)
    resp = self.request(path=('/item/%s' % str(item['_id'])), method='GET', user=self.users[1])
    self.assertStatus(resp, 403)
    resp = self.request(path=('/item/%s' % str(item['_id'])), method='GET', user=self.users[0])
    self.assertStatusOk(resp)
    self.assertEqual(resp.json['_id'], item['_id'])
    self.assertEqual(resp.json['_modelType'], 'item')
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json[0]['_id'], item['_id'])
    params['text'] = 'my item name'
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json[0]['_id'], item['_id'])
    del params['folderId']
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json[0]['_id'], item['_id'])
    params['limit'] = 1
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(resp.json[0]['_id'], item['_id'])
    params['offset'] = 1
    resp = self.request(path='/item', method='GET', user=self.users[0], params=params)
    self.assertStatusOk(resp)
    self.assertEqual(len(resp.json), 0)
    resp = self.request(path='/item', method='GET', user=self.users[0], params={})
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid search mode.')
    params = {'name': 'changed name', 'description': 'new description'}
    resp = self.request(path=('/item/%s' % item['_id']), method='PUT', params=params, user=self.users[0])
    self.assertStatusOk(resp)
    self.assertEqual(resp.json['name'], params['name'])
    self.assertEqual(resp.json['description'], params['description'])
    item = Item().load(item['_id'], force=True)
    self.assertFalse(Item().hasAccess(item))
    resp = self.request(path=('/item/%s' % item['_id']), method='PUT', user=self.users[0], params={'folderId': self.publicFolder['_id']})
    self.assertStatusOk(resp)
    item = Item().load(resp.json['_id'], force=True)
    self.assertTrue(Item().hasAccess(item))
    self.publicFolder = Folder().setUserAccess(self.publicFolder, self.users[1], AccessType.WRITE, save=True)
    resp = self.request(path=('/item/%s' % item['_id']), method='PUT', user=self.users[1], params={'folderId': self.privateFolder['_id']})
    self.assertStatus(resp, 403)
    self.assertTrue(resp.json['message'].startswith('Write access denied for folder'))
    resp = self.request(path='/item/', method='PUT', params=params, user=self.users[0])
    self.assertStatus(resp, 400)
    resp = self.request(path=('/item/%s/blurgh' % item['_id']), method='GET', user=self.users[1])
    self.assertStatus(resp, 400)
    resp = self.request(path='/item/', method='DELETE', user=self.users[1])
    self.assertStatus(resp, 400)
    self.publicFolder = Folder().setUserAccess(self.publicFolder, self.users[1], AccessType.READ, save=True)
    resp = self.request(path=('/item/%s' % str(item['_id'])), method='DELETE', user=self.users[1])
    self.assertStatus(resp, 403)
    self.publicFolder = Folder().setUserAccess(self.publicFolder, self.users[1], AccessType.WRITE, save=True)
    resp = self.request(path=('/item/%s' % str(item['_id'])), method='DELETE', user=self.users[1])
    self.assertStatusOk(resp)
    item = Item().load(item['_id'])
    self.assertEqual(item, None)