Exemplo n.º 1
0
def test_get_violation_list_command(demisto_args, output, requests_mock, mocker, capfd):
    requests_mock.get(MOCK_URL + "/api/discovery/v1/violation/list", json=MOCK_ALL_VIOLATIONS)

    mock_demisto(mocker, demisto_args, "gamma-get-violation-list")
    with capfd.disabled():
        main()
    content = demisto.results.call_args[0][0]['Contents'][0]['violation_id']
    assert output == content
Exemplo n.º 2
0
def test_get_violation_command(requests_mock, mocker, capfd):
    requests_mock.get(
        MOCK_URL + "/api/discovery/v1/violation/list",
        json=MOCK_VIOLATION
    )

    args = {"violation": "2036"}
    mock_demisto(mocker, args, 'gamma-get-violation')
    with capfd.disabled():
        main()
    content = demisto.results.call_args[0][0]['Contents'][0]['violation_id']
    assert 2036 == content
Exemplo n.º 3
0
def test_main_get_violation_list(requests_mock, mocker, capfd):
    # Test fetch
    requests_mock.get(
        MOCK_URL + "/api/discovery/v1/violation/list",
        json=MOCK_ALL_VIOLATIONS
    )
    args = {'minimum_id': "2036", 'limit': "5"}
    command = 'gamma-get-violation-list'
    mock_demisto(mocker, args, command)
    with capfd.disabled():
        main()
    response = demisto.results.call_args[0][0]["Contents"]
    assert {2036, 5100} == {i["violation_id"] for i in response}
Exemplo n.º 4
0
def test_main_fetch_incidents(demisto_args, demisto_command, output_1, output_2,
                              requests_mock, mocker, capfd):
    # Test fetch
    requests_mock.get(
        MOCK_URL + "/api/discovery/v1/violation/list",
        json=MOCK_ALL_VIOLATIONS
    )
    mock_demisto(mocker, demisto_args, demisto_command)
    with capfd.disabled():
        main()
    contents = json.loads(demisto.results.call_args[0][0]["Contents"])
    assert output_1 == contents[0]["name"]
    assert output_2 == contents[1]["name"]
Exemplo n.º 5
0
def test_update_violation_command(demisto_args, demisto_command, output,
                                  requests_mock, mocker, capfd):
    test_violation = 5100
    requests_mock.put(MOCK_URL + f'/api/discovery/v1/violation/{test_violation}',
                      json=MOCK_VIOLATION_2)
    requests_mock.get(MOCK_URL + "/api/discovery/v1/violation/list",
                      json=MOCK_VIOLATION_2_UPDATED)

    mock_demisto(mocker, demisto_args, demisto_command)
    with capfd.disabled():
        main()
    contents = demisto.results.call_args[0][0]['Contents'][0]['violation_status']
    assert output == contents
Exemplo n.º 6
0
def test_main_get_bad_violation(mocker, requests_mock, capfd):
    requests_mock.get(
        MOCK_URL + "/api/discovery/v1/violation/list",
        json=MOCK_VIOLATION
    )

    # Test wrong ID
    command = "gamma-get-violation"
    args = {"violation": "5100"}
    mock_demisto(mocker, args, command)
    with pytest.raises(SystemExit):
        with capfd.disabled():
            main()
    assert demisto.results.call_args[0][0]['Contents'] == "Failed to execute gamma-get-violation " \
                                                          "command.\nError:\nViolation with this " \
                                                          "ID does not exist."