Ejemplo n.º 1
0
def test_get_issue_and_attachments(mocker, get_attachments_arg,
                                   should_get_attachments):
    """
    Given:
        - Case A: That the user has set the get_attachments to 'true' as he wants to download attachments
        - Case B: That the user has set the get_attachments to 'false' as he does not want to download attachments
    When
        - Calling the get issue command
    Then
        - Ensure the demisto.results with file data is called
        - Ensure the demisto.results with file data is not called
    """
    from test_data.raw_response import GET_ISSUE_RESPONSE
    from JiraV2 import get_issue
    from requests import Response

    def jira_req_mock(method: str,
                      resource_url: str,
                      body: str = '',
                      link: bool = False,
                      resp_type: str = 'text',
                      headers: dict = None,
                      files: dict = None):

        response = Response()
        response.status_code = 200
        response._content = b'{"filename": "filename"}'

        if resource_url == 'rest/attachment/15451':
            return response
        elif resp_type == 'json':
            return GET_ISSUE_RESPONSE
        else:
            return type("RequestObjectNock", (OptionParser, object),
                        {"content": 'Some zip data'})

    mocker.patch("JiraV2.jira_req", side_effect=jira_req_mock)
    demisto_results_mocker = mocker.patch.object(demisto, 'results')
    get_issue('id', get_attachments=get_attachments_arg)
    if should_get_attachments:
        demisto_results_mocker.assert_called_once()
    else:
        demisto_results_mocker.assert_not_called()
Ejemplo n.º 2
0
def test_get_issue_outputs(mocker):
    """
    Given:
        - The issue ID.
    When
        - Running the get issue command.
    Then
        - Ensure the outputs as expected
    """
    from test_data.raw_response import GET_ISSUE_RESPONSE
    from test_data.expected_results import GET_ISSUE_OUTPUTS_RESULT
    from JiraV2 import get_issue

    mocker.patch('JiraV2.jira_req', return_value=GET_ISSUE_RESPONSE)

    _, outputs, _ = get_issue('id')

    assert outputs == GET_ISSUE_OUTPUTS_RESULT