예제 #1
0
    def test_adduser(self):
        '''
        Tests if specified user gets added in the group.
        '''
        mock = MagicMock(return_value={'retcode': 0})
        with patch.dict(groupadd.__grains__, {'kernel': 'Linux'}):
            with patch.dict(groupadd.__salt__, {'cmd.retcode': mock}):
                self.assertFalse(groupadd.adduser('test', 'root'))

        with patch.dict(groupadd.__grains__, {'kernel': ''}):
            with patch.dict(groupadd.__salt__, {'cmd.retcode': mock}):
                self.assertFalse(groupadd.adduser('test', 'root'))
예제 #2
0
    def test_adduser(self):
        '''
        Tests if specified user gets added in the group.
        '''
        mock = MagicMock(return_value={'retcode': 0})
        with patch.dict(groupadd.__grains__, {'kernel': 'Linux'}):
            with patch.dict(groupadd.__salt__, {'cmd.retcode': mock}):
                self.assertFalse(groupadd.adduser('test', 'root'))

        with patch.dict(groupadd.__grains__, {'kernel': ''}):
            with patch.dict(groupadd.__salt__, {'cmd.retcode': mock}):
                self.assertFalse(groupadd.adduser('test', 'root'))
예제 #3
0
    def test_adduser(self):
        """
        Tests if specified user gets added in the group.
        """
        mock = MagicMock(return_value={"retcode": 0})
        with patch.dict(groupadd.__grains__, {"kernel": "Linux"}):
            with patch.dict(groupadd.__salt__, {"cmd.retcode": mock}):
                self.assertFalse(groupadd.adduser("test", "root"))

        with patch.dict(groupadd.__grains__, {"kernel": ""}):
            with patch.dict(groupadd.__salt__, {"cmd.retcode": mock}):
                self.assertFalse(groupadd.adduser("test", "root"))
예제 #4
0
    def test_adduser(self):
        '''
        Tests if specified user gets added in the group.
        '''
        os_version_list = [
            {
                'grains': {
                    'kernel': 'Linux',
                    'os_family': 'RedHat',
                    'osmajorrelease': '5'
                },
                'cmd': ('gpasswd', '-a', 'root', 'test')
            },
            {
                'grains': {
                    'kernel': 'Linux',
                    'os_family': 'Suse',
                    'osmajorrelease': '11'
                },
                'cmd': ('usermod', '-A', 'test', 'root')
            },
            {
                'grains': {
                    'kernel': 'Linux'
                },
                'cmd': ('gpasswd', '--add', 'root', 'test')
            },
            {
                'grains': {
                    'kernel': 'OTHERKERNEL'
                },
                'cmd': ('usermod', '-G', 'test', 'root')
            },
        ]

        for os_version in os_version_list:
            mock = MagicMock(return_value={'retcode': 0})
            with patch.dict(groupadd.__grains__, os_version['grains']):
                with patch.dict(groupadd.__salt__, {'cmd.retcode': mock}):
                    self.assertFalse(groupadd.adduser('test', 'root'))
                    groupadd.__salt__['cmd.retcode'].assert_called_once_with(
                        os_version['cmd'], python_shell=False)
예제 #5
0
    def test_adduser(self):
        """
        Tests if specified user gets added in the group.
        """
        os_version_list = [
            {
                "grains": {
                    "kernel": "Linux",
                    "os_family": "RedHat",
                    "osmajorrelease": "5",
                },
                "cmd": ["gpasswd", "-a", "root", "test"],
            },
            {
                "grains": {
                    "kernel": "Linux",
                    "os_family": "Suse",
                    "osmajorrelease": "11",
                },
                "cmd": ["usermod", "-A", "test", "root"],
            },
            {
                "grains": {
                    "kernel": "Linux"
                },
                "cmd": ["gpasswd", "--add", "root", "test"],
            },
            {
                "grains": {
                    "kernel": "OTHERKERNEL"
                },
                "cmd": ["usermod", "-G", "test", "root"],
            },
        ]

        for os_version in os_version_list:
            mock = MagicMock(return_value={"retcode": 0})
            with patch.dict(groupadd.__grains__, os_version["grains"]):
                with patch.dict(groupadd.__salt__, {"cmd.retcode": mock}):
                    self.assertFalse(groupadd.adduser("test", "root"))
                    groupadd.__salt__["cmd.retcode"].assert_called_once_with(
                        os_version["cmd"], python_shell=False)
예제 #6
0
    def test_adduser(self):
        """
        Tests if specified user gets added in the group.
        """
        os_version_list = [
            {
                "grains": {"kernel": "Linux", "os_family": "RedHat", "osmajorrelease": "5"},
                "cmd": ("gpasswd", "-a", "root", "test"),
            },
            {
                "grains": {"kernel": "Linux", "os_family": "Suse", "osmajorrelease": "11"},
                "cmd": ("usermod", "-A", "test", "root"),
            },
            {"grains": {"kernel": "Linux"}, "cmd": ("gpasswd", "--add", "root", "test")},
            {"grains": {"kernel": "OTHERKERNEL"}, "cmd": ("usermod", "-G", "test", "root")},
        ]

        for os_version in os_version_list:
            mock = MagicMock(return_value={"retcode": 0})
            with patch.dict(groupadd.__grains__, os_version["grains"]):
                with patch.dict(groupadd.__salt__, {"cmd.retcode": mock}):
                    self.assertFalse(groupadd.adduser("test", "root"))
                    groupadd.__salt__["cmd.retcode"].assert_called_once_with(os_version["cmd"], python_shell=False)