Пример #1
0
 def test_put_about_type_header(self):
     """
     There was a bug where the fluidinfo.py wasn't creating the correct
     content-type header when PUTting to an about tag value, this test
     re-creates it.
     """
     # ensures we have an object about foo
     headers, response = fluidinfo.get('/about/foo')
     # create a one off tag to use for the purposes of testing
     fluidinfo.login(USERNAME, PASSWORD)
     new_tag = str(uuid.uuid4())
     tag_body = {'description': 'a test tag', 'name': new_tag,
                 'indexed': False}
     # create a tag to use in a bit
     result = fluidinfo.post('/tags/test', tag_body)
     self.assertEqual('201', result[0]['status'])
     self.assertTrue(result[1].has_key('id'))
     # make sure we can PUT using the about API
     try:
         header, content = fluidinfo.put('/about/foo/test/'+new_tag,
             'this is a test')
         # check that it worked
         self.assertEqual('204', header['status'])
     finally:
         # Housekeeping
         fluidinfo.delete('/tags/test/' + new_tag)
Пример #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
Пример #3
0
 def test_call_DELETE(self):
     fluidinfo.login(USERNAME, PASSWORD)
     # Simply create a new namespace and then delete it
     new_namespace = str(uuid.uuid4())
     body = {'description': 'a test namespace', 'name': new_namespace}
     result = fluidinfo.post('/namespaces/test', body)
     self.assertEqual('201', result[0]['status'])
     self.assertTrue(result[1].has_key('id'))
     result = fluidinfo.delete('/namespaces/test/' + new_namespace)
     self.assertEqual('204', result[0]['status'])
Пример #4
0
def getFluidinfoClient(options):
    """Configure and return a C{fluidinfo.py} client for use with Fluidinfo.

    @param options: An C{optparse.Values} instance with options loaded from
        the command-line.
    @return: A ready-to-use C{fluidinfo.py} instance.
    """
    fluidinfo.instance = options.endpoint
    fluidinfo.login(options.username, options.password)
    return fluidinfo
Пример #5
0
 def test_call_GET(self):
     fluidinfo.login(USERNAME, PASSWORD)
     # No query string args to append
     result = fluidinfo.get('/namespaces/test')
     self.assertEqual('200', result[0]['status'])
     # make sure the resulting json is turned into a Python dictionary
     self.assertTrue(isinstance(result[1], dict))
     # ...and we have the expected id
     self.assertTrue(result[1].has_key('id'))
     # The same call WITH query string args to append to the URL
     # eg we'll get /namespaces/test?returnDescription=True as the path
     result = fluidinfo.get('/namespaces/test', None, None,
                           returnDescription = True)
     self.assertEqual('200', result[0]['status'])
     # make sure the result has the expected description field
     self.assertTrue(result[1].has_key('description'))
     # finally we need to make sure that primitive values returned from
     # fluidDB are turned from their json representation to their
     # Pythonic form
     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])
     primitives = [1, 1.1, u'foo', ['a', 'b', u'c'], True, None, ]
     for primitive in primitives:
         result = fluidinfo.put(path, primitive)
         self.assertEqual('204', result[0]['status'])
         # GET the new tag value and check it gets translated back to
         # the correct type
         result = fluidinfo.get(path)
         self.assertEqual('application/vnd.fluiddb.value+json',
                          result[0]['content-type'])
         self.assertTrue(isinstance(result[1], type(primitive)))
     # check the new /values GET works
     result = fluidinfo.get('/values', tags=['fluiddb/about',
         'test/%s/%s' % (new_namespace, new_tag)],
         query='has test/%s/%s' % (new_namespace, new_tag))
     self.assertEqual('200', result[0]['status'])
     self.assertTrue(result[1].has_key('results'))
     # Housekeeping
     fluidinfo.delete('/tags/test/' + new_namespace + '/' + new_tag)
     fluidinfo.delete('/namespaces/test/'+new_namespace)
Пример #6
0
 def test_call_POST(self):
     fluidinfo.login(USERNAME, PASSWORD)
     new_namespace = str(uuid.uuid4())
     ns_body = {'description': 'a test namespace',
                'name': new_namespace}
     # Make sure that if the body is a dict it gets translated to json
     result = fluidinfo.post('/namespaces/test', ns_body)
     self.assertEqual('201', result[0]['status'])
     self.assertTrue(result[1].has_key('id'))
     # Housekeeping
     fluidinfo.call('DELETE', '/namespaces/test/'+new_namespace)
Пример #7
0
def grabCredentials():
    """
    Grabs user's Fluidinfo credentials and makes sure the Authorization headers
    are set.
    """
    print "Please enter your Fluidinfo username and password:"******"Username: "******"Password: "******"Logging in as %s" % username)
    fluidinfo.login(username, password)
    return username
Пример #8
0
def grabCredentials():
    """
    Grabs user's Fluidinfo credentials and makes sure the Authorization headers
    are set.
    """
    print "Please enter your Fluidinfo username and password:"******"Username: "******"Password: "******"Logging in as %s" % username)
    fluidinfo.login(username, password)
    return username
Пример #9
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)
Пример #10
0
 def test_logout(self):
     # Lets first log in and check we're good to go
     fluidinfo.login(USERNAME, PASSWORD)
     result = fluidinfo.get('/users/test')
     self.assertEqual('200', result[0]['status'])
     # Log out (this should clear the Authorization header)
     fluidinfo.logout()
     # We should still be able to do anonymous calls
     result = fluidinfo.get('/users/test')
     self.assertEqual('200', result[0]['status'])
     # but we can't do anything that requires us to be authenticated
     new_namespace = str(uuid.uuid4())
     result = fluidinfo.post('/namespaces/test',
                          {'description': 'will fail',
                           'name': new_namespace})
     self.assertEqual('401', result[0]['status'])
    def connect(klass, username, password):
        fluidinfo.login(username, password)
        conn = klass()
        conn.username = username
        conn.setup_biar_namespaces()
        # Check that we can actually connect, e.g. network is not down
        try:
            fluidinfo.login(username, password)
        except Exception as e:
            print "Encountered a problem logging in"
            raise e

        # Check to ensure that the login creditials were accepted
        response = conn.user_info()
        if type(response) is str:
            errorMessage = "Log in failed for user %s, message: %s" % (conn.username, response)
            raise Exception(errorMessage)

        return conn
Пример #12
0
 def test_login(self):
     # we're not logged in but able to do anonymous calls
     result = fluidinfo.get('/users/test')
     self.assertEqual('200', result[0]['status'])
     new_namespace = str(uuid.uuid4())
     # and we can't do anything that requires us to be authenticated
     result = fluidinfo.post('/namespaces/test',
                          {'description': 'will fail',
                           'name': new_namespace})
     self.assertEqual('401', result[0]['status'])
     # Now lets log in with *bad* credentials
     fluidinfo.login(USERNAME, PASSWORD + 'bad_password')
     result = fluidinfo.get('/users/test')
     # Unauthorised due to bad credentials
     self.assertEqual('401', result[0]['status'])
     # Try again with the good case
     fluidinfo.login(USERNAME, PASSWORD)
     result = fluidinfo.get('/users/test')
     self.assertEqual('200', result[0]['status'])
Пример #13
0
    def connect(klass, username, password):
        fluidinfo.login(username, password)
        conn = klass()
        conn.username = username
        conn.setup_biar_namespaces()
        # Check that we can actually connect, e.g. network is not down
        try:
            fluidinfo.login(username, password)
        except Exception as e:
            print "Encountered a problem logging in"
            raise e

        # Check to ensure that the login creditials were accepted
        response = conn.user_info()
        if type(response) is str:
            errorMessage = "Log in failed for user %s, message: %s" % (
                conn.username, response)
            raise Exception(errorMessage)

        return conn
Пример #14
0
#!/usr/bin/env python

from getpass import getpass
import fluidinfo as fi
from pprint import pprint

username = '******'
password = getpass('password: '******'../loveme.do.safariextz') as f:
    extension = f.read()

h, r = fi.put('/about/@fluidinfo/gridaphobe/fluidinfo.safariextz', extension,
              'application/octet-stream')

if h['status'] != '204':
    print 'Error uploading extension:'
    pprint(h)


with open('update.plist') as f:
    plist = f.read()

h, r = fi.put('/about/@fluidinfo/gridaphobe/safari-extension.plist', plist,
              'text/plain')

if h['status'] != '204':
    print 'Error uploading plist:'
Пример #15
0
import fluidinfo
import json
import os
import urllib

### @export "fluid-login"
USERNAME = '******'
PASSWORD = '******'

if not USERNAME:
    raise Exception("Please supply a fluid account username")

if not PASSWORD:
    raise Exception("Please supply a fluid account password")

fluidinfo.login(USERNAME, PASSWORD)

headers, response = fluidinfo.call('GET', "/users/%s" % USERNAME)
print response

### @export "set-tag-permissions"
taglist = [
    'author', 'keyword', 'series'
    'is_video', 'is_blog_post', 'volume', 'year', 'name', 'pmid', 'short-name',
    'grant_id', 'wonga'
]


def setPermOnTag(foo):

    permission_space = '/permissions/tags/biar/%s' % foo
Пример #16
0
#!/usr/bin/env python

import os
import sys
import fluidinfo
from urllib import quote

fluidinfo.login("twitter.com", os.environ["FLUIDINFO_TWITTER_PASSWORD"])

tags = sys.stdin.readlines()
ntags = len(tags)

for i, tag in enumerate(tags):
    tag = quote(tag[:-1])
    hdrs, response = fluidinfo.call("DELETE", "/tags/%s" % tag)
    if hdrs["status"] == "204":
        print "%d/%d deleted %s", (i + 1, ntags, tag)
    else:
        print "%d/%d failed deleting %s: %s" % (i + 1, ntags, tag, hdrs)
import fluidinfo
import json
import os
import urllib

### @export "fluid-login"
USERNAME = "******"
PASSWORD = "******"

if not USERNAME:
    raise Exception("Please supply a fluid account username")

if not PASSWORD:
    raise Exception("Please supply a fluid account password")

fluidinfo.login(USERNAME, PASSWORD)

headers, response = fluidinfo.call("GET", "/users/%s" % USERNAME)
print response

### @export "set-tag-permissions"
taglist = [
    "author",
    "keyword",
    "series" "is_video",
    "is_blog_post",
    "volume",
    "year",
    "name",
    "pmid",
    "short-name",