Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added some tests

  • Loading branch information...
commit 85ff225bbbb93ee9b609556f495d104b00c7616f 1 parent f85c4e2
@delijati delijati authored
View
5 apex/lib/libapex.py
@@ -86,7 +86,10 @@ def apex_id_from_token(request):
velruse = requests.get(request.host_url + '/velruse/auth_info', \
params=payload)
if velruse.status_code == 200:
- auth = velruse.json()
+ try:
+ auth = velruse.json()
+ except:
+ raise HTTPBadRequest(_('Velruse error while decoding json'))
if 'profile' in auth:
auth['id'] = auth['profile']['accounts'][0]['userid']
auth['provider'] = auth['profile']['accounts'][0]['domain']
View
4 apex/tests/__init__.py
@@ -35,7 +35,9 @@ def tearDownClass(cls):
#Base.metadata.drop_all(cls.engine)
def setUp(self):
- self.config = testing.setUp()
+ request = testing.DummyRequest()
+ self.config = testing.setUp(request=request)
+
self.config.add_route('home', '/')
self.config.add_settings(settings)
self.config.include('apex')
View
131 apex/tests/test_views.py
@@ -1,9 +1,10 @@
import os
import webob.multidict
+import apex.views
from pyramid import testing
-
from apex.tests import BaseTestCase
+from apex.lib.libapex import create_user
here = os.path.abspath(os.path.dirname(__file__))
@@ -11,16 +12,14 @@
hostname isn't defined.
"""
environ = {
- 'HTTP_HOST':'test.com',
- 'SERVER_NAME':'test.com',
+ 'HTTP_HOST': 'test.com',
+ 'SERVER_NAME': 'test.com',
+ 'REMOTE_ADDR': '127.0.0.1',
}
class Test_views(BaseTestCase):
def test_view_login(self):
- from apex.lib.libapex import create_user
- from apex.views import login
-
create_user(username='test', password='password')
request = testing.DummyRequest()
@@ -28,85 +27,155 @@ def test_view_login(self):
# wtforms requires this
request.POST = webob.multidict.MultiDict()
request.context = testing.DummyResource()
- response = login(request)
+ response = apex.views.login(request)
self.assertEqual(response['title'], 'You need to login')
- def test_simple_login(self):
- from apex.lib.libapex import create_user
- from apex.views import login
-
+ def test_login(self):
create_user(username='test', password='password')
request = testing.DummyRequest(environ=environ)
request.method = 'POST'
- # wtforms requires this
request.POST = webob.multidict.MultiDict()
- request.POST['username'] = 'test'
+ request.POST['login'] = 'test'
request.POST['password'] = 'password'
-
request.context = testing.DummyResource()
- response = login(request)
-
- # response object from dummy missing status_int
- #self.assertEqual(response.status_int, 302)
+ response = apex.views.login(request)
+ self.assertEqual(response.status, "302 Found")
def test_fail_login(self):
- from apex.lib.libapex import create_user
- from apex.views import login
-
create_user(username='test', password='password1')
request = testing.DummyRequest(environ=environ)
request.method = 'POST'
- # wtforms requires this
request.POST = webob.multidict.MultiDict()
- request.POST['username'] = 'test'
+ request.POST['login'] = 'test'
request.POST['password'] = 'password'
-
request.context = testing.DummyResource()
- response = login(request)
-
+ response = apex.views.login(request)
self.assertEqual(len(response['form'].errors), 1)
def test_logout(self):
""" need to import environ for SERVER_NAME and HOST_NAME
since we're dealing with cookies.
"""
- from apex.views import logout
-
request = testing.DummyRequest(environ=environ)
request.context = testing.DummyResource()
- response = logout(request)
+ response = apex.views.logout(request)
self.assertEqual('302 Found', response.status)
+ def test_change_password_fail(self):
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ # no user
+ self.assertRaises(AttributeError, apex.views.change_password, request)
+
def test_change_password(self):
pass
+ def test_forgot_password_fail(self):
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ response = apex.views.forgot_password(request)
+ self.assertEqual(len(response['form'].errors), 1)
+
def test_forgot_password(self):
pass
+ def test_reset_password_fail(self):
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ response = apex.views.reset_password(request)
+ self.assertEqual(len(response['form'].errors), 2)
+
def test_reset_password(self):
pass
+ def test_activate_fail(self):
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ response = apex.views.reset_password(request)
+ self.assertEqual(len(response['form'].errors), 2)
+
def test_activate(self):
pass
+ def test_register_fail(self):
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ response = apex.views.register(request)
+ self.assertEqual(len(response['form'].errors), 4)
+
def test_register(self):
- pass
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ request.POST['login'] = 'test'
+ request.POST['password'] = 'password'
+ request.POST['password2'] = 'password'
+ request.POST['email'] = 'mau@wau.de'
+ response = apex.views.register(request)
+ self.assertEqual(response.status, "302 Found")
+
+ def test_add_auth_fail(self):
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ response = apex.views.add_auth(request)
+ self.assertEqual(len(response['form'].errors), 4)
def test_add_auth(self):
pass
+ def test_apex_callback_fail(self):
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ request.POST['token'] = 'test'
+ response = apex.views.apex_callback(request)
+ self.assertEqual(response.status, "302 Found")
+
def test_apex_callback(self):
pass
+ def test_openid_required_fail(self):
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ self.assertRaises(AttributeError, apex.views.openid_required, request)
+
def test_openid_required(self):
pass
def test_forbidden(self):
- pass
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.matched_route = None
+ response = apex.views.forbidden(request)
+ # TODO return something != 200 OK
+ self.assertEqual(response.status, "200 OK")
+
+ def test_edit_fail(self):
+ request = testing.DummyRequest(environ=environ)
+ request.context = testing.DummyResource()
+ request.method = 'POST'
+ request.POST = webob.multidict.MultiDict()
+ self.assertRaises(AttributeError, apex.views.edit, request)
def test_edit(self):
pass
View
7 apex/views.py
@@ -302,7 +302,12 @@ def apex_callback(request):
route_url(apex_settings('came_from_route'), request))
headers = []
if 'token' in request.POST:
- auth = apex_id_from_token(request)
+ auth = None
+ try:
+ auth = apex_id_from_token(request)
+ except:
+ # TODO add logging
+ pass
if auth:
user = None
if not request.session.has_key('id'):
Please sign in to comment.
Something went wrong with that request. Please try again.