test_pw_user.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. import pytest
  9. from tests.support.case import ModuleCase
  10. from tests.support.helpers import random_string
  11. @pytest.mark.skip_unless_on_freebsd
  12. class PwUserModuleTest(ModuleCase):
  13. @pytest.mark.destructive_test
  14. @pytest.mark.skip_if_not_root
  15. def test_groups_includes_primary(self):
  16. # Let's create a user, which usually creates the group matching the name
  17. uname = random_string("PWU-", lowercase=False)
  18. if self.run_function("user.add", [uname]) is not True:
  19. # Skip because creating is not what we're testing here
  20. self.run_function("user.delete", [uname, True, True])
  21. self.skipTest("Failed to create user")
  22. try:
  23. uinfo = self.run_function("user.info", [uname])
  24. self.assertIn(uname, uinfo["groups"])
  25. # This uid is available, store it
  26. uid = uinfo["uid"]
  27. self.run_function("user.delete", [uname, True, True])
  28. # Now, a weird group id
  29. gname = random_string("PWU-", lowercase=False)
  30. if self.run_function("group.add", [gname]) is not True:
  31. self.run_function("group.delete", [gname, True, True])
  32. self.skipTest("Failed to create group")
  33. ginfo = self.run_function("group.info", [gname])
  34. # And create the user with that gid
  35. if self.run_function("user.add", [uname, uid, ginfo["gid"]]) is False:
  36. # Skip because creating is not what we're testing here
  37. self.run_function("user.delete", [uname, True, True])
  38. self.skipTest("Failed to create user")
  39. uinfo = self.run_function("user.info", [uname])
  40. self.assertIn(gname, uinfo["groups"])
  41. except AssertionError:
  42. self.run_function("user.delete", [uname, True, True])
  43. raise