Add tests for delete tasks

This commit raises coverage for ldaptasks.tasks to 100% by adding tests
for delete_ldap_group, delete_ldap_group_if_empty and delete_ldap_user
tasks.
This commit is contained in:
Jan Dittberner 2016-02-02 18:31:37 +00:00
parent 67ccdbb7c8
commit 94aacf1398

View file

@ -15,6 +15,9 @@ from ldaptasks.tasks import (
add_ldap_user_to_group,
create_ldap_group,
create_ldap_user,
delete_ldap_group,
delete_ldap_group_if_empty,
delete_ldap_user,
remove_ldap_user_from_group,
set_ldap_user_password,
)
@ -211,3 +214,89 @@ class LdapTaskTestCase(TestCase):
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s', 'search_s', 'search_s'
])
def test_delete_ldap_user_existing(self):
res = delete_ldap_user('existing')
self.assertTrue(res)
self.assertNotIn(
'uid=existing,' + settings.USER_BASE_DN, self.ldapobj.directory)
self.assertNotIn('memberUid', self.ldapobj.directory[
'cn=existing,' + settings.GROUP_BASE_DN])
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s', 'search_s', 'search_s',
'search_s', 'search_s', 'search_s', 'modify_s', 'delete_s'
])
def test_delete_ldap_user_missing(self):
res = delete_ldap_user('missing')
self.assertFalse(res)
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s'
])
def test_delete_ldap_user_no_group(self):
self.ldapobj.directory[
'uid=existing,' + settings.USER_BASE_DN]['gidNumber'] = ['5000']
res = delete_ldap_user('existing')
self.assertTrue(res)
self.assertNotIn(
'uid=existing,' + settings.USER_BASE_DN, self.ldapobj.directory)
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s', 'search_s', 'search_s',
'delete_s'
])
def test_delete_ldap_user_not_in_group(self):
del self.ldapobj.directory[
'cn=existing,' + settings.GROUP_BASE_DN]['memberUid']
res = delete_ldap_user('existing')
self.assertTrue(res)
self.assertNotIn(
'uid=existing,' + settings.USER_BASE_DN, self.ldapobj.directory)
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s', 'search_s', 'search_s',
'search_s', 'delete_s'
])
def test_delete_ldap_group_if_empty_nonempty(self):
res = delete_ldap_group_if_empty('existing')
self.assertFalse(res)
self.assertIn(
'cn=existing,' + settings.GROUP_BASE_DN, self.ldapobj.directory)
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s', 'search_s'
])
def test_delete_ldap_group_if_empty_missing(self):
res = delete_ldap_group_if_empty('missing')
self.assertFalse(res)
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s'
])
def test_delete_ldap_group_if_empty_empty(self):
del self.ldapobj.directory[
'cn=existing,' + settings.GROUP_BASE_DN]['memberUid']
res = delete_ldap_group_if_empty('existing')
self.assertTrue(res)
self.assertNotIn(
'cn=existing,' + settings.GROUP_BASE_DN, self.ldapobj.directory)
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s', 'search_s', 'delete_s'
])
def test_delete_ldap_group_existing(self):
res = delete_ldap_group('existing')
self.assertTrue(res)
self.assertNotIn(
'cn=existing,' + settings.GROUP_BASE_DN, self.ldapobj.directory)
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s', 'search_s', 'delete_s'
])
def test_delete_ldap_group_missing(self):
res = delete_ldap_group('missing')
self.assertFalse(res)
self.assertEqual(self.ldapobj.methods_called(), [
'initialize', 'simple_bind_s', 'search_s'
])