1
0

test_pw_user.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  4. tests.integration.modules.pw_user
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. """
  7. from __future__ import absolute_import, print_function, unicode_literals
  8. from tests.support.case import ModuleCase
  9. from tests.support.helpers import (
  10. destructiveTest,
  11. random_string,
  12. runs_on,
  13. skip_if_not_root,
  14. )
  15. @runs_on(kernel="FreeBSD")
  16. class PwUserModuleTest(ModuleCase):
  17. @destructiveTest
  18. @skip_if_not_root
  19. def test_groups_includes_primary(self):
  20. # Let's create a user, which usually creates the group matching the name
  21. uname = random_string("PWU-", lowercase=False)
  22. if self.run_function("user.add", [uname]) is not True:
  23. # Skip because creating is not what we're testing here
  24. self.run_function("user.delete", [uname, True, True])
  25. self.skipTest("Failed to create user")
  26. try:
  27. uinfo = self.run_function("user.info", [uname])
  28. self.assertIn(uname, uinfo["groups"])
  29. # This uid is available, store it
  30. uid = uinfo["uid"]
  31. self.run_function("user.delete", [uname, True, True])
  32. # Now, a weird group id
  33. gname = random_string("PWU-", lowercase=False)
  34. if self.run_function("group.add", [gname]) is not True:
  35. self.run_function("group.delete", [gname, True, True])
  36. self.skipTest("Failed to create group")
  37. ginfo = self.run_function("group.info", [gname])
  38. # And create the user with that gid
  39. if self.run_function("user.add", [uname, uid, ginfo["gid"]]) is False:
  40. # Skip because creating is not what we're testing here
  41. self.run_function("user.delete", [uname, True, True])
  42. self.skipTest("Failed to create user")
  43. uinfo = self.run_function("user.info", [uname])
  44. self.assertIn(gname, uinfo["groups"])
  45. except AssertionError:
  46. self.run_function("user.delete", [uname, True, True])
  47. raise