From 67bf6c3dc48df782ffe06604296cbf6489b2d8cb Mon Sep 17 00:00:00 2001 From: Christophe de Vienne Date: Thu, 29 Nov 2012 22:24:39 +0100 Subject: [PATCH] resolve types in pecan.wsexpose. It is a temporary solution. --HG-- extra : rebase_source : a6835042f14fb016722323496ba8b826a2a8aa9d --- tests/pecantest/test/controllers/ws.py | 14 +++++++++++++- tests/pecantest/test/tests/test_ws.py | 5 +++++ wsme/pecan.py | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/pecantest/test/controllers/ws.py b/tests/pecantest/test/controllers/ws.py index 15f5367..410bbef 100644 --- a/tests/pecantest/test/controllers/ws.py +++ b/tests/pecantest/test/controllers/ws.py @@ -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 d’un révolutionnaire pour servir à " + u"l’histoire de la révolution de février", + ) + ] return author diff --git a/tests/pecantest/test/tests/test_ws.py b/tests/pecantest/test/tests/test_ws.py index 4b7f7d1..03457e9 100644 --- a/tests/pecantest/test/tests/test_ws.py +++ b/tests/pecantest/test/tests/test_ws.py @@ -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 '1' in a.body + assert 'aname' in a.body diff --git a/wsme/pecan.py b/wsme/pecan.py index ce1341d..f0ad4e5 100644 --- a/wsme/pecan.py +++ b/wsme/pecan.py @@ -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(