Beispiel #1
0
def test_kql_connect_no_cs(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()
    check.is_true(kql_driver.loaded)
    with pytest.raises(MsticpyKqlConnectionError) as mp_ex:
        kql_driver.connect()
    check.is_in("no connection string", mp_ex.value.args)
Beispiel #2
0
def test_kql_query_success(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()
    kql_driver.connect(connection_str="la://connection")

    result_df = kql_driver.query("test query")
    check.is_instance(result_df, pd.DataFrame)
Beispiel #3
0
def test_kql_connect(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()
    check.is_true(kql_driver.loaded)

    kql_driver.connect(connection_str="la://connection")
    check.is_true(kql_driver.connected)
Beispiel #4
0
def test_kql_schema(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()
    kql_driver.connect(connection_str="la://connection")

    check.is_in("table1", kql_driver.schema)
    check.is_in("table2", kql_driver.schema)
    check.is_in("field1", kql_driver.schema["table1"])
Beispiel #5
0
def test_kql_connect_authn_exceptions(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()

    with pytest.raises(MsticpyKqlConnectionError) as mp_ex:
        kql_driver.connect(connection_str="la://connection+AuthenticationError")
    check.is_in("authentication failed", mp_ex.value.args)
    check.is_false(kql_driver.connected)
Beispiel #6
0
def test_kql_query_failed(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()
    kql_driver.connect(connection_str="la://connection")

    output = io.StringIO()
    with redirect_stdout(output):
        kql_driver.query("test query_failed")
    check.is_in("Warning - query did", output.getvalue())
Beispiel #7
0
def test_kql_query_no_table(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()
    kql_driver.connect(connection_str="la://connection")

    with pytest.raises(MsticpyNoDataSourceError) as mp_ex:
        query_source = {"args.table": "table3"}
        kql_driver.query("test query", query_source=query_source)

    check.is_in("table3 not found.", mp_ex.value.args)
Beispiel #8
0
def test_kql_query_partial(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()
    kql_driver.connect(connection_str="la://connection")

    output = io.StringIO()
    with redirect_stdout(output):
        result_df = kql_driver.query("test query_partial")
    check.is_instance(result_df, pd.DataFrame)
    check.is_in("Warning - query returned partial", output.getvalue())
Beispiel #9
0
def test_kql_query_failed(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()
    kql_driver.connect(connection_str="la://connection")

    with pytest.raises(MsticpyDataQueryError) as mp_ex:
        kql_driver.query("test query_failed")
    arg_str = "\n".join([str(arg) for arg in mp_ex.value.args])
    check.is_in("Query:", arg_str)
    check.is_in("test query_failed", arg_str)
    check.is_in("Query failed", arg_str)
    check.is_in(
        "https://msticpy.readthedocs.io/en/latest/DataAcquisition.html",
        arg_str)
Beispiel #10
0
def test_kql_connect_adal_exceptions(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()

    with pytest.raises(MsticpyKqlConnectionError) as mp_ex:
        kql_driver.connect(connection_str="la://connection+AdalErrorUnk")
    check.is_in("could not authenticate to tenant", mp_ex.value.args)
    check.is_false(kql_driver.connected)

    with pytest.raises(MsticpyKqlConnectionError) as mp_ex:
        kql_driver.connect(connection_str="la://connection+AdalErrorNR")
    check.is_in("could not authenticate to tenant", mp_ex.value.args)
    check.is_in("Full error", str(mp_ex.value.args))
    check.is_false(kql_driver.connected)

    with pytest.raises(MsticpyKqlConnectionError) as mp_ex:
        kql_driver.connect(connection_str="la://connection+AdalErrorPoll")
    check.is_in("authentication timed out", mp_ex.value.args)
    check.is_false(kql_driver.connected)
Beispiel #11
0
def test_kql_connect_kql_exceptions(get_ipython):
    """Check loaded true."""
    get_ipython.return_value = _MockIPython()
    kql_driver = KqlDriver()

    with pytest.raises(MsticpyKqlConnectionError) as mp_ex:
        kql_driver.connect(connection_str="la://connection+KqlErrorUnk")
    check.is_in("Kql response error", mp_ex.value.args)
    check.is_false(kql_driver.connected)

    with pytest.raises(MsticpyKqlConnectionError) as mp_ex:
        kql_driver.connect(
            connection_str="la://connection.workspace('1234').tenant(KqlErrorWS)"
        )
    check.is_in("unknown workspace", mp_ex.value.args)
    check.is_false(kql_driver.connected)

    with pytest.raises(MsticpyKqlConnectionError) as mp_ex:
        kql_driver.connect(
            connection_str="la://connection.workspace('1234').tenant(KqlEngineError)"
        )
    check.is_in("kql connection error", mp_ex.value.args)
    check.is_false(kql_driver.connected)