<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import grp <EOL> import pwd <EOL> from salttesting import TestCase , skipIf <EOL> from salttesting . helpers import ensure_in_syspath <EOL> from salttesting . mock import MagicMock , patch , NO_MOCK , NO_MOCK_REASON <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> from salt . modules import mac_user <EOL> from salt . exceptions import SaltInvocationError , CommandExecutionError <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class MacUserTestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> mac_user . __context__ = { } <EOL> mac_user . __grains__ = { } <EOL> mac_user . __salt__ = { } <EOL> mock_pwall = [ pwd . struct_passwd ( ( '<STR_LIT>' , '<STR_LIT:*>' , <NUM_LIT> , <NUM_LIT> , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> pwd . struct_passwd ( ( '<STR_LIT>' , '<STR_LIT:*>' , <NUM_LIT> , <NUM_LIT> , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> pwd . struct_passwd ( ( '<STR_LIT>' , '<STR_LIT:*>' , <NUM_LIT> , <NUM_LIT> , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) ] <EOL> mock_pwnam = pwd . struct_passwd ( ( '<STR_LIT>' , '<STR_LIT:*>' , <NUM_LIT> , <NUM_LIT> , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> mock_getgrgid = grp . struct_group ( ( '<STR_LIT>' , '<STR_LIT:*>' , <NUM_LIT> , [ ] ) ) <EOL> mock_getgrall = [ grp . struct_group ( ( '<STR_LIT>' , '<STR_LIT:*>' , <NUM_LIT> , [ ] ) ) , <EOL> grp . struct_group ( ( '<STR_LIT>' , '<STR_LIT:*>' , <NUM_LIT> , [ '<STR_LIT:root>' , '<STR_LIT>' ] ) ) ] <EOL> mock_info_ret = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT:test>' , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> } <EOL> @ skipIf ( True , '<STR_LIT>' ) <EOL> def test_flush_dscl_cache ( self ) : <EOL> pass <EOL> def test_dscl ( self ) : <EOL> '''<STR_LIT>''' <EOL> mac_mock = MagicMock ( return_value = { '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> with patch . dict ( mac_user . __salt__ , { '<STR_LIT>' : mac_mock } ) : <EOL> with patch . dict ( mac_user . __grains__ , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( <NUM_LIT:10> , <NUM_LIT:9> , <NUM_LIT:1> ) } ) : <EOL> self . assertEqual ( mac_user . _dscl ( [ '<STR_LIT:username>' , '<STR_LIT>' , <NUM_LIT> ] ) , <EOL> { '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_pwall ) ) <EOL> def test_first_avail_uid ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertEqual ( mac_user . _first_avail_uid ( ) , <NUM_LIT> ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_info_ret ) ) <EOL> def test_add_user_exists ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , mac_user . add , '<STR_LIT:test>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_add_whitespace ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( SaltInvocationError , mac_user . add , '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_add_uid_int ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( SaltInvocationError , mac_user . add , '<STR_LIT:foo>' , '<STR_LIT:foo>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_add_gid_int ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( SaltInvocationError , mac_user . add , '<STR_LIT:foo>' , <NUM_LIT:20> , '<STR_LIT:foo>' ) <EOL> def test_delete_whitespace ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( SaltInvocationError , mac_user . delete , '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_delete_user_exists ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertTrue ( mac_user . delete ( '<STR_LIT:foo>' ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_pwall ) ) <EOL> @ patch ( '<STR_LIT>' , <EOL> MagicMock ( return_value = [ '<STR_LIT>' ] ) ) <EOL> def test_getent ( self ) : <EOL> '''<STR_LIT>''' <EOL> ret = [ { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> } ] <EOL> self . assertEqual ( mac_user . getent ( ) , ret ) <EOL> def test_chuid_int ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( SaltInvocationError , mac_user . chuid , '<STR_LIT:foo>' , '<STR_LIT:foo>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_chuid_user_exists ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , mac_user . chuid , '<STR_LIT:foo>' , <NUM_LIT> ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_info_ret ) ) <EOL> def test_chuid_same_uid ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertTrue ( mac_user . chuid ( '<STR_LIT:foo>' , <NUM_LIT> ) ) <EOL> def test_chgid_int ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( SaltInvocationError , mac_user . chgid , '<STR_LIT:foo>' , '<STR_LIT:foo>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_chgid_user_exists ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , mac_user . chgid , '<STR_LIT:foo>' , <NUM_LIT> ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_info_ret ) ) <EOL> def test_chgid_same_gid ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertTrue ( mac_user . chgid ( '<STR_LIT:foo>' , <NUM_LIT> ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_chshell_user_exists ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , mac_user . chshell , <EOL> '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_info_ret ) ) <EOL> def test_chshell_same_shell ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertTrue ( mac_user . chshell ( '<STR_LIT:foo>' , '<STR_LIT>' ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_chhome_user_exists ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , mac_user . chhome , <EOL> '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_info_ret ) ) <EOL> def test_chhome_same_home ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertTrue ( mac_user . chhome ( '<STR_LIT:foo>' , '<STR_LIT>' ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_chfullname_user_exists ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , mac_user . chfullname , <EOL> '<STR_LIT:test>' , '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_info_ret ) ) <EOL> def test_chfullname_same_name ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertTrue ( mac_user . chfullname ( '<STR_LIT:test>' , '<STR_LIT>' ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = { } ) ) <EOL> def test_chgroups_user_exists ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , mac_user . chgroups , <EOL> '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_info_ret ) ) <EOL> def test_chgroups_bad_groups ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( SaltInvocationError , mac_user . chgroups , <EOL> '<STR_LIT:test>' , '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_info_ret ) ) <EOL> @ patch ( '<STR_LIT>' , <EOL> MagicMock ( return_value = ( '<STR_LIT>' , '<STR_LIT:root>' ) ) ) <EOL> def test_chgroups_same_desired ( self ) : <EOL> '''<STR_LIT>''' <EOL> mock_primary = MagicMock ( return_value = '<STR_LIT>' ) <EOL> with patch . dict ( mac_user . __salt__ , { '<STR_LIT>' : mock_primary } ) : <EOL> self . assertTrue ( mac_user . chgroups ( '<STR_LIT:test>' , '<STR_LIT>' ) ) <EOL> @ patch ( '<STR_LIT>' , <EOL> MagicMock ( return_value = [ '<STR_LIT>' ] ) ) <EOL> def test_info ( self ) : <EOL> '''<STR_LIT>''' <EOL> mock_pwnam = pwd . struct_passwd ( ( '<STR_LIT:test>' , '<STR_LIT:*>' , <NUM_LIT:0> , <NUM_LIT:0> , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ret = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT:test>' , '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:0> } <EOL> with patch ( '<STR_LIT>' , MagicMock ( return_value = mock_pwnam ) ) : <EOL> self . assertEqual ( mac_user . info ( '<STR_LIT:root>' ) , ret ) <EOL> @ patch ( '<STR_LIT>' , <EOL> MagicMock ( return_value = [ '<STR_LIT>' ] ) ) <EOL> def test_format_info ( self ) : <EOL> '''<STR_LIT>''' <EOL> data = pwd . struct_passwd ( ( '<STR_LIT>' , '<STR_LIT:*>' , <NUM_LIT> , <NUM_LIT> , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ret = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> } <EOL> self . assertEqual ( mac_user . _format_info ( data ) , ret ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_pwall ) ) <EOL> def test_list_users ( self ) : <EOL> '''<STR_LIT>''' <EOL> ret = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( mac_user . list_users ( ) , ret ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( MacUserTestCase , needs_daemon = False ) </s>
