resolve types in pecan.wsexpose. It is a temporary solution.

--HG--
extra : rebase_source : a6835042f14fb016722323496ba8b826a2a8aa9d
This commit is contained in:
Christophe de Vienne 2012-11-29 22:24:39 +01:00
parent cbb5caf4bf
commit 67bf6c3dc4
3 changed files with 19 additions and 1 deletions

View File

@ -41,9 +41,21 @@ class AuthorsController(RestController):
books = BooksController()
@wsme.pecan.wsexpose([Author])
def get_all(self):
return [
Author(id=1, firstname=u'FirstName')
]
@wsme.pecan.wsexpose(Author, int)
def get(self, id):
author = Author()
author.id = id
author.name = u"aname"
author.firstname = u"aname"
author.books = [
Book(
name=u"Les Confessions dun révolutionnaire pour servir à "
u"lhistoire de la révolution de février",
)
]
return author

View File

@ -4,6 +4,9 @@ import json
class TestWS(FunctionalTest):
def test_get_all(self):
self.app.get('/authors')
def test_get_author(self):
a = self.app.get(
'/authors/1.json',
@ -13,9 +16,11 @@ class TestWS(FunctionalTest):
print a
assert a['id'] == 1
assert a['firstname'] == 'aname'
a = self.app.get(
'/authors/1.xml',
)
print a
assert '<id>1</id>' in a.body
assert '<firstname>aname</firstname>' in a.body

View File

@ -49,6 +49,7 @@ def wsexpose(*args, **kwargs):
def decorate(f):
sig(f)
funcdef = wsme.api.FunctionDefinition.get(f)
funcdef.resolve_types(wsme.types.registry)
def callfunction(self, *args, **kwargs):
args, kwargs = wsme.rest.args.get_args(