aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Chatzimichos <tampakrap@gentoo.org>2013-08-10 23:30:39 +0200
committerTheo Chatzimichos <tampakrap@gentoo.org>2013-08-10 23:30:39 +0200
commit78083aeabd5bc1612d833604a887009af832f5e3 (patch)
tree32bf7da4bfa085711a5a2de711f67325a4fec34a /okupy/tests
parentImprove the test that checks if the correct templates are being used (diff)
downloadidentity.gentoo.org-78083aeabd5bc1612d833604a887009af832f5e3.tar.gz
identity.gentoo.org-78083aeabd5bc1612d833604a887009af832f5e3.tar.bz2
identity.gentoo.org-78083aeabd5bc1612d833604a887009af832f5e3.zip
Move accounts outside of the class
Diffstat (limited to 'okupy/tests')
-rw-r--r--okupy/tests/integration/login.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/okupy/tests/integration/login.py b/okupy/tests/integration/login.py
index b066c34..8f3ba7f 100644
--- a/okupy/tests/integration/login.py
+++ b/okupy/tests/integration/login.py
@@ -11,10 +11,15 @@ from ...common.test_helpers import OkupyTestCase
import mock
+
+account1 = {'username': 'alice', 'password': 'ldaptest'}
+account2 = {'username': 'bob', 'password': 'ldapmoretest'}
+wrong_account = {'username': 'wrong', 'password': 'wrong'}
+
+
class LoginTestsEmptyDB(OkupyTestCase):
cursor_wrapper = mock.Mock()
cursor_wrapper.side_effect = DatabaseError
- account = {'username': 'alice', 'password': 'ldaptest'}
@classmethod
def setUpClass(cls):
@@ -47,7 +52,7 @@ class LoginTestsEmptyDB(OkupyTestCase):
self.assertEqual(User.objects.count(), 0)
def test_correct_user(self):
- account = self.account.copy()
+ account = account1.copy()
account['next'] = ''
response = self.client.post('/login/', account)
self.assertRedirects(response, '/')
@@ -61,25 +66,25 @@ class LoginTestsEmptyDB(OkupyTestCase):
def test_no_ldap(self):
self.mockldap.stop()
- response = self.client.post('/login/', self.account)
+ response = self.client.post('/login/', account1)
self.assertMessage(response, 'Login failed', 40)
self.assertEqual(User.objects.count(), 0)
self.mockldap.start()
@mock.patch("django.db.backends.util.CursorWrapper", cursor_wrapper)
def test_no_database(self):
- response = self.client.post('/login/', self.account)
+ response = self.client.post('/login/', account1)
self.assertMessage(response, "Can't contact the LDAP server or the database", 40)
self.assertEqual(len(mail.outbox), 1)
self.assertTrue(mail.outbox[0].subject.startswith('%sERROR:' % settings.EMAIL_SUBJECT_PREFIX))
def test_already_authenticated_user_redirects_to_index(self):
- response = self.client.post('/login/', self.account)
+ response = self.client.post('/login/', account1)
response = self.client.get('/login/')
self.assertRedirects(response, '/')
def test_logout_for_logged_in_user(self):
- response = self.client.post('/login/', self.account)
+ response = self.client.post('/login/', account1)
response = self.client.get('/logout/')
self.assertRedirects(response, '/login/')
@@ -90,9 +95,6 @@ class LoginTestsEmptyDB(OkupyTestCase):
class LoginTestsOneAccountInDB(OkupyTestCase):
fixtures = ['alice']
- account1 = {'username': 'alice', 'password': 'ldaptest'}
- account2 = {'username': 'bob', 'password': 'ldapmoretest'}
-
@classmethod
def setUpClass(cls):
cls.mockldap = MockLdap(settings.DIRECTORY)
@@ -107,13 +109,13 @@ class LoginTestsOneAccountInDB(OkupyTestCase):
def test_dont_authenticate_from_db_when_ldap_is_down(self):
self.mockldap.stop()
- response = self.client.post('/login/', self.account1)
+ response = self.client.post('/login/', account1)
self.assertMessage(response, 'Login failed', 40)
self.assertEqual(User.objects.count(), 1)
self.mockldap.start()
def test_authenticate_account_that_is_already_in_db(self):
- response = self.client.post('/login/', self.account1)
+ response = self.client.post('/login/', account1)
self.assertRedirects(response, '/')
user = User.objects.get(pk=1)
self.assertEqual(User.objects.count(), 1)
@@ -124,7 +126,7 @@ class LoginTestsOneAccountInDB(OkupyTestCase):
self.assertEqual(user.email, '')
def test_authenticate_new_account(self):
- response = self.client.post('/login/', self.account2)
+ response = self.client.post('/login/', account2)
self.assertRedirects(response, '/')
self.assertEqual(User.objects.count(), 2)
user1 = User.objects.get(pk=1)