Beispiel #1
0
    def test_changes(self):
        '''
        Test salt.states.user._changes
        '''
        mock_info = MagicMock(
            return_value={
                'uid': 5000,
                'gid': 5000,
                'groups': ['foo'],
                'home': '/home/foo',
                'fullname': 'Foo Bar',
            })
        shadow_info = MagicMock(return_value={
            'min': 2,
            'max': 88888,
            'inact': 77,
            'warn': 14,
        })
        shadow_hash = MagicMock(return_value='abcd')
        dunder_salt = {
            'user.info': mock_info,
            'shadow.info': shadow_info,
            'shadow.default_hash': shadow_hash,
            'file.group_to_gid': MagicMock(side_effect=['foo']),
            'file.gid_to_group': MagicMock(side_effect=[5000])
        }

        def mock_exists(*args):
            return True

        # side_effect used because these mocks should only be called once
        with patch.dict(user.__grains__, {'kernel': 'Linux'}), \
                patch.dict(user.__salt__, dunder_salt), \
                patch.dict(user.__opts__, {"test": False}), \
                patch('os.path.isdir', mock_exists):
            ret = user._changes('foo', maxdays=999999, inactdays=0, warndays=7)
            assert ret == {
                'maxdays': 999999,
                'mindays': 0,
                'fullname': '',
                'warndays': 7,
                'inactdays': 0
            }
Beispiel #2
0
    def test_changes(self):
        """
        Test salt.states.user._changes
        """
        mock_info = MagicMock(
            return_value={
                "uid": 5000,
                "gid": 5000,
                "groups": ["foo"],
                "home": "/home/foo",
                "fullname": "Foo Bar",
            })
        shadow_info = MagicMock(return_value={
            "min": 2,
            "max": 88888,
            "inact": 77,
            "warn": 14
        })
        shadow_hash = MagicMock(return_value="abcd")
        dunder_salt = {
            "user.info": mock_info,
            "shadow.info": shadow_info,
            "shadow.default_hash": shadow_hash,
            "file.group_to_gid": MagicMock(side_effect=["foo"]),
            "file.gid_to_group": MagicMock(side_effect=[5000]),
        }

        def mock_exists(*args):
            return True

        # side_effect used because these mocks should only be called once
        with patch.dict(user.__grains__, {"kernel": "Linux"}), patch.dict(
                user.__salt__, dunder_salt), patch.dict(
                    user.__opts__,
                    {"test": False}), patch("os.path.isdir", mock_exists):
            ret = user._changes("foo", maxdays=999999, inactdays=0, warndays=7)
            assert ret == {
                "maxdays": 999999,
                "mindays": 0,
                "fullname": "",
                "warndays": 7,
                "inactdays": 0,
            }