Commit 76ab893e by Piotr Mitros

name can be a list

parent f3c5a8b3
......@@ -67,6 +67,10 @@ def view(category = None, name = None, description = None, args = None):
args: Optional argspec for the function. This is generally better
omitted.
TODO: human_name: Name without Python name restrictions -- e.g.
"Daily uploads" instead of "daily_uploads" -- for use in
human-usable dashboards.
'''
def view_factory(f):
registry.register_handler('view',category, name, description, f, args)
......
......@@ -33,11 +33,21 @@ def register_handler(cls, category, name, description, f, args):
category+="+"
if cls not in request_handlers:
request_handlers[cls] = {}
if name in request_handlers[cls]:
# We used to have this be an error.
# We changed to a warning for the way we handle dummy values.
log.warn("{0} already in {1}".format(name, category)) # raise KeyError(name+" already in "+category)
request_handlers[cls][name] = {'function': f, 'name': name, 'doc': description, 'category' : category}
# We may want to register under multiple names. E.g.
# edx.get_grades and (once adopted globally) generic
# get_grades
if isinstance(name, list):
names = name
else:
names = [name]
for n in names:
if n in request_handlers[cls]:
# We used to have this be an error.
# We changed to a warning for the way we handle dummy values.
log.warn("{0} already in {1}".format(n, category)) # raise KeyError(name+" already in "+category)
request_handlers[cls][n] = {'function': f, 'name': n, 'doc': description, 'category' : category}
class StreamingEvent:
''' Event object. Behaves like the normal JSON event dictionary,
......
......@@ -164,3 +164,15 @@ def djt_fake_user_count(query):
the network, as well as optional parameters like fs, db, etc.
'''
return "<html>Users: {uc}</html>".format(uc = query.djt_fake_user_count())
@query(name=['djt_three_name', 'edx_djt_three_name', 'edx.djt_three_name'])
def djt_three_name():
return "I have three names"
@query(name = 'djt_check_three_name')
def check_three_name(query):
if query.djt_three_name() != "I have three names":
raise Exception("oops")
if query.edx_djt_three_name() != "I have three names":
raise Exception("oops")
return "Works"
......@@ -151,3 +151,8 @@ class SimpleTest(TestCase):
c = Client()
response = c.get('/view/djt_fake_user_count').content
self.assertEqual(response, "<html>Users: 2</html>")
def test_multiname(self):
c = Client()
response = c.get('/query/djt_check_three_name').content
self.assertEqual(response, "Works")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment