def test_fetch_incidents_no_incidents(mocker): """ Given - Jira fetch incidents command When - Sending HTTP request and getting no issues from the query Then - Verify no incidents are returned """ from JiraV2 import fetch_incidents mocker.patch.object(demisto, "info") mocker.patch.object(demisto, "debug") mocker.patch("JiraV2.run_query", return_value={}) incidents = fetch_incidents( "status=Open AND labels=lies", id_offset=1, should_get_attachments=False, should_get_comments=False, should_mirror_in=False, should_mirror_out=False, comment_tag="", attachment_tag="", ) assert incidents == []
def test_fetch_incidents_no_incidents(mocker): """ Given - Jira fetch incidents command When - Sending HTTP request and getting no issues from the query Then - Verify no incidents are returned """ from JiraV2 import fetch_incidents mocker.patch.object(demisto, "info") mocker.patch.object(demisto, "debug") mocker.patch("JiraV2.run_query", return_value={}) mocker.patch.object(demisto, 'setLastRun') incidents = fetch_incidents( "status=Open AND labels=lies", id_offset=1, should_get_attachments=False, should_get_comments=False, should_mirror_in=False, should_mirror_out=False, comment_tag="", attachment_tag="", ) assert incidents == [] assert demisto.setLastRun.call_count == 1 lastRun = demisto.setLastRun.call_args[0][0] assert lastRun == {'idOffset': 0, 'lastCreatedTime': ''}
def test_fetch_incident_with_getting_attachments_and_comments(mocker): """ Given: - Fetch parameters When - Incidents needs to include both attachments and comments. Then - Returned all fetched incidents with their attachments and comments. """ from JiraV2 import fetch_incidents from test_data.raw_response import QUERY_ISSUE_RESPONSE from test_data.expected_results import GET_JIRA_ISSUE_RES mocker.patch.object(demisto, "info") mocker.patch.object(demisto, "debug") mocker.patch("JiraV2.run_query", return_value=QUERY_ISSUE_RESPONSE) mocker.patch.object( demisto, "params", return_value={ "fetch_attachments": True, "fetch_comments": True, "id_offset": "17803", "query": "status!=done", }, ) mocker.patch( "JiraV2.get_comments_command", return_value=( "", "", { "comments": [{ "updated": "2071-12-21 12:29:05.529000+00:00" }] }, ), ) mocker.patch( "JiraV2.get_attachments", return_value=[{ "FileID": 1, "File": "name", "Type": "file" }], ) mocker.patch("JiraV2.get_issue", return_value=("", "", GET_JIRA_ISSUE_RES)) res = fetch_incidents( "status!=done", id_offset=1, should_get_attachments=True, should_get_comments=True, should_mirror_in=False, should_mirror_out=False, comment_tag="", attachment_tag="", ) assert list(res[0]["attachment"][0].keys()) == ["path", "name"] assert len(res[0]["labels"][12]["value"]) > 0
def test_fetch_incident_with_comments_when_exception_is_raised(mocker): """ Given: - Fetch parameters When - Incidents needs to include comments and there is an exception raised. Then - Returned all fetched incidents without their comments. """ from JiraV2 import fetch_incidents from test_data.raw_response import QUERY_ISSUE_RESPONSE mocker.patch.object(demisto, "info") mocker.patch.object(demisto, "debug") mocker.patch("JiraV2.run_query", return_value=QUERY_ISSUE_RESPONSE) mocker.patch.object( demisto, "params", return_value={ "fetch_attachments": True, "fetch_comments": True, "id_offset": "17803", "query": "status!=done", }, ) mocker.patch( "JiraV2.get_comments_command", return_value=( "", "", { "comments": [{ "updated": "2071-12-21 12:29:05.529000+00:00" }] }, ), ) mocker.patch( "JiraV2.get_issue", return_value=TimeoutError, ) res = fetch_incidents( "status!=done", id_offset=1, should_get_attachments=False, should_get_comments=True, should_mirror_in=False, should_mirror_out=False, comment_tag="", attachment_tag="", ) assert res[0]["labels"][12]["value"] == "[]"
def test_fetch_incident_mirror_direction(mocker): """ Given: - Fetch parameters When - Incidents needs to include Which direction to mirror its data- test 'Both' in this case. Then - Returned all fetched incidents without 'mirror_direction' set to 'Both'. """ from JiraV2 import fetch_incidents from test_data.raw_response import QUERY_ISSUE_RESPONSE from test_data.expected_results import GET_JIRA_ISSUE_RES import json mocker.patch.object(demisto, "info") mocker.patch.object(demisto, "debug") mocker.patch("JiraV2.run_query", return_value=QUERY_ISSUE_RESPONSE) mocker.patch.object( demisto, "params", return_value={ "fetch_attachments": True, "fetch_comments": True, "id_offset": "17803", "query": "status!=done", }, ) mocker.patch( "JiraV2.get_comments_command", return_value=( "", "", { "comments": [{ "updated": "2071-12-21 12:29:05.529000+00:00" }] }, ), ) mocker.patch("JiraV2.get_issue", return_value=("", "", GET_JIRA_ISSUE_RES)) res = fetch_incidents( "status!=done", id_offset=1, should_get_attachments=False, should_get_comments=True, should_mirror_in=True, should_mirror_out=True, comment_tag="", attachment_tag="", ) assert json.loads(res[0]["rawJSON"])["mirror_direction"] == "Both"
def test_fetch_incidents_no_incidents(mocker): """ Given - Jira fetch incidents command When - Sending HTTP request and getting no issues from the query Then - Verify no incidents are returned """ from JiraV2 import fetch_incidents mocker.patch('JiraV2.run_query', return_value={}) incidents = fetch_incidents('status=Open AND labels=lies', id_offset=1) assert incidents == []
def test_fetch_incidents_with_incidents_and_full_last_run(mocker): """ Given - Jira fetch incidents command - Last run is populated with idOffset and lastCreatedTime When - Sending HTTP request and getting new issue Then - Verify last run is updated with the ticket id offset and are updated """ from JiraV2 import fetch_incidents from test_data.raw_response import QUERY_ISSUE_RESPONSE mocker.patch.object(demisto, "info") mocker.patch.object(demisto, "debug") mocker.patch("JiraV2.run_query", return_value=QUERY_ISSUE_RESPONSE) mocker.patch.object(demisto, 'setLastRun') mocker.patch.object(demisto, 'getLastRun', return_value={ 'idOffset': 1000, 'lastCreatedTime': '2019-04-04T00:55:22.743+0300' }) incidents = fetch_incidents( "status=Open AND labels=lies", id_offset=1, should_get_attachments=False, should_get_comments=False, should_mirror_in=False, should_mirror_out=False, comment_tag="", attachment_tag="", ) assert len(incidents) == 1 assert demisto.setLastRun.call_count == 1 last_run = demisto.setLastRun.call_args[0][0] assert last_run == { 'idOffset': 12652, 'lastCreatedTime': '2019-05-04T00:44:31.743+0300' }