Пример #1
0
def test_pending_transaction_in_transaction():
    """Test transactional_update.pending_transaction when in transaction"""
    tu_in_transaction = "salt.modules.transactional_update.in_transaction"
    with patch(tu_in_transaction) as in_transaction_mock:
        in_transaction_mock.return_value = True
        with pytest.raises(CommandExecutionError):
            tu.pending_transaction()
Пример #2
0
    def test_pending_transaction(self):
        """Test transactional_update.pending_transaction"""
        matrix = (
            (False, ["1", "2+", "3-"], True),
            (False, ["1", "2-", "3+"], True),
            (False, ["1", "2", "3*"], False),
        )

        for in_transaction, snapshots, result in matrix:
            salt_mock = {
                "cmd.run_all":
                MagicMock(return_value={
                    "stdout": snapshots,
                    "retcode": 0
                })
            }

            tu_in_transaction = "salt.modules.transactional_update.in_transaction"
            with patch(tu_in_transaction) as in_transaction_mock:
                in_transaction_mock.return_value = in_transaction
                with patch.dict(tu.__salt__, salt_mock):
                    assert tu.pending_transaction() is result
                    salt_mock["cmd.run_all"].assert_called_with([
                        "snapper", "--no-dbus", "list", "--columns", "number"
                    ])