示例#1
0
 def testNotes(self):
     f = HTTPTopLevel('users', 'PUT')
     usage = HTTPUsage('/dummy', 'an example of great profundity')
     f.addUsage(usage)
     note = Note('hey')
     usage.addNote(note)
     note = Note('hey')
     usage.addNote(note)
     self.assertEqual(len(usage.notes), 2)
     self.reg.register(f)
     apis = self.reg.get('users', 'PUT')
     self.assertEqual(apis, [['users', [('PUT', f)]]])
     f = apis[0][1][0][1]
     self.assertEqual(len(f.usages), 1)
     self.assertEqual(len(f.usages[0].notes), 2)
示例#2
0
    def testFindUsage(self):

        class Dummy1(object):
            pass

        class Dummy2(object):
            pass

        class Dummy3(object):
            pass

        f = HTTPTopLevel('users', 'PUT')
        self.reg.register(f)
        usage1 = HTTPUsage('', "Return a list of all users.")
        usage1.resourceClass = Dummy1
        f.addUsage(usage1)

        f = HTTPTopLevel('dummy', 'GET')
        self.reg.register(f)
        usage2 = HTTPUsage('', "Return a list of all dummies.")
        usage2.resourceClass = Dummy2
        f.addUsage(usage2)

        # Find the usage with class Dummy1.
        u = self.reg.findUsage('users', 'PUT',
                               usageResourceClass=Dummy1)
        self.assertTrue(u.resourceClass is usage1.resourceClass)

        # Find the usage with class Dummy2.
        u = self.reg.findUsage('dummy', 'GET',
                               usageResourceClass=Dummy2)
        self.assertTrue(u.resourceClass is usage2.resourceClass)

        # Ask for a non-existent usage class.
        self.assertRaises(error.NoSuchUsage,
                          self.reg.findUsage, 'dummy', 'GET',
                          usageResourceClass=Dummy3)

        # Ask for a non-existent toplevel.
        self.assertRaises(error.NoSuchToplevel,
                          self.reg.findUsage, 'sunny', 'PUT',
                          usageResourceClass=Dummy2)

        # Ask for a non-existent verb.
        self.assertRaises(error.NoSuchVerb,
                          self.reg.findUsage, 'dummy', 'PUT',
                          usageResourceClass=Dummy2)
示例#3
0
    a given query"""))
usage.resourceClass = RecentObjectsActivityResource
usage.addArgument(Argument(
    'query',
    dedent("""
    A query string specifying what sorts of objects to get recent activity for.
    The query language is described <a
    href="http://doc.fluidinfo.com/fluidDB/queries.html">here</a>. You must
    convert your query to UTF-8 and then <a href="http://en.wikipedia.org/wiki
    /Percent-encoding">
     percent-encode</a> it before adding it to the request URI
     """),
    'string',
    default=None,
    mandatory=True))
topLevel.addUsage(usage)

request = dedent("""
    GET /recent/objects?query=has+bob%2Ffollows HTTP/1.1
    Authorization: Basic XXXXXXXX""")
response = dedent("""
    HTTP/1.1 200 OK
    Content-Length: 1027
    Date: Mon, 02 Aug 2010 13:16:09 GMT
    Content-Type: application/json

    [ { "about" : "http://en.wikipedia.org/wiki/Billion_laughs",
        "id" : "63a5413d-2e0f-4078-9c04-00e58a727478",
        "tag" : "bob/like",
        "updated-at" : "2012-02-22T19:21:50.208654",
        "username" : "bob",
示例#4
0
文件: values.py 项目: xanixon/fluiddb
topLevel.description = """The GET method on values is used to retrieve
    tag values from objects matching a query."""

# We could here mention
# href="http://doc.fluidinfo.com/fluidDB/api/draft-values-spec.html">
# /values draft spec</a>.

registry.register(topLevel)

# --- GET /values --------------------------------------------------------

usage = HTTPUsage(
    '', """Search for objects matching a Fluidinfo query, and return the
           value of the requested tags on the matching objects.""")
usage.resourceClass = ValuesResource
topLevel.addUsage(usage)

usage.addArgument(
    Argument(queryArg,
             '''A query string specifying what objects to match. The
       Fluidinfo query language is described
       <a href="http://doc.fluidinfo.com/fluidDB/queries.html">here</a>.''',
             'string',
             None,
             mandatory=True))

usage.addArgument(
    Argument(tagArg,
             '''The name of a tag whose value should be returned. Repeat this
    argument as many times as needed. All values are returned if '*' is
    specified.''',