def testItemMetadataCrud(self):
    '\n        Test CRUD of metadata.\n        '
    params = {'name': 'item with metadata', 'description': ' a description ', 'folderId': self.privateFolder['_id']}
    resp = self.request(path='/item', method='POST', params=params, user=self.users[0])
    self.assertStatusOk(resp)
    item = resp.json
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='DELETE', user=self.users[0], body=json.dumps(['foobar']), type='application/json')
    item = resp.json
    self.assertStatusOk(resp)
    self.assertEqual(item['meta'], {})
    metadata = {'foo': 'bar', 'test': 2}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    item = resp.json
    self.assertEqual(item['meta']['foo'], metadata['foo'])
    self.assertEqual(item['meta']['test'], metadata['test'])
    body = '{"key": {"foo": Infinity}}'
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=body, type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Error: "Infinity" is not valid JSON.')
    metadata['test'] = None
    metadata['foo'] = 'baz'
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    item = resp.json
    self.assertEqual(item['meta']['foo'], metadata['foo'])
    self.assertNotHasKeys(item['meta'], ['test'])
    metadata['nullVal'] = None
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), params={'allowNull': True}, type='application/json')
    item = resp.json
    self.assertEqual(item['meta']['nullVal'], None)
    del metadata['nullVal']
    metadata['other'] = 'macguffin'
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    item = resp.json
    self.assertEqual(item['meta']['other'], metadata['other'])
    self.assertEqual(item['meta']['nullVal'], None)
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='DELETE', user=self.users[0], body=json.dumps(['other']), type='application/json')
    item = resp.json
    self.assertNotHasKeys(item['meta'], ['other'])
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='DELETE', user=self.users[0], body=json.dumps(['foo', 'foo.bar']), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid key foo.bar: keys must not contain the "." character.')
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='DELETE', user=self.users[0], body=json.dumps(['foo', '$bar']), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid key $bar: keys must not start with the "$" character.')
    metadata = {'test': 'allowed'}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata).replace('"', "'"), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid JSON passed in request body.')
    metadata = {'foo.bar': 'notallowed'}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid key foo.bar: keys must not contain the "." character.')
    metadata = {'$foobar': 'alsonotallowed'}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid key $foobar: keys must not start with the "$" character.')
    metadata = {'': 'stillnotallowed'}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Key names must not be empty.')
Test CRUD of metadata.
def testItemMetadataCrud(self):
    '\n        \n        '
    params = {'name': 'item with metadata', 'description': ' a description ', 'folderId': self.privateFolder['_id']}
    resp = self.request(path='/item', method='POST', params=params, user=self.users[0])
    self.assertStatusOk(resp)
    item = resp.json
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='DELETE', user=self.users[0], body=json.dumps(['foobar']), type='application/json')
    item = resp.json
    self.assertStatusOk(resp)
    self.assertEqual(item['meta'], {})
    metadata = {'foo': 'bar', 'test': 2}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    item = resp.json
    self.assertEqual(item['meta']['foo'], metadata['foo'])
    self.assertEqual(item['meta']['test'], metadata['test'])
    body = '{"key": {"foo": Infinity}}'
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=body, type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Error: "Infinity" is not valid JSON.')
    metadata['test'] = None
    metadata['foo'] = 'baz'
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    item = resp.json
    self.assertEqual(item['meta']['foo'], metadata['foo'])
    self.assertNotHasKeys(item['meta'], ['test'])
    metadata['nullVal'] = None
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), params={'allowNull': True}, type='application/json')
    item = resp.json
    self.assertEqual(item['meta']['nullVal'], None)
    del metadata['nullVal']
    metadata['other'] = 'macguffin'
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    item = resp.json
    self.assertEqual(item['meta']['other'], metadata['other'])
    self.assertEqual(item['meta']['nullVal'], None)
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='DELETE', user=self.users[0], body=json.dumps(['other']), type='application/json')
    item = resp.json
    self.assertNotHasKeys(item['meta'], ['other'])
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='DELETE', user=self.users[0], body=json.dumps(['foo', 'foo.bar']), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid key foo.bar: keys must not contain the "." character.')
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='DELETE', user=self.users[0], body=json.dumps(['foo', '$bar']), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid key $bar: keys must not start with the "$" character.')
    metadata = {'test': 'allowed'}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata).replace('"', "'"), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid JSON passed in request body.')
    metadata = {'foo.bar': 'notallowed'}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid key foo.bar: keys must not contain the "." character.')
    metadata = {'$foobar': 'alsonotallowed'}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Invalid key $foobar: keys must not start with the "$" character.')
    metadata = {: 'stillnotallowed'}
    resp = self.request(path=('/item/%s/metadata' % item['_id']), method='PUT', user=self.users[0], body=json.dumps(metadata), type='application/json')
    self.assertStatus(resp, 400)
    self.assertEqual(resp.json['message'], 'Key names must not be empty.')