Exemplo n.º 1
0
def test_WebInspectScan_scan_complete_success(scan_mock, scan_override_mock, wi_config_mock, config_git_mock,
                                              get_status_mock, export_mock):
    # Given
    overrides = _setup_overrides()
    scan_object = WebInspectScan(overrides)
    scan_object._set_api(None, None)
    scan_object.scan_id = "test_guid"
    get_status_mock.return_value = 'complete'

    # When
    scan_object._scan()

    # Expect
    assert export_mock.call_count == 2
Exemplo n.º 2
0
def test_WebInspectScan_exit_gracefully_success(scan_mock, scan_override_mock, wi_config_mock, config_git_mock,
                                                       stop_scan_mock):
    # Given
    overrides = _setup_overrides()

    scan_object = WebInspectScan(overrides)
    scan_object._set_api(None, None)
    scan_object.scan_id = "scan_guid"  # this gets set when a scan is created - we're not creating a scan here.

    # When
    with pytest.raises(SystemExit):
        scan_object._exit_scan_gracefully("scan_guid")

    # Expect
    assert stop_scan_mock.call_count == 1
Exemplo n.º 3
0
def test_WebInspectScan_scan_failure_none_type_scan_status(scan_mock, scan_override_mock, wi_config_mock, config_git_mock,
                                              get_status_mock, log_mock):
    # Given
    overrides = _setup_overrides()
    scan_object = WebInspectScan(overrides)
    scan_object._set_api(None, None)
    scan_object.scan_id = "test_guid"
    get_status_mock.return_value = None  # Sometimes we got a None response - we want to exit on that(?)

    # When
    with pytest.raises(SystemExit):
        scan_object._scan()

    # Expect
    assert log_mock.call_count == 1
Exemplo n.º 4
0
def test_WebInspectScan_scan_bad_state_failure(scan_mock, scan_override_mock, wi_config_mock, config_git_mock,
                                              get_status_mock, log_mock):
    # Given
    overrides = _setup_overrides()
    scan_object = WebInspectScan(overrides)
    scan_object._set_api(None, None)
    scan_object.scan_id = "test_guid"
    get_status_mock.return_value = 'SomeRandomState'  # any non: Running, NotRunning, Complete state

    # When
    with pytest.raises(SystemExit):
        scan_object._scan()

    # Expect
    assert log_mock.call_count == 1
Exemplo n.º 5
0
def test_WebInspectScan_scan_not_running_failure(scan_mock, scan_override_mock,
                                                 wi_config_mock,
                                                 config_git_mock,
                                                 get_status_mock,
                                                 stop_scan_mock):
    # Given
    overrides = _setup_overrides()
    scan_object = WebInspectScan(overrides)
    scan_object._set_api(None, None)
    scan_object.scan_id = "test_guid"
    get_status_mock.return_value = 'notrunning'

    # When
    with pytest.raises(SystemExit):
        scan_object._scan()

    # Expect
    assert stop_scan_mock.call_count == 1
Exemplo n.º 6
0
def test_xml_parsing_success(scan_mock, scan_overrides_mock, wi_config_mock, config_mock, write_to_console_mock,
                             write_to_json_mock, element_tree_mock, get_time_mock):
    # Given
    overrides = _setup_overrides()
    scan_object = WebInspectScan(overrides)
    scan_object.scan_overrides.settings = 'litecart'
    scan_object.scan_id = "test_scan_id"
    scan_object.scan_overrides.scan_name = "test_scan_name"
    filename = "test.xml"
    scan_object.start_time = '2013-02-01 10:10:08'
    get_time_mock.side_effect = ['2013-02-01 10:11:08']

    #When
    scan_object.xml_parsing(filename)

    #Expect
    assert scan_mock.call_count == 1
    assert write_to_console_mock.call_count == 1
    assert write_to_json_mock.call_count == 1
    write_to_json_mock.assert_called_once_with('test.xml', 'test_scan_name', 'test_scan_id', '2013-02-01 10:10:08', '2013-02-01 10:11:08')
    write_to_console_mock.assert_called_once_with("test_scan_name")