Update function docs

This commit is contained in:
Shane Lee 2024-02-02 10:31:41 -07:00 committed by Pedro Algarvio
parent da2bf5ccd4
commit b1b0c37871
2 changed files with 28 additions and 22 deletions

View file

@ -193,7 +193,8 @@ def get_account_created(name):
:param str name: The username of the account
:return: The date/time the account was created (yyyy-mm-dd hh:mm:ss)
:return: The date/time the account was created (yyyy-mm-dd hh:mm:ss) or 0 if
the value is not defined
:rtype: str
:raises: CommandExecutionError on user not found or any other unknown error
@ -208,7 +209,7 @@ def get_account_created(name):
ret = _get_account_policy_data_value(name, "creationTime")
except CommandExecutionError as exc:
if "Value not found" in exc.message:
return 0
return "0"
else:
raise
@ -222,7 +223,8 @@ def get_last_change(name):
:param str name: The username of the account
:return: The date/time the account was modified (yyyy-mm-dd hh:mm:ss)
:return: The date/time the account was modified (yyyy-mm-dd hh:mm:ss) or 0
if the value is not defined
:rtype: str
:raises: CommandExecutionError on user not found or any other unknown error
@ -237,7 +239,7 @@ def get_last_change(name):
ret = _get_account_policy_data_value(name, "passwordLastSetTime")
except CommandExecutionError as exc:
if "Value not found" in exc.message:
return 0
return "0"
else:
raise
@ -251,8 +253,9 @@ def get_login_failed_count(name):
:param str name: The username of the account
:return: The number of failed login attempts
:rtype: int
:return: The number of failed login attempts. 0 may mean there are no failed
login attempts or the value is not defined
:rtype: str
:raises: CommandExecutionError on user not found or any other unknown error
@ -266,7 +269,7 @@ def get_login_failed_count(name):
ret = _get_account_policy_data_value(name, "failedLoginCount")
except CommandExecutionError as exc:
if "Value not found" in exc.message:
return 0
return "0"
else:
raise
return salt.utils.mac_utils.parse_return(ret)
@ -279,7 +282,7 @@ def get_login_failed_last(name):
:param str name: The username of the account
:return: The date/time of the last failed login attempt on this account
(yyyy-mm-dd hh:mm:ss)
(yyyy-mm-dd hh:mm:ss) or 0 if the value is not defined
:rtype: str
:raises: CommandExecutionError on user not found or any other unknown error
@ -294,7 +297,7 @@ def get_login_failed_last(name):
ret = _get_account_policy_data_value(name, "failedLoginTimestamp")
except CommandExecutionError as exc:
if "Value not found" in exc.message:
return 0
return "0"
else:
raise

View file

@ -1,6 +1,7 @@
"""
Unit Tests for the mac_desktop execution module.
"""
from datetime import datetime
import pytest
@ -13,11 +14,15 @@ pytestmark = [
]
def test_get_account_created():
@pytest.fixture
def zero_date():
return datetime.fromtimestamp(0).strftime("%Y-%m-%d %H:%M:%S")
def test_get_account_created(zero_date):
with patch.object(mac_shadow, "_get_account_policy_data_value", return_value="0"):
result = mac_shadow.get_account_created("junk")
expected = "1969-12-31 17:00:00"
assert result == expected
assert result == zero_date
def test_get_account_created_no_value():
@ -27,7 +32,7 @@ def test_get_account_created_no_value():
side_effect=CommandExecutionError("Value not found: creationTime"),
):
result = mac_shadow.get_account_created("junk")
expected = 0
expected = "0"
assert result == expected
@ -40,11 +45,10 @@ def test_get_account_created_error():
mac_shadow.get_account_created("junk")
def test_get_last_change():
def test_get_last_change(zero_date):
with patch.object(mac_shadow, "_get_account_policy_data_value", return_value="0"):
result = mac_shadow.get_last_change("junk")
expected = "1969-12-31 17:00:00"
assert result == expected
assert result == zero_date
def test_get_last_change_no_value():
@ -54,7 +58,7 @@ def test_get_last_change_no_value():
side_effect=CommandExecutionError("Value not found: creationTime"),
):
result = mac_shadow.get_last_change("junk")
expected = 0
expected = "0"
assert result == expected
@ -81,7 +85,7 @@ def test_get_login_failed_count_no_value():
side_effect=CommandExecutionError("Value not found: creationTime"),
):
result = mac_shadow.get_login_failed_count("junk")
expected = 0
expected = "0"
assert result == expected
@ -94,11 +98,10 @@ def test_get_login_failed_count_error():
mac_shadow.get_login_failed_count("junk")
def test_login_failed_last():
def test_login_failed_last(zero_date):
with patch.object(mac_shadow, "_get_account_policy_data_value", return_value="0"):
result = mac_shadow.get_login_failed_last("junk")
expected = "1969-12-31 17:00:00"
assert result == expected
assert result == zero_date
def test_get_login_failed_last_no_value():
@ -108,7 +111,7 @@ def test_get_login_failed_last_no_value():
side_effect=CommandExecutionError("Value not found: creationTime"),
):
result = mac_shadow.get_login_failed_last("junk")
expected = 0
expected = "0"
assert result == expected