script-JiraChangeTransition

This script applies the transition supplied by the user from the Jira Transitions incident field. It gets the new Jira status after applying the transition and updates the Cortex XSOAR incident status.

python · Atlassian Jira

Details

IDscript-JiraChangeTransition
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10116658
Tagsfield-change-triggered

README

This script applies the transition supplied by the user from the Jira Transitions incident field. It gets the new Jira status after applying the transition and updates the Cortex XSOAR incident status.

Script Data


Name Description
Script Type python3
Tags field-change-triggered
Cortex XSOAR Version 5.0.0

Inputs


There are no inputs for this script.

Outputs


There are no outputs for this script.

from unittest.mock import MagicMock

import demistomock as demisto
import pytest
from CommonServerPython import *


def test_change_jira_transition():
    """Tests the order of the demisto.executeCommand, and checks if it was run with the correct arguments."""
    from ScriptJiraChangeTransition import apply_transition

    demisto.incidents = MagicMock(return_value=[{"dbotMirrorId": "1234", "CustomFields": {"jiratransitions": "To New Status"}}])
    execute_command_mocker = demisto.executeCommand = MagicMock(
        side_effect=[
            None,
            [{"Type": 1, "Contents": {"fields": {"status": {"name": "New Status"}, "updated": "2023-01-01"}}}],
            None,
            None,
            None,
            None,
        ]
    )
    apply_transition()
    call_args_list = execute_command_mocker.call_args_list
    assert call_args_list[0][0] == ("jira-edit-issue", {"issueId": "1234", "transition": "To New Status", "issue_id": "1234"})
    assert call_args_list[1][0] == ("jira-get-issue", {"issueId": "1234", "issue_id": "1234"})
    assert call_args_list[2][0] == ("setIncident", {"jirastatus": "New Status"})
    assert call_args_list[3][0] == ("setIncident", {"jirav3status": "New Status"})
    assert call_args_list[4][0] == ("setIncident", {"jiratransitions": "Select"})
    assert call_args_list[5][0] == ("setIncident", {"lastupdatetime": "2023-01-01"})


def test_new_status_not_found_error():
    """Tests that an error is returned when the new status cannot be extracted after executing the command
    !jira-get-issue.
    """
    from ScriptJiraChangeTransition import apply_transition

    demisto.incidents = MagicMock(return_value=[{"dbotMirrorId": "1234", "CustomFields": {"jiratransitions": "To New Status"}}])
    demisto.executeCommand = MagicMock(
        side_effect=[
            None,
            [{"Type": 1, "Contents": {"fields": {"status": {"dummy_key": "dummy value"}, "updated": "2023-01-01"}}}],
            None,
            None,
            None,
        ]
    )
    with pytest.raises(DemistoException) as e:
        apply_transition()
    assert "Could not find: the issue's status name" in str(e)


def test_new_updated_time_not_found_error():
    """Tests that an error is returned when the new updated time cannot be extracted after executing the command
    !jira-get-issue.
    """
    from ScriptJiraChangeTransition import apply_transition

    demisto.incidents = MagicMock(return_value=[{"dbotMirrorId": "1234", "CustomFields": {"jiratransitions": "To New Status"}}])
    demisto.executeCommand = MagicMock(
        side_effect=[None, [{"Type": 1, "Contents": {"fields": {"status": {"name": "New Status"}}}}], None, None, None]
    )
    with pytest.raises(DemistoException) as e:
        apply_transition()
    assert "could not find the issue's updated time" in str(e)