Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add tests for existing functionality.

  • Loading branch information...
commit 05d6faf277dbdd7758a1bcff93fae2892294f74e 1 parent eac42a8
@cdent cdent authored
Showing with 65 additions and 0 deletions.
  1. +1 −0  Makefile
  2. +64 −0 test/test_status.py
View
1  Makefile
@@ -9,6 +9,7 @@ clean:
rm -r dist || true
rm -r build || true
rm -r *.egg-info || true
+ rm -r store || true
test:
py.test -x test
View
64 test/test_status.py
@@ -0,0 +1,64 @@
+"""
+Test that status returns the info we expect.
+"""
+
+
+from wsgi_intercept import httplib2_intercept
+import wsgi_intercept
+import httplib2
+import shutil
+import simplejson
+
+from base64 import b64encode
+
+from tiddlyweb import __version__ as VERSION
+
+from tiddlyweb.config import config
+from tiddlyweb.web.serve import load_app
+from tiddlyweb.model.user import User
+from tiddlywebplugins.utils import get_store
+
+
+def setup_module(module):
+ try:
+ shutil.rmtree('store')
+ except: # it's not there
+ pass
+
+ app = load_app()
+ def app_fn():
+ return app
+
+ module.store = get_store(config)
+
+ httplib2_intercept.install()
+ wsgi_intercept.add_wsgi_intercept('0.0.0.0', 8080, app_fn)
+
+ module.http = httplib2.Http()
+
+
+def test_simple_status():
+ response, content = http.request('http://0.0.0.0:8080/status')
+ assert response['status'] == '200'
+ info = simplejson.loads(content)
+
+ assert info['username'] == 'GUEST'
+ assert info['version'] == VERSION
+ assert 'cookie_form' in info['challengers'][0]
+
+
+def test_with_user_status():
+ user = User('apple')
+ user.set_password('fruit')
+ store.put(user)
+
+ authorization = b64encode('apple:fruit')
+
+ response, content = http.request('http://0.0.0.0:8080/status',
+ headers = {'Authorization': 'Basic %s' % authorization})
+ assert response['status'] == '200'
+
+ info = simplejson.loads(content)
+ assert info['username'] == 'apple'
+
+# javascript
Please sign in to comment.
Something went wrong with that request. Please try again.