From e8b06f5c2d340492600730d699022c578a6fd954 Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Sun, 22 Aug 2010 15:26:46 -0700 Subject: [PATCH] added black-box tests for auth, tweaked password login accordingly --- auth/auth_systems/password.py | 2 +- auth/bbtests.py | 5 ---- auth/tests.py | 45 ++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 7 deletions(-) delete mode 100644 auth/bbtests.py diff --git a/auth/auth_systems/password.py b/auth/auth_systems/password.py index 744012f..e9b6e0f 100644 --- a/auth/auth_systems/password.py +++ b/auth/auth_systems/password.py @@ -112,5 +112,5 @@ def update_status(token, message): def send_message(user_id, user_name, user_info, subject, body): if user_info.has_key('email'): email = user_info['email'] - name = user_info.get('name', email) + name = user_name or user_info.get('name', email) send_mail(subject, body, settings.SERVER_EMAIL, ["%s <%s>" % (name, email)], fail_silently=False) diff --git a/auth/bbtests.py b/auth/bbtests.py deleted file mode 100644 index 5c3da26..0000000 --- a/auth/bbtests.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -Black-box tests for Auth Systems - -2010-08-11 -""" diff --git a/auth/tests.py b/auth/tests.py index 072e070..b88220f 100644 --- a/auth/tests.py +++ b/auth/tests.py @@ -7,9 +7,14 @@ import models from django.db import IntegrityError, transaction +from django.test.client import Client +from django.test import TestCase + +from django.core import mail + from auth_systems import AUTH_SYSTEMS -class UserTests(unittest.TestCase): +class UserModelTests(unittest.TestCase): def setUp(self): pass @@ -72,3 +77,41 @@ class UserTests(unittest.TestCase): u2 = models.User.update_or_create(user_type = auth_system, user_id = 'foobar_eq', info={'name':'Foo Bar Status Update'}) self.assertEquals(u, u2) + + +import views +import auth_systems.password as password_views +from django.core.urlresolvers import reverse + +# FIXME: login CSRF should make these tests more complicated +# and should be tested for + +class UserBlackboxTests(TestCase): + + def setUp(self): + # create a bogus user + self.test_user = models.User.objects.create(user_type='password',user_id='foobar_user',name="Foobar User", info={'password':'foobaz', 'email':'foobar-test@adida.net'}) + + def test_password_login(self): + # get to the login page + login_page_response = self.client.get(reverse(views.start, kwargs={'system_name':'password'}), follow=True) + + # log in and follow all redirects + response = self.client.post(reverse(password_views.password_login_view), {'username' : 'foobar_user', 'password': 'foobaz'}, follow=True) + + self.assertContains(response, "logged in as") + self.assertContains(response, "Foobar User") + + def test_logout(self): + response = self.client.post(reverse(views.logout), follow=True) + + self.assertContains(response, "not logged in") + self.assertNotContains(response, "Foobar User") + + def test_email(self): + """using the test email backend""" + self.test_user.send_message("testing subject", "testing body") + + self.assertEquals(len(mail.outbox), 1) + self.assertEquals(mail.outbox[0].subject, "testing subject") + self.assertEquals(mail.outbox[0].to[0], "Foobar User <foobar-test@adida.net>") -- GitLab