From 7ca51988782311ab74b23920fa5fd1b64900f46a Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Wed, 21 Jul 2010 05:28:51 +0000 Subject: Add a test of the password protected python store sample. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@966096 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/wsgi/composite.py | 34 +++++++++++++++------- .../store-gae/htdocs/test/getcatalog-result.txt | 1 + sca-cpp/trunk/samples/store-gae/server-test | 24 +++++++++++++-- 3 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 sca-cpp/trunk/samples/store-gae/htdocs/test/getcatalog-result.txt (limited to 'sca-cpp') diff --git a/sca-cpp/trunk/modules/wsgi/composite.py b/sca-cpp/trunk/modules/wsgi/composite.py index 453718e556..a014156af9 100755 --- a/sca-cpp/trunk/modules/wsgi/composite.py +++ b/sca-cpp/trunk/modules/wsgi/composite.py @@ -118,23 +118,27 @@ def postArgs(a): l = car(a); return cons(l, postArgs(cdr(a))) -# Return the URL of the logout page -def logout(ruri): +# Return the URL used to sign out +def signout(ruri): try: from google.appengine.api import users return users.create_logout_url(ruri) except: return None +# Return the URL used to sign in +def signin(ruri): + try: + from google.appengine.api import users + return users.create_login_url(ruri) + except: + return None + # WSGI application function def application(e, r): m = requestMethod(e) fpath = requestPath(e) - # Debug hook - if fpath == "/debug": - return result(e, r, 200, (("Content-type", "text/plain"),), ("Debug",)) - # Serve static files if m == "GET": if fpath.endswith(".html"): @@ -146,11 +150,19 @@ def application(e, r): if fpath == "/": return result(e, r, 301, (("Location", "/index.html"),)) - # Logout - if fpath == "/logout": - redir = logout("/") - if redir: - return result(e, r, 301, (("Location", redir),)) + # Debug hook + if fpath == "/debug": + return result(e, r, 200, (("Content-type", "text/plain"),), ("Debug",)) + + # Sign in and out + if fpath == "/login": + redir = signin("/") + if redir: + return result(e, r, 301, (("Location", redir),)) + if fpath == "/logout": + redir = signout(signin("/")) + if redir: + return result(e, r, 301, (("Location", redir),)) # Find the requested component path = tokens(fpath) diff --git a/sca-cpp/trunk/samples/store-gae/htdocs/test/getcatalog-result.txt b/sca-cpp/trunk/samples/store-gae/htdocs/test/getcatalog-result.txt new file mode 100644 index 0000000000..6c2d599106 --- /dev/null +++ b/sca-cpp/trunk/samples/store-gae/htdocs/test/getcatalog-result.txt @@ -0,0 +1 @@ +{"id":1,"result":[{"price":2.9900000000000002,"javaClass":"services.Item","currencyCode":"USD","name":"Apple","currencySymbol":"$"},{"price":3.5499999999999998,"javaClass":"services.Item","currencyCode":"USD","name":"Orange","currencySymbol":"$"},{"price":1.55,"javaClass":"services.Item","currencyCode":"USD","name":"Pear","currencySymbol":"$"}]} \ No newline at end of file diff --git a/sca-cpp/trunk/samples/store-gae/server-test b/sca-cpp/trunk/samples/store-gae/server-test index a36f6a0239..acaf3b2f0d 100755 --- a/sca-cpp/trunk/samples/store-gae/server-test +++ b/sca-cpp/trunk/samples/store-gae/server-test @@ -25,12 +25,30 @@ curl_prefix=`cat $here/../../modules/http/curl.prefix` ./start 2>/dev/null sleep 2 -# Test HTTP GET +# Test HTTP GET (with authentication) mkdir -p tmp -$curl_prefix/bin/curl -L http://localhost:8090/ 2>/dev/null >tmp/login.html -grep "Login" tmp/login.html >/dev/null +$curl_prefix/bin/curl -L -c tmp/cookies.txt -b tmp/cookies.txt "http://localhost:8090/_ah/login?email=test@example.com&action=Login&continue=http://localhost:8090/" 2>/dev/null >tmp/index.html +diff tmp/index.html htdocs/index.html rc=$? +# Test Catalog +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl -b tmp/cookies.txt http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @../store-cpp/htdocs/test/getcatalog-request.txt >tmp/getcatalog-result.txt 2>/dev/null + diff tmp/getcatalog-result.txt htdocs/test/getcatalog-result.txt + rc=$? +fi + +# Test Shopping Cart +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl -b tmp/cookies.txt http://localhost:8090/references/Store/shoppingCart -X POST -H "Content-type: application/atom+xml" --data @../store-cpp/htdocs/test/shopping-cart-entry.xml 2>/dev/null + rc=$? +fi +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl -b tmp/cookies.txt http://localhost:8090/references/Store/shoppingCart >tmp/shopping-cart-feed.xml 2>/dev/null + grep "3.55" tmp/shopping-cart-feed.xml >/dev/null + rc=$? +fi + # Cleanup ./stop sleep 2 -- cgit v1.2.3