Exemplo n.º 1
0
 def test_call_PUT(self):
     fluidinfo.login(USERNAME, PASSWORD)
     new_namespace = str(uuid.uuid4())
     new_tag = str(uuid.uuid4())
     ns_body = {'description': 'a test namespace',
                'name': new_namespace}
     tag_body = {'description': 'a test tag', 'name': new_tag,
                 'indexed': False}
     # create a namespace and tag to use in a bit
     result = fluidinfo.post('/namespaces/test', ns_body)
     self.assertEqual('201', result[0]['status'])
     self.assertTrue(result[1].has_key('id'))
     ns_id = result[1]['id'] # for later use
     result = fluidinfo.post('/tags/test/' + new_namespace, tag_body)
     self.assertEqual('201', result[0]['status'])
     self.assertTrue(result[1].has_key('id'))
     path = '/'+'/'.join(['objects', ns_id, 'test', new_namespace,
                          new_tag])
     # Make sure that primitive types are json encoded properly with
     # the correct mime-type, dicts are translated to json, the
     # mime-type argument for opaque types is used properly and if
     # no mime-type is supplied and the previous checks are not met
     # an appropriate exception is raised.
     primitives = [1, 1.1, 'foo', u'foo', True, None, ['a', 'b', u'c']]
     for primitive in primitives:
         result = fluidinfo.put(path, primitive)
         self.assertEqual('204', result[0]['status'])
         # call HEAD verb on that tag value to get the mime-type from
         # Fluidinfo
         result = fluidinfo.head(path)
         self.assertEqual('application/vnd.fluiddb.value+json',
                          result[0]['content-type'])
     # dicts are json encoded
     result = fluidinfo.put(path, {'foo': 'bar'})
     # check again with HEAD verb
     result = fluidinfo.head(path)
     self.assertEqual('application/json', result[0]['content-type'])
     # Make sure that the body and mime args work as expected (mime
     # overrides the primitive string type making the value opaque)
     result = fluidinfo.put(path, '<html><body><h1>Hello,'\
                           'World!</h1></body></html>', 'text/html')
     result = fluidinfo.head(path)
     self.assertEqual('text/html', result[0]['content-type'])
     # unspecified mime-type on a non-primitive value results in an
     # exception
     self.assertRaises(TypeError, fluidinfo.call, 'PUT', path, object())
     # make sure it's possible to PUT a tag value using a list based path
     pathAsList = ['objects', ns_id, 'test', new_namespace, new_tag]
     result = fluidinfo.put(pathAsList, 'foo')
     self.assertEqual('204', result[0]['status'])
     # Housekeeping
     fluidinfo.delete('/tags/test/' + new_namespace + '/' + new_tag)
     fluidinfo.delete('/namespaces/test/' + new_namespace)
Exemplo n.º 2
0
 def test_call_HEAD(self):
     fluidinfo.login(USERNAME, PASSWORD)
     # Grab an object ID for a user for us to use in the HEAD path
     result = fluidinfo.get('/users/test')
     obj_id = result[1]['id']
     path = '/objects/%s/fluiddb/users/username' % obj_id
     result = fluidinfo.head(path)
     self.assertEqual('200', result[0]['status'])
     self.assertFalse(result[1]) # no response body with HEAD call