Skip to content

Commit

Permalink
tests(usergroups): add unit tests against user groups module
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Apr 22, 2024
1 parent ca95ad2 commit f03d07e
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/test_utils_user_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#! python3 # noqa E265

"""
Usage from the repo root folder:
.. code-block:: bash
# for whole tests
python -m unittest tests.test_user_groups
# for specific test
python -m unittest tests.test_user_groups.TestUtilsUserGroups.test_win32_getenv
"""

# standard library
import unittest
from getpass import getuser
from sys import platform as opersys

# project
from qgis_deployment_toolbelt.utils.user_groups import (
_is_computer_in_domain_powershell,
_is_computer_in_domain_pyad,
_is_computer_in_domain_win32,
get_user_local_groups,
is_computer_attached_to_a_domain,
is_user_in_group,
)

# ############################################################################
# ########## Classes #############
# ################################


class TestUtilsUserGroups(unittest.TestCase):
"""Test package utilities."""

def test_computer_attached_to_domain(self):
"""Test if the computer belongs to a domain."""
# for now, domain link is only supported on Windows
if opersys != "win32":
self.assertFalse(is_computer_attached_to_a_domain())

# test different methods on Windows but for now, no domain mocked in tests
# TODO: mock domain link
domain_status = is_computer_attached_to_a_domain()
self.assertIsInstance(domain_status, bool)

self.assertEqual(domain_status, _is_computer_in_domain_powershell())
self.assertEqual(domain_status, _is_computer_in_domain_pyad())
self.assertEqual(domain_status, _is_computer_in_domain_win32())

def test_user_in_group(self):
"""Test function determining user's groups."""
user_groups = get_user_local_groups()

# test with existing group
self.assertTrue(is_user_in_group(user_groups[0]))

# test with unisting group
self.assertFalse(is_user_in_group(group_name="fake_group", user_name=getuser()))


# ############################################################################
# ####### Stand-alone run ########
# ################################
if __name__ == "__main__":
unittest.main()

0 comments on commit f03d07e

Please sign in to comment.