From 9ee2d2f9a21119039e00fdb0f456793cbd49aef3 Mon Sep 17 00:00:00 2001 From: Christophe de Vienne Date: Fri, 15 Feb 2013 14:05:49 +0100 Subject: [PATCH] Add a test for the body= parameter of wsexpose --HG-- extra : rebase_source : fc9479a0aa0de8485440a70e86971666fea56fb8 --- tests/pecantest/test/controllers/ws.py | 7 +++++-- tests/pecantest/test/tests/test_ws.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/pecantest/test/controllers/ws.py b/tests/pecantest/test/controllers/ws.py index dc369b1..8a3535e 100644 --- a/tests/pecantest/test/controllers/ws.py +++ b/tests/pecantest/test/controllers/ws.py @@ -27,13 +27,16 @@ class BooksController(RestController): book = Book( name=u"Les Confessions d’un révolutionnaire pour servir à " u"l’histoire de la révolution de février", - author=Author(lastname=u"Proudhon")) + author=Author(lastname=u"Proudhon") + ) return book @wsmeext.pecan.wsexpose(Book, int, int, body=Book) def put(self, author_id, id, book=None): print author_id, id print book + book.id = id + book.author = Author(id=author_id) return book @@ -73,7 +76,7 @@ class AuthorsController(RestController): author.books = [ Book( name=u"Les Confessions d’un révolutionnaire pour servir à " - u"l’histoire de la révolution de février", + 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 2f4f3cb..3bb409d 100644 --- a/tests/pecantest/test/tests/test_ws.py +++ b/tests/pecantest/test/tests/test_ws.py @@ -82,3 +82,14 @@ class TestWS(FunctionalTest): a = json.loads(res.body) print a assert a['faultcode'] == 'Server' + + def test_body_parameter(self): + res = self.app.put( + '/authors/1/books/2.json', + '{"name": "Alice au pays des merveilles"}', + headers={"Content-Type": "application/json"} + ) + book = json.loads(res.body) + print book + assert book['id'] == 2 + assert book['author']['id'] == 1