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

This commit is contained in:
Christophe de Vienne 2012-11-29 22:24:39 +01:00
parent 7def85c238
commit 143bbb189b
3 changed files with 19 additions and 1 deletions

View File

@ -41,9 +41,21 @@ class AuthorsController(RestController):
books = BooksController() books = BooksController()
@wsme.pecan.wsexpose([Author])
def get_all(self):
return [
Author(id=1, firstname=u'FirstName')
]
@wsme.pecan.wsexpose(Author, int) @wsme.pecan.wsexpose(Author, int)
def get(self, id): def get(self, id):
author = Author() author = Author()
author.id = id 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 return author

View File

@ -4,6 +4,9 @@ import json
class TestWS(FunctionalTest): class TestWS(FunctionalTest):
def test_get_all(self):
self.app.get('/authors')
def test_get_author(self): def test_get_author(self):
a = self.app.get( a = self.app.get(
'/authors/1.json', '/authors/1.json',
@ -13,9 +16,11 @@ class TestWS(FunctionalTest):
print a print a
assert a['id'] == 1 assert a['id'] == 1
assert a['firstname'] == 'aname'
a = self.app.get( a = self.app.get(
'/authors/1.xml', '/authors/1.xml',
) )
print a print a
assert '<id>1</id>' in a.body 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): def decorate(f):
sig(f) sig(f)
funcdef = wsme.api.FunctionDefinition.get(f) funcdef = wsme.api.FunctionDefinition.get(f)
funcdef.resolve_types(wsme.types.registry)
def callfunction(self, *args, **kwargs): def callfunction(self, *args, **kwargs):
args, kwargs = wsme.rest.args.get_args( args, kwargs = wsme.rest.args.get_args(