diff options
author | Pavlos Ratis <dastergon@gentoo.org> | 2013-09-20 07:34:10 -0700 |
---|---|---|
committer | Pavlos Ratis <dastergon@gentoo.org> | 2013-09-20 07:34:10 -0700 |
commit | daf0376753e54492765f6cb837a63f11551566d9 (patch) | |
tree | f74536811c9ab6e44f241e9da6372a5c18df839e | |
parent | Merge pull request #97 from dastergon/minor_fix_docs (diff) | |
parent | add tearDownClass (diff) | |
download | identity.gentoo.org-daf0376753e54492765f6cb837a63f11551566d9.tar.gz identity.gentoo.org-daf0376753e54492765f6cb837a63f11551566d9.tar.bz2 identity.gentoo.org-daf0376753e54492765f6cb837a63f11551566d9.zip |
Merge pull request #98 from dastergon/test_updates
Minor updates in tests
-rw-r--r-- | okupy/tests/integration/test_index.py | 7 | ||||
-rw-r--r-- | okupy/tests/integration/test_lists.py | 7 | ||||
-rw-r--r-- | okupy/tests/integration/test_login.py | 7 | ||||
-rw-r--r-- | okupy/tests/integration/test_settings.py | 7 | ||||
-rw-r--r-- | okupy/tests/integration/test_signup.py | 7 | ||||
-rw-r--r-- | okupy/tests/unit/test_auth.py | 9 | ||||
-rw-r--r-- | okupy/tests/unit/test_index.py | 7 | ||||
-rw-r--r-- | okupy/tests/unit/test_ldapuser.py | 13 | ||||
-rw-r--r-- | okupy/tests/unit/test_lists.py | 7 | ||||
-rw-r--r-- | okupy/tests/unit/test_login.py | 13 | ||||
-rw-r--r-- | okupy/tests/unit/test_secondary_password.py | 39 | ||||
-rw-r--r-- | okupy/tests/unit/test_signup.py | 17 |
12 files changed, 100 insertions, 40 deletions
diff --git a/okupy/tests/integration/test_index.py b/okupy/tests/integration/test_index.py index e2c754e..cec706d 100644 --- a/okupy/tests/integration/test_index.py +++ b/okupy/tests/integration/test_index.py @@ -13,13 +13,18 @@ class IndexIntegrationTests(TestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.client = Client() self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_redirect_to_login_for_anonymous(self): response = self.client.get('/') diff --git a/okupy/tests/integration/test_lists.py b/okupy/tests/integration/test_lists.py index a9ad99e..e6360a9 100644 --- a/okupy/tests/integration/test_lists.py +++ b/okupy/tests/integration/test_lists.py @@ -14,13 +14,18 @@ class ListsIntegrationTests(TestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.client = Client() self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_devlist_page_uses_correct_template(self): response = self.client.get('/devlist/') diff --git a/okupy/tests/integration/test_login.py b/okupy/tests/integration/test_login.py index f30c742..378c2e9 100644 --- a/okupy/tests/integration/test_login.py +++ b/okupy/tests/integration/test_login.py @@ -17,10 +17,15 @@ class LoginIntegrationTests(TestCase): def setUp(self): self.client = Client() self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj + + @classmethod + def tearDownClass(cls): + del cls.mockldap def test_login_page_uses_correct_template(self): response = self.client.get('/login/') diff --git a/okupy/tests/integration/test_settings.py b/okupy/tests/integration/test_settings.py index 3779e51..94ef620 100644 --- a/okupy/tests/integration/test_settings.py +++ b/okupy/tests/integration/test_settings.py @@ -13,13 +13,18 @@ class SettingsIntegrationTests(TestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.client = Client() self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_profile_settings_page_uses_correct_template(self): response = self.client.post('/login/', vars.LOGIN_ALICE) diff --git a/okupy/tests/integration/test_signup.py b/okupy/tests/integration/test_signup.py index 86041b5..64e8d50 100644 --- a/okupy/tests/integration/test_signup.py +++ b/okupy/tests/integration/test_signup.py @@ -13,13 +13,18 @@ class SignupIntegrationTests(TestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.client = Client() self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_signup_page_uses_correct_template(self): response = self.client.get('/signup/') diff --git a/okupy/tests/unit/test_auth.py b/okupy/tests/unit/test_auth.py index d514999..586987b 100644 --- a/okupy/tests/unit/test_auth.py +++ b/okupy/tests/unit/test_auth.py @@ -19,12 +19,17 @@ class AuthSSLUnitTests(TestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_valid_certificate_authenticates_alice(self): request = set_request(uri='/login') @@ -74,7 +79,7 @@ class AuthSSHUnitTests(TestCase): def setUp(self): self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() diff --git a/okupy/tests/unit/test_index.py b/okupy/tests/unit/test_index.py index b35d99a..9f71230 100644 --- a/okupy/tests/unit/test_index.py +++ b/okupy/tests/unit/test_index.py @@ -16,12 +16,17 @@ class IndexUnitTests(TestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_index_url_resolves_to_index_view(self): found = resolve('/') diff --git a/okupy/tests/unit/test_ldapuser.py b/okupy/tests/unit/test_ldapuser.py index 7dd2b5f..4ca821f 100644 --- a/okupy/tests/unit/test_ldapuser.py +++ b/okupy/tests/unit/test_ldapuser.py @@ -23,12 +23,17 @@ class LDAPUserUnitTests(TestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_return_unicode_username(self): alice = LDAPUser.objects.get(username='alice') @@ -39,7 +44,7 @@ class LDAPUserUnitTests(TestCase): secondary_password = Random.get_random_bytes(48) secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode( secondary_password)) - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(secondary_password_crypt) request = set_request('/', user=vars.USER_ALICE) request.session['secondary_password'] = cipher.encrypt( @@ -51,7 +56,7 @@ class LDAPUserUnitTests(TestCase): secondary_password = Random.get_random_bytes(48) secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode( secondary_password)) - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(secondary_password_crypt) request = set_request('/', user=vars.USER_ALICE) request.session['secondary_password'] = cipher.encrypt( @@ -102,7 +107,7 @@ class LDAPUserUnitTests(TestCase): secondary_password = Random.get_random_bytes(48) secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode( secondary_password)) - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(secondary_password_crypt) request = set_request('/', user=vars.USER_ALICE) request.session['secondary_password'] = cipher.encrypt( diff --git a/okupy/tests/unit/test_lists.py b/okupy/tests/unit/test_lists.py index d34e27c..8cdcb6f 100644 --- a/okupy/tests/unit/test_lists.py +++ b/okupy/tests/unit/test_lists.py @@ -15,12 +15,17 @@ class ListsUnitTests(OkupyTestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_devlist_url_resolves_to_lists_view(self): found = resolve('/devlist/') diff --git a/okupy/tests/unit/test_login.py b/okupy/tests/unit/test_login.py index b602d65..f781741 100644 --- a/okupy/tests/unit/test_login.py +++ b/okupy/tests/unit/test_login.py @@ -25,12 +25,17 @@ class LoginUnitTests(OkupyTestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_incorrect_user_raises_login_failed(self): request = set_request(uri='/login', post=vars.LOGIN_WRONG, @@ -86,14 +91,14 @@ class LoginUnitTests(OkupyTestCase): login(request) self.assertEqual(len(ldap_users( 'alice', - directory=self.ldapobject.directory)[1]['userPassword']), 2) + directory=self.ldapobj.directory)[1]['userPassword']), 2) self.assertEqual(len(request.session['secondary_password']), 48) def test_secondary_password_is_removed_in_logout(self): secondary_password = Random.get_random_bytes(48) secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode( secondary_password)) - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(secondary_password_crypt) request = set_request(uri='/login', post=vars.LOGIN_ALICE, user=vars.USER_ALICE) @@ -102,7 +107,7 @@ class LoginUnitTests(OkupyTestCase): logout(request) self.assertEqual(len(ldap_users( 'alice', - directory=self.ldapobject.directory)[1]['userPassword']), 1) + directory=self.ldapobj.directory)[1]['userPassword']), 1) class LoginUnitTestsNoLDAP(OkupyTestCase): diff --git a/okupy/tests/unit/test_secondary_password.py b/okupy/tests/unit/test_secondary_password.py index ff0a794..62c9890 100644 --- a/okupy/tests/unit/test_secondary_password.py +++ b/okupy/tests/unit/test_secondary_password.py @@ -20,12 +20,17 @@ class SecondaryPassword(TestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_secondary_password_gets_added_in_session(self): request = set_request(uri='/', user=vars.USER_ALICE) @@ -38,39 +43,39 @@ class SecondaryPassword(TestCase): set_secondary_password(request, 'ldaptest') self.assertEqual(len(ldap_users( 'alice', - directory=self.ldapobject.directory)[1]['userPassword']), 2) + directory=self.ldapobj.directory)[1]['userPassword']), 2) def test_remove_leftovers_before_adding_secondary_password(self): leftover = ldap_md5_crypt.encrypt('leftover_password') - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(leftover) request = set_request(uri='/', user=vars.USER_ALICE) set_secondary_password(request, 'ldaptest') self.assertNotIn(leftover, ldap_users( - 'alice', directory=self.ldapobject.directory)[1]['userPassword']) + 'alice', directory=self.ldapobj.directory)[1]['userPassword']) def test_dont_remove_primary_password_while_cleaning_leftovers(self): leftover = ldap_md5_crypt.encrypt('leftover_password') - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(leftover) request = set_request(uri='/', user=vars.USER_ALICE) set_secondary_password(request, 'ldaptest') self.assertTrue(ldap_md5_crypt.verify( 'ldaptest', ldap_users( 'alice', - directory=self.ldapobject.directory)[1]['userPassword'][0])) + directory=self.ldapobj.directory)[1]['userPassword'][0])) def test_dont_remove_unknown_hashes_while_cleaning_leftovers(self): leftover = ldap_md5_crypt.encrypt('leftover_password') - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(leftover) leftover2 = 'plain_leftover2' - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(leftover2) request = set_request(uri='/', user=vars.USER_ALICE) set_secondary_password(request, 'ldaptest') self.assertIn(leftover2, ldap_users( - 'alice', directory=self.ldapobject.directory)[1]['userPassword']) + 'alice', directory=self.ldapobj.directory)[1]['userPassword']) def test_session_and_ldap_secondary_passwords_match(self): request = set_request(uri='/', user=vars.USER_ALICE) @@ -79,26 +84,26 @@ class SecondaryPassword(TestCase): request.session['secondary_password'], 48)), ldap_users( 'alice', - directory=self.ldapobject.directory)[1]['userPassword'][1])) + directory=self.ldapobj.directory)[1]['userPassword'][1])) def test_remove_secondary_password_from_ldap(self): secondary_password = Random.get_random_bytes(48) secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode( secondary_password)) - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(secondary_password_crypt) request = set_request(uri='/', user=vars.USER_ALICE) request.session['secondary_password'] = cipher.encrypt( secondary_password) remove_secondary_password(request) self.assertNotIn(secondary_password_crypt, ldap_users( - 'alice', directory=self.ldapobject.directory)[1]['userPassword']) + 'alice', directory=self.ldapobj.directory)[1]['userPassword']) def test_dont_remove_primary_password_when_removing_secondary_passwd(self): secondary_password = Random.get_random_bytes(48) secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode( secondary_password)) - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(secondary_password_crypt) request = set_request(uri='/', user=vars.USER_ALICE) request.session['secondary_password'] = cipher.encrypt( @@ -106,19 +111,19 @@ class SecondaryPassword(TestCase): remove_secondary_password(request) self.assertTrue(ldap_md5_crypt.verify('ldaptest', ldap_users( 'alice', - directory=self.ldapobject.directory)[1]['userPassword'][0])) + directory=self.ldapobj.directory)[1]['userPassword'][0])) def test_dont_remove_unknown_hashes_when_removing_secondary_password(self): secondary_password = Random.get_random_bytes(48) secondary_password_crypt = ldap_md5_crypt.encrypt(b64encode( secondary_password)) - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append('unknown_hash') - self.ldapobject.directory[ldap_users('alice')[0]][ + self.ldapobj.directory[ldap_users('alice')[0]][ 'userPassword'].append(secondary_password_crypt) request = set_request(uri='/', user=vars.USER_ALICE) request.session['secondary_password'] = cipher.encrypt( secondary_password) remove_secondary_password(request) self.assertIn('unknown_hash', ldap_users( - 'alice', directory=self.ldapobject.directory)[1]['userPassword']) + 'alice', directory=self.ldapobj.directory)[1]['userPassword']) diff --git a/okupy/tests/unit/test_signup.py b/okupy/tests/unit/test_signup.py index 8009546..dc43c74 100644 --- a/okupy/tests/unit/test_signup.py +++ b/okupy/tests/unit/test_signup.py @@ -21,12 +21,17 @@ class SignupUnitTests(OkupyTestCase): def setUpClass(cls): cls.mockldap = MockLdap(vars.DIRECTORY) + @classmethod + def tearDownClass(cls): + del cls.mockldap + def setUp(self): self.mockldap.start() - self.ldapobject = self.mockldap[settings.AUTH_LDAP_SERVER_URI] + self.ldapobj = self.mockldap[settings.AUTH_LDAP_SERVER_URI] def tearDown(self): self.mockldap.stop() + del self.ldapobj def test_username_already_exists_in_ldap(self): _form = vars.SIGNUP_TESTUSER.copy() @@ -79,9 +84,9 @@ class SignupUnitTests(OkupyTestCase): request = set_request(activate_url, messages=True) activate(request, vars.QUEUEDUSER.encrypted_id) self.assertTrue(ldap_users(vars.QUEUEDUSER.username, - directory=self.ldapobject.directory)) + directory=self.ldapobj.directory)) ldap_account = ldap_users(vars.QUEUEDUSER.username, - directory=self.ldapobject.directory)[1] + directory=self.ldapobj.directory)[1] self.assertEqual(ldap_account['objectClass'], settings.AUTH_LDAP_USER_OBJECTCLASS) self.assertEqual(ldap_account['sn'][0], vars.QUEUEDUSER.last_name) @@ -181,14 +186,14 @@ class SignupUnitTests(OkupyTestCase): def test_add_first_user_in_empty_ldap_directory(self): vars.QUEUEDUSER.save() activate_url = '/activate/%s/' % vars.QUEUEDUSER.encrypted_id - self.ldapobject.directory = ldap_users(clean=True) + self.ldapobj.directory = ldap_users(clean=True) request = set_request(activate_url, messages=True) activate(request, vars.QUEUEDUSER.encrypted_id) self.assertTrue(ldap_users(vars.QUEUEDUSER.username, - directory=self.ldapobject.directory)) + directory=self.ldapobj.directory)) self.assertEqual(ldap_users( vars.QUEUEDUSER.username, - directory=self.ldapobject.directory)[1]['uidNumber'][0], '1') + directory=self.ldapobj.directory)[1]['uidNumber'][0], '1') class SignupunitTestsNoLDAP(OkupyTestCase): |