Always remove the users/groups added to the system

This commit is contained in:
Pedro Algarvio 2013-09-02 05:51:29 +01:00
parent 8d29140cdc
commit 7e57813243

View File

@ -38,32 +38,38 @@ class UseraddModuleTest(integration.ModuleCase):
uname = self.__random_string()
if self.run_function('user.add', [uname]) is not True:
# Skip because creating is not what we're testing here
self.run_function('user.delete', [uname, True, True])
self.skipTest('Failed to create user')
uinfo = self.run_function('user.info', [uname])
self.assertIn(uname, uinfo['groups'])
try:
uinfo = self.run_function('user.info', [uname])
self.assertIn(uname, uinfo['groups'])
# This uid is available, store it
uid = uinfo['uid']
# This uid is available, store it
uid = uinfo['uid']
self.run_function('user.delete', [uname, True, True])
self.run_function('user.delete', [uname, True, True])
# Now, a weird group id
gname = self.__random_string()
if self.run_function('group.add', [gname]) is not True:
self.skipTest('Failed to create group')
# Now, a weird group id
gname = self.__random_string()
if self.run_function('group.add', [gname]) is not True:
self.run_function('group.delete', [gname, True, True])
self.skipTest('Failed to create group')
ginfo = self.run_function('group.info', [gname])
ginfo = self.run_function('group.info', [gname])
# And create the user with that gid
if self.run_function('user.add', [uname, uid, ginfo['gid']]) is False:
# Skip because creating is not what we're testing here
self.skipTest('Failed to create user')
# And create the user with that gid
if self.run_function('user.add', [uname, uid, ginfo['gid']]) is False:
# Skip because creating is not what we're testing here
self.run_function('user.delete', [uname, True, True])
self.skipTest('Failed to create user')
uinfo = self.run_function('user.info', [uname])
self.assertIn(gname, uinfo['groups'])
uinfo = self.run_function('user.info', [uname])
self.assertIn(gname, uinfo['groups'])
self.run_function('user.delete', [uname, True, True])
except AssertionError:
self.run_function('user.delete', [uname, True, True])
raise
if __name__ == '__main__':