def test_close_session():
    mock_spark_session = MagicMock()
    client = LivyClient(mock_spark_session)
    client.start()

    client.close_session()

    mock_spark_session.delete.assert_called_once_with()
Example #2
0
def test_close_session():
    mock_spark_session = MagicMock()
    client = LivyClient(mock_spark_session)
    client.start()

    client.close_session()

    mock_spark_session.delete.assert_called_once_with()
def test_kind():
    kind = "pyspark"
    mock_spark_session = MagicMock()
    language_mock = PropertyMock(return_value=kind)
    type(mock_spark_session).kind = language_mock
    client = LivyClient(mock_spark_session)
    client.start()

    l = client.kind

    assert l == kind
def test_execute_hive():
    mock_spark_session = MagicMock()
    client = LivyClient(mock_spark_session)
    client.start()
    command = "command"

    client.execute_hive(command)

    mock_spark_session.create_sql_context.assert_called_with()
    mock_spark_session.wait_for_idle.assert_called_with(3600)
    mock_spark_session.execute.assert_called_with('hiveContext.sql("{}").collect()'.format(command))
def test_execute_code():
    mock_spark_session = MagicMock()
    client = LivyClient(mock_spark_session)
    client.start()
    command = "command"

    client.execute(command)

    mock_spark_session.create_sql_context.assert_called_with()
    mock_spark_session.wait_for_idle.assert_called_with(3600)
    mock_spark_session.execute.assert_called_with(command)
def test_session_id():
    session_id = "0"
    mock_spark_session = MagicMock()
    session_id_mock = PropertyMock(return_value=session_id)
    type(mock_spark_session).id = session_id_mock
    client = LivyClient(mock_spark_session)
    client.start()

    i = client.session_id

    assert i == session_id
Example #7
0
def test_kind():
    kind = "pyspark"
    mock_spark_session = MagicMock()
    language_mock = PropertyMock(return_value=kind)
    type(mock_spark_session).kind = language_mock
    client = LivyClient(mock_spark_session)
    client.start()

    l = client.kind

    assert l == kind
Example #8
0
def test_execute_code():
    mock_spark_session = MagicMock()
    client = LivyClient(mock_spark_session)
    client.start()
    command = "command"

    client.execute(command)

    mock_spark_session.create_sql_context.assert_called_with()
    mock_spark_session.wait_for_idle.assert_called_with(3600)
    mock_spark_session.execute.assert_called_with(command)
Example #9
0
def test_session_id():
    session_id = "0"
    mock_spark_session = MagicMock()
    session_id_mock = PropertyMock(return_value=session_id)
    type(mock_spark_session).id = session_id_mock
    client = LivyClient(mock_spark_session)
    client.start()

    i = client.session_id

    assert i == session_id
def test_serialize():
    url = "url"
    username = "******"
    password = "******"
    connection_string = get_connection_string(url, username, password)
    http_client = MagicMock()
    http_client.connection_string = connection_string
    kind = Constants.session_kind_spark
    session_id = "-1"
    sql_created = False
    session = MagicMock()
    session.get_state.return_value = LivySessionState(session_id, connection_string, kind, sql_created)

    client = LivyClient(session)
    client.start()

    serialized = client.serialize()

    assert serialized["connectionstring"] == connection_string
    assert serialized["id"] == "-1"
    assert serialized["kind"] == kind
    assert serialized["sqlcontext"] == sql_created
    assert serialized["version"] == "0.0.0"
    assert len(serialized.keys()) == 5
Example #11
0
def test_serialize():
    url = "url"
    username = "******"
    password = "******"
    connection_string = get_connection_string(url, username, password)
    http_client = MagicMock()
    http_client.connection_string = connection_string
    kind = SESSION_KIND_SPARK
    session_id = "-1"
    sql_created = False
    session = MagicMock()
    session.get_state.return_value = LivySessionState(session_id, connection_string, kind, sql_created)

    client = LivyClient(session)
    client.start()

    serialized = client.serialize()

    assert serialized["connectionstring"] == connection_string
    assert serialized["id"] == "-1"
    assert serialized["kind"] == kind
    assert serialized["sqlcontext"] == sql_created
    assert serialized["version"] == "0.0.0"
    assert len(serialized.keys()) == 5
def test_start_creates_sql_context():
    mock_spark_session = MagicMock()
    client = LivyClient(mock_spark_session)
    client.start()
    mock_spark_session.create_sql_context.assert_called_with()
Example #13
0
def test_start_creates_sql_context():
    mock_spark_session = MagicMock()
    client = LivyClient(mock_spark_session)
    client.start()
    mock_spark_session.create_sql_context.assert_called_with()