PrintContext

Pretty-print the contents of the playbook context.

python · Common Scripts

Details

IDPrintContext
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10404775
TagsUtility

README

Pretty-prints the contents of the playbook context.

Script Data


Name Description
Script Type python
Tags Utility

Inputs


Argument Name Description
outputformat The output format. Can be, “table”, “json” or “markdown”. If omitted, the default is “markdown”.

Outputs


There are no outputs for this script.

import demistomock as demisto  # noqa: F401
import pytest
from CommonServerPython import *  # noqa: F401
from PrintContext import print_context

CONTEXT_DATA = [{"data1": 1}]


@pytest.mark.parametrize("expected_content, fmt, ctx", [(CONTEXT_DATA, "json", CONTEXT_DATA), ("Context empty.", "table", [])])
def test_print_context(mocker, expected_content, fmt, ctx):
    """
    Given:
        - The script args.
    When:
        - Running the print_context function.
    Then:
        - Validating the outputs as expected.
    """
    results_mock = mocker.patch.object(demisto, "results")
    print_context(fmt, ctx)
    res = results_mock.call_args[0][0]
    assert expected_content == res


@pytest.mark.parametrize(
    "expected_content, fmt, ctx",
    [
        ("**Context data**:\n```\n", "markdown", CONTEXT_DATA),
    ],
)
def test_print_context_markdown(mocker, expected_content, fmt, ctx):
    """
    Given:
        - The script args.
    When:
        - Running the print_context function.
    Then:
        - Validating the outputs as expected.
    """
    results_mock = mocker.patch.object(demisto, "results")
    print_context(fmt, ctx)
    res = results_mock.call_args[0][0]["Contents"]
    assert expected_content in res