forked from saltstack/salt
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes an issue with the user.shadow module where it would fail retrieving values that weren't set yet... last login for example. Also adds some tests
- Loading branch information
Showing
2 changed files
with
92 additions
and
18 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
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,69 @@ | ||
""" | ||
Unit Tests for the mac_desktop execution module. | ||
""" | ||
|
||
import pytest | ||
|
||
import salt.modules.mac_shadow as mac_shadow | ||
from salt.exceptions import CommandExecutionError | ||
from tests.support.mock import patch | ||
|
||
pytestmark = [ | ||
pytest.mark.skip_unless_on_darwin, | ||
] | ||
|
||
|
||
def test_get_account_created(): | ||
with patch("_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 | ||
|
||
|
||
def test_get_account_created_error(): | ||
with patch("_get_account_policy_data_value", side_effect=CommandExecutionError): | ||
result = mac_shadow.get_account_created("junk") | ||
expected = "Creation date not defined" | ||
assert result == expected | ||
|
||
|
||
def test_get_last_change(): | ||
with patch("_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 | ||
|
||
|
||
def test_get_last_change_error(): | ||
with patch("_get_account_policy_data_value", side_effect=CommandExecutionError): | ||
result = mac_shadow.get_last_change("junk") | ||
expected = "Password last set date/time undefined" | ||
assert result == expected | ||
|
||
|
||
def test_login_failed_count(): | ||
with patch("_get_account_policy_data_value", return_value=0): | ||
result = mac_shadow.get_login_failed_count("junk") | ||
expected = "0" | ||
assert result == expected | ||
|
||
|
||
def test_get_login_failed_count_error(): | ||
with patch("_get_account_policy_data_value", side_effect=CommandExecutionError): | ||
result = mac_shadow.get_login_failed_count("junk") | ||
expected = "Failed login count undefined" | ||
assert result == expected | ||
|
||
|
||
def test_login_failed_last(): | ||
with patch("_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 | ||
|
||
|
||
def test_get_login_failed_last_error(): | ||
with patch("_get_account_policy_data_value", side_effect=CommandExecutionError): | ||
result = mac_shadow.get_login_failed_last("junk") | ||
expected = "Last failed login undefined" | ||
assert result == expected |