-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(usergroups): add unit tests against user groups module
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |