Exemple #1
0
def test_delete():
    """
    Test deleting an attribute from a file
    """
    with patch("os.path.exists") as exists_mock:
        expected = {
            "changes": {
                "key": "delete"
            },
            "comment": "",
            "name": "/path/to/file",
            "result": True,
        }

        exists_mock.return_value = True

        list_mock = MagicMock(return_value={"key": "value2"})
        delete_mock = MagicMock()
        with patch.dict(xattr.__salt__, {
                "xattr.list": list_mock,
                "xattr.delete": delete_mock
        }):
            out = xattr.delete("/path/to/file", ["key"])

            list_mock.assert_called_once_with("/path/to/file")
            delete_mock.assert_called_once_with("/path/to/file", "key")
            assert out == expected
Exemple #2
0
def test_delete_not():
    """
    Test deleting an attribute that doesn't exist from a file
    """
    with patch("os.path.exists") as exists_mock:
        expected = {
            "changes": {},
            "comment": "All attributes were already deleted.",
            "name": "/path/to/file",
            "result": True,
        }

        exists_mock.return_value = True

        list_mock = MagicMock(return_value={"other.key": "value2"})
        delete_mock = MagicMock()
        with patch.dict(xattr.__salt__, {
                "xattr.list": list_mock,
                "xattr.delete": delete_mock
        }):
            out = xattr.delete("/path/to/file", ["key"])

            list_mock.assert_called_once_with("/path/to/file")
            assert not delete_mock.called
            assert out == expected
Exemple #3
0
    def test_delete_not(self):
        '''
            Test deleting an attribute that doesn't exist from a file
        '''
        with patch('os.path.exists') as exists_mock:
            expected = {
                'changes': {},
                'comment': 'All attributes were already deleted.',
                'name': '/path/to/file',
                'result': True
            }

            exists_mock.return_value = True

            list_mock = MagicMock(return_value={'other.key': 'value2'})
            delete_mock = MagicMock()
            with patch.dict(xattr.__salt__, {
                    'xattr.list': list_mock,
                    'xattr.delete': delete_mock
            }):
                out = xattr.delete('/path/to/file', ['key'])

                list_mock.assert_called_once_with('/path/to/file')
                assert not delete_mock.called
                self.assertEqual(out, expected)
Exemple #4
0
    def test_delete(self, exists_mock):
        '''
            Test deleting an attribute from a file
        '''
        expected = {
            'changes': {
                'key': 'delete'
            },
            'comment': '',
            'name': '/path/to/file',
            'result': True
        }

        exists_mock.return_value = True

        list_mock = MagicMock(return_value={'key': 'value2'})
        delete_mock = MagicMock()
        with patch.dict(xattr.__salt__, {
                'xattr.list': list_mock,
                'xattr.delete': delete_mock
        }):
            out = xattr.delete('/path/to/file', ['key'])

            list_mock.assert_called_once_with('/path/to/file')
            delete_mock.assert_called_once_with('/path/to/file', 'key')
            self.assertEqual(out, expected)
    def test_delete(self, exists_mock):
        '''
            Test deleting an attribute from a file
        '''
        expected = {
            'changes': {'key': 'delete'},
            'comment': '',
            'name': '/path/to/file',
            'result': True
        }

        exists_mock.return_value = True

        list_mock = MagicMock(return_value={'key': 'value2'})
        delete_mock = MagicMock()
        with patch.dict(xattr.__salt__, {'xattr.list': list_mock,
                                         'xattr.delete': delete_mock}):
            out = xattr.delete('/path/to/file', ['key'])

            list_mock.assert_called_once_with('/path/to/file')
            delete_mock.assert_called_once_with('/path/to/file', 'key')
            self.assertEqual(out, expected)
    def test_delete_not(self, exists_mock):
        '''
            Test deleting an attribute that doesn't exist from a file
        '''
        expected = {
            'changes': {},
            'comment': 'All attributes were already deleted.',
            'name': '/path/to/file',
            'result': True
        }

        exists_mock.return_value = True

        list_mock = MagicMock(return_value={'other.key': 'value2'})
        delete_mock = MagicMock()
        with patch.dict(xattr.__salt__, {'xattr.list': list_mock,
                                         'xattr.delete': delete_mock}):
            out = xattr.delete('/path/to/file', ['key'])

            list_mock.assert_called_once_with('/path/to/file')
            assert not delete_mock.called
            self.assertEqual(out, expected)