Here are the examples of the python api pytest.mark.hanatest taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
61 Examples
3
Example 1
Project: PyHDB Source File: test_lob.py
@pytest.mark.hanatest
def test_select_single_blob_row(connection, test_table, content_table):
cursor = connection.cursor()
row = cursor.execute("select name, fblob, fclob, fnclob from %s where name='lob0'" % TABLE).fetchone()
name, blob, clob, nclob = row
assert name == 'lob0'
assert isinstance(blob, lobs.Blob)
assert isinstance(clob, lobs.Clob)
assert isinstance(nclob, lobs.NClob)
assert blob.read() == b'blob0'
assert clob.read() == 'clob0'
assert nclob.read() == 'nclob0'
3
Example 2
Project: PyHDB Source File: test_lob.py
@pytest.mark.hanatest
def test_insert_single_blob_and_clob_row(connection, test_table):
"""Insert a single row providing blob (as string) and clob (as LOB obj) (argument order: blob, name, clob)"""
cursor = connection.cursor()
blob_data = b'ab \0x1 \0x17 yz'
clob_data = string.ascii_letters
clob_obj = lobs.Clob(clob_data)
cursor.execute("insert into %s (fblob, name, fclob) values (:1, :2, :3)" % TABLE, [blob_data, 'blob1', clob_obj])
blob, clob = cursor.execute("select fblob, fclob from %s where name='blob1' " % TABLE).fetchone()
assert blob.read() == blob_data
assert clob.read() == clob_data
3
Example 3
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_int(connection):
cursor = connection.cursor()
cursor.execute("SELECT 1 FROM DUMMY")
result = cursor.fetchone()
assert result == (1,)
3
Example 4
@pytest.mark.hanatest
def test_invalid_request(connection):
request = RequestMessage.new(
connection,
RequestSegment(2)
)
with pytest.raises(DatabaseError):
connection.send_request(request)
3
Example 5
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_binary(connection):
cursor = connection.cursor()
cursor.execute("SELECT X'FF00FFA3B5' FROM DUMMY")
result = cursor.fetchone()
assert result == (b"\xFF\x00\xFF\xA3\xB5",)
3
Example 6
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_executemany_python_expansion(connection, test_table_1):
cursor = connection.cursor()
cursor.executemany(
"INSERT INTO {} VALUES(%s)".format(TABLE),
(
("Statement 1",),
("Statement 2",)
)
)
cursor.execute("SELECT * FROM %s" % TABLE)
result = cursor.fetchall()
assert result == [('Statement 1',), ('Statement 2',)]
3
Example 7
Project: PyHDB Source File: test_lob.py
@pytest.mark.hanatest
def test_insert_single_string_clob_row(connection, test_table):
"""Insert a single row providing clob data in string format (argument order: name, clob)"""
cursor = connection.cursor()
clob_data = CLOB_DATA
cursor.execute("insert into %s (name, fclob) values (:1, :2)" % TABLE, ['clob1', clob_data])
clob = cursor.execute("select fclob from %s where name='clob1' " % TABLE).fetchone()[0]
assert clob.read() == clob_data
3
Example 8
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_execute_with_params4(connection, test_table_1, content_table_1):
"""Test format (positional) parameter expansion style"""
# Uses prepare_operation method
cursor = connection.cursor()
sql = 'select test from PYHDB_TEST_1 where test=%s'
# correct way:
assert cursor.execute(sql, ['row2']).fetchall() == [('row2',)]
# invalid - extra unexpected parameter
with pytest.raises(ProgrammingError):
cursor.execute(sql, ['row2', 'extra']).fetchall()
3
Example 9
@pytest.mark.hanatest
def test_insert_string(connection, test_table):
"""Insert string into table"""
cursor = connection.cursor()
large_string = ''.join(random.choice(string.ascii_letters) for _ in iter_range(5000))
cursor.execute("insert into %s (name) values (:1)" % TABLE, [large_string])
connection.commit()
cursor = connection.cursor()
row = cursor.execute('select name from %s' % TABLE).fetchone()
assert row[0] == large_string
3
Example 10
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_insert_commit(connection, test_table_1):
cursor = connection.cursor()
cursor.execute("SELECT COUNT(*) FROM %s" % TABLE)
assert cursor.fetchone() == (0,)
cursor.execute("INSERT INTO %s VALUES('Hello World')" % TABLE)
assert cursor.rowcount == 1
cursor.execute("SELECT COUNT(*) FROM %s" % TABLE)
assert cursor.fetchone() == (1,)
connection.commit()
3
Example 11
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_to_timestamp(connection):
now = datetime.datetime.now()
now = now.replace(microsecond=123000)
cursor = connection.cursor()
cursor.execute("SELECT to_timestamp(%s) FROM DUMMY", (now,))
result = cursor.fetchone()
assert result[0] == now
3
Example 12
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_to_time(connection):
now = datetime.datetime.now().time()
cursor = connection.cursor()
cursor.execute("SELECT to_time(%s) FROM DUMMY", (now,))
result = cursor.fetchone()
# No support of microsecond
assert result[0] == now.replace(microsecond=0)
3
Example 13
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_execute_raises_error_after_close(connection):
cursor = connection.cursor()
cursor.close()
with pytest.raises(ProgrammingError):
cursor.execute("SELECT TEST FROM DUMMY")
3
Example 14
@pytest.mark.hanatest
def test_isconnected(hana_system):
connection = Connection(*hana_system)
assert not connection.isconnected()
connection.connect()
assert connection.isconnected()
connection.close()
assert not connection.isconnected()
3
Example 15
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_execute_with_params1(connection, test_table_1, content_table_1):
"""Test qmark parameter expansion style - uses cursor.prepare*() methods"""
# Note: use fetchall() to check that only one row gets returned
cursor = connection.cursor()
sql = 'select test from PYHDB_TEST_1 where test=?'
# correct way:
assert cursor.execute(sql, ['row2']).fetchall() == [('row2',)]
# invalid - extra unexpected parameter
with pytest.raises(ProgrammingError):
cursor.execute(sql, ['row2', 'extra']).fetchall()
3
Example 16
Project: PyHDB Source File: test_lob.py
@pytest.mark.hanatest
def test_insert_single_string_blob_row(connection, test_table):
"""Insert a single row providing blob data in string format (argument order: name, blob)"""
cursor = connection.cursor()
blob_data = BLOB_DATA
cursor.execute("insert into %s (name, fblob) values (:1, :2)" % TABLE, ['blob1', blob_data])
blob = cursor.execute("select fblob from %s where name='blob1' " % TABLE).fetchone()[0]
assert blob.read() == blob_data
3
Example 17
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_IntegrityError_on_unique_constraint_violation(connection, test_table_1):
cursor = connection.cursor()
cursor.execute("ALTER TABLE %s ADD CONSTRAINT prim_key PRIMARY KEY (TEST)" % TABLE)
cursor.execute("INSERT INTO %s VALUES('Value 1')" % TABLE)
with pytest.raises(IntegrityError):
cursor.execute("INSERT INTO %s VALUES('Value 1')" % TABLE)
3
Example 18
@pytest.mark.hanatest
def test_insert_single_object_nclob_row(connection, test_table):
"""Insert a single row providing blob data as LOB object (argument order: nclob, name)"""
cursor = connection.cursor()
nclob_data = NCLOB_DATA
nclob_obj = lobs.NClob(nclob_data)
cursor.execute("insert into %s (fnclob, name) values (:1, :2)" % TABLE, [nclob_obj, 'nclob1'])
nclob = cursor.execute("select fnclob from %s where name='nclob1' " % TABLE).fetchone()[0]
assert nclob.read() == nclob_data
3
Example 19
Project: PyHDB Source File: test_connection.py
@pytest.mark.hanatest
def test_socket_use_init_timeout(hana_system):
connection = Connection(*hana_system, timeout=10)
connection.connect()
assert connection._socket.gettimeout() == 10
connection.close()
3
Example 20
Project: PyHDB Source File: test_lob.py
@pytest.mark.hanatest
def test_insert_two_large_lobs_via_writelob_requests(connection, test_table):
"""
Inserting BLOBs larger that MAX_SEGMENT_SIZE will split the upload to the DB into the normal INSERT
statement plus one or more WRITE_LOB requests.
Check that such a large BLOBs are written correctly.
"""
bigblob = os.urandom(2 * constants.MAX_SEGMENT_SIZE + 1000)
bigclob = ''.join(random.choice(string.ascii_letters) for x in iter_range(2 * constants.MAX_SEGMENT_SIZE))
cursor = connection.cursor()
cursor.execute("insert into %s (fblob, name, fclob) values (:1, :2, :3)" % TABLE, [bigblob, 'blob1', bigclob])
connection.commit()
cursor = connection.cursor()
row = cursor.execute("select fblob, fclob from %s where name=:1" % TABLE, ['blob1']).fetchone()
assert row[0].read() == bigblob
assert row[1].read() == bigclob
3
Example 21
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_string(connection):
cursor = connection.cursor()
cursor.execute("SELECT 'Hello World' FROM DUMMY")
result = cursor.fetchone()
assert result == ("Hello World",)
3
Example 22
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_long_string(connection):
test_string = '%030x' % random.randrange(16**300)
cursor = connection.cursor()
cursor.execute("SELECT '%s' FROM DUMMY" % test_string)
result = cursor.fetchone()
assert result == (test_string,)
3
Example 23
Project: PyHDB Source File: test_connection.py
@pytest.mark.hanatest
def test_set_timeout_update_socket_setting(connection):
assert connection.timeout is None
connection.timeout = 10
assert connection.timeout == 10
assert connection._socket.gettimeout() == 10
3
Example 24
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_current_time(connection):
cursor = connection.cursor()
cursor.execute("SELECT current_time FROM DUMMY")
result = cursor.fetchone()
assert isinstance(result[0], datetime.time)
3
Example 25
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_create_and_drop_table(connection):
cursor = connection.cursor()
if tests.helper.exists_table(connection, TABLE):
cursor.execute('DROP TABLE "%s"' % TABLE)
assert not tests.helper.exists_table(connection, TABLE)
cursor.execute('CREATE TABLE "%s" ("TEST" VARCHAR(255))' % TABLE)
assert tests.helper.exists_table(connection, TABLE)
cursor.execute('DROP TABLE "%s"' % TABLE)
3
Example 26
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_current_timestamp(connection):
cursor = connection.cursor()
cursor.execute("SELECT current_timestamp FROM DUMMY")
result = cursor.fetchone()
assert isinstance(result[0], datetime.datetime)
3
Example 27
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_current_date(connection):
cursor = connection.cursor()
cursor.execute("SELECT current_date FROM DUMMY")
result = cursor.fetchone()
assert isinstance(result[0], datetime.date)
3
Example 28
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
@pytest.mark.parametrize("method", [
'fetchone',
'fetchall',
'fetchmany',
])
def test_fetch_raises_error_after_close(connection, method):
cursor = connection.cursor()
cursor.close()
with pytest.raises(ProgrammingError):
getattr(cursor, method)()
3
Example 29
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_without_result(connection):
cursor = connection.cursor()
cursor.execute("SELECT 1 FROM DUMMY WHERE 1 != 1")
result = cursor.fetchone()
assert result is None
3
Example 30
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_fetchall_multiple_rows(connection):
cursor = connection.cursor()
cursor.execute('SELECT "VIEW_NAME" FROM "PUBLIC"."VIEWS" LIMIT 10')
result = cursor.fetchall()
assert len(result) == 10
3
Example 31
@pytest.mark.hanatest
def test_invalid_sql(connection):
cursor = connection.cursor()
with pytest.raises(DatabaseError):
cursor.execute("SELECT FROM DUMMY")
3
Example 32
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_description_after_execution(connection):
cursor = connection.cursor()
assert cursor.description is None
cursor.execute("SELECT 'Hello World' AS TEST FROM DUMMY")
assert cursor.description == ((u'TEST', 9, None, 11, 0, None, 0),)
3
Example 33
Project: PyHDB Source File: test_geometry.py
@pytest.mark.hanatest
def test_insert_point(connection, test_table_point):
"""Insert spatial point into table"""
cursor = connection.cursor()
point_x = random.randint(-100.0, 100.0)
point_y = random.randint(-100.0, 100.0)
wkt_string = "POINT(%f %f)" % (point_x, point_y)
cursor.execute("insert into %s (point) values (:1)" % TABLE_POINT, [wkt_string])
connection.commit()
cursor = connection.cursor()
row = cursor.execute('select point.ST_X(), point.ST_Y() from %s' % TABLE_POINT).fetchone()
assert row[0] == point_x
assert row[1] == point_y
3
Example 34
Project: PyHDB Source File: test_call_stored.py
@pytest.mark.hanatest
def test_proc_with_results(connection, procedure_with_result_fixture):
cursor = connection.cursor()
# prepare call
psid = cursor.prepare("CALL PYHDB_PROC_WITH_RESULT(?)")
ps = cursor.get_prepared_statement(psid)
# execute prepared statement
cursor.execute_prepared(ps, [{'OUTVAR': 0}])
result = cursor.fetchall()
assert result == [(2015,)]
cursor.close()
3
Example 35
Project: PyHDB Source File: test_lob.py
@pytest.mark.hanatest
def test_select_single_null_blob_row(connection, test_table, content_table):
cursor = connection.cursor()
row = cursor.execute("select name, fblob, fclob, fnclob from %s where name='nulls'" % TABLE).fetchone()
name, blob, clob, nclob = row
assert name == 'nulls'
assert blob is None
assert clob is None
assert nclob is None
3
Example 36
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_executemany_hana_expansion(connection, test_table_1):
cursor = connection.cursor()
cursor.executemany(
"INSERT INTO %s VALUES(:1)" % TABLE,
(
("Statement 1",),
("Statement 2",)
)
)
cursor.execute("SELECT * FROM %s" % TABLE)
result = cursor.fetchall()
assert result == [('Statement 1',), ('Statement 2',)]
3
Example 37
Project: PyHDB Source File: test_lob.py
@pytest.mark.hanatest
def test_insert_single_object_blob_row(connection, test_table):
"""Insert a single row providing blob data as LOB object (argument order: blob, name)"""
cursor = connection.cursor()
blob_data = b'ab \0x1 \0x17 yz'
blob_obj = lobs.Blob(blob_data)
cursor.execute("insert into %s (fblob, name) values (:1, :2)" % TABLE, [blob_obj, 'blob1'])
blob = cursor.execute("select fblob from %s where name='blob1' " % TABLE).fetchone()[0]
assert blob.read() == blob_data
3
Example 38
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_execute_with_params2(connection, test_table_1, content_table_1):
"""Test numeric parameter expansion style - uses cursor.prepare() methods"""
# Note: use fetchall() to check that only one row gets returned
cursor = connection.cursor()
sql = 'select test from PYHDB_TEST_1 where test=?'
# correct way:
assert cursor.execute(sql, ['row2']).fetchall() == [('row2',)]
# invalid - extra unexpected parameter
with pytest.raises(ProgrammingError):
cursor.execute(sql, ['row2', 'extra']).fetchall()
3
Example 39
Project: PyHDB Source File: test_lob.py
@pytest.mark.hanatest
def test_insert_single_object_clob_row(connection, test_table):
"""Insert a single row providing clob data in string format (argument order: name, clob)"""
cursor = connection.cursor()
clob_data = CLOB_DATA
clob_obj = lobs.Clob(clob_data)
cursor.execute("insert into %s (name, fclob) values (:1, :2)" % TABLE, ['clob1', clob_obj])
clob = cursor.execute("select fclob from %s where name='clob1' " % TABLE).fetchone()[0]
assert clob.read() == clob_data
3
Example 40
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_prepared_decimal(connection, test_table_2):
cursor = connection.cursor()
cursor.execute("INSERT INTO PYHDB_TEST_2(TEST) VALUES(?)", [Decimal("3.14159265359")])
cursor.execute("SELECT * FROM PYHDB_TEST_2")
result = cursor.fetchall()
assert result == [(Decimal("3.14159265359"),)]
3
Example 41
@pytest.mark.hanatest
def test_insert_single_object_nclob_row(connection, test_table):
"""Insert a single row providing nclob data as LOB object (argument order: nclob, name)"""
cursor = connection.cursor()
nclob_data = NCLOB_DATA
nclob_obj = lobs.NClob(nclob_data)
cursor.execute("insert into %s (fnclob, name) values (:1, :2)" % TABLE, [nclob_obj, 'nclob1'])
nclob = cursor.execute("select fnclob from %s where name='nclob1' " % TABLE).fetchone()[0]
assert nclob.read() == nclob_data
3
Example 42
Project: PyHDB Source File: test_connection.py
@pytest.mark.hanatest
@pytest.mark.parametrize("method", [
'close',
'commit',
'rollback',
'cursor',
])
def test_method_raises_error_after_close(hana_system, method):
connection = pyhdb.connect(*hana_system)
connection.close()
with pytest.raises(pyhdb.Error):
getattr(connection, method)()
3
Example 43
Project: PyHDB Source File: test_lob.py
@pytest.mark.hanatest
def test_insert_large_blob_via_writelob_requests(connection, test_table):
"""
Inserting a BLOB larger that MAX_SEGMENT_SIZE will split the upload to the DB into the normal INSERT
statement plus one or more WRITE_LOB requests.
Check that such a large BLOB is written correctly.
"""
bigblob = os.urandom(2 * constants.MAX_SEGMENT_SIZE + 1000)
cursor = connection.cursor()
cursor.execute("insert into %s (fblob, name) values (:1, :2)" % TABLE, [bigblob, 'blob1'])
connection.commit()
cursor = connection.cursor()
row = cursor.execute("select fblob from %s where name=:1" % TABLE, ['blob1']).fetchone()
assert row[0].read() == bigblob
3
Example 44
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_decimal(connection):
getcontext().prec = 36
cursor = connection.cursor()
cursor.execute("SELECT -312313212312321.1245678910111213142 FROM DUMMY")
result = cursor.fetchone()
assert result == (Decimal('-312313212312321.1245678910111213142'),)
3
Example 45
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_execute_with_params5(connection, test_table_1, content_table_1):
"""Test pyformat (named) parameter expansion style"""
# Note: use fetchall() to check that only one row gets returned
cursor = connection.cursor()
sql = 'select test from {} where test=%(test)s'.format(TABLE)
# correct way:
assert cursor.execute(sql, {'test': 'row2'}).fetchall() == [('row2',)]
# also correct way, additional dict value should just be ignored
assert cursor.execute(sql, {'test': 'row2', 'd': 2}).fetchall() == \
[('row2',)]
3
Example 46
Project: PyHDB Source File: test_call_stored.py
@pytest.mark.hanatest
def test_PROC_ADD2(connection, procedure_add2_fixture):
cursor = connection.cursor()
sql_to_prepare = 'call PYHDB_PROC_ADD2 (?, ?, ?, ?)'
params = [1, 2, None, None]
params = {'A':2, 'B':5, 'C':None, 'D': None}
psid = cursor.prepare(sql_to_prepare)
ps = cursor.get_prepared_statement(psid)
cursor.execute_prepared(ps, [params])
result = cursor.fetchall()
assert result == [(7, 'A')]
3
Example 47
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_cursor_fetchall_single_row(connection):
cursor = connection.cursor()
cursor.execute("SELECT 1 FROM DUMMY")
result = cursor.fetchall()
assert result == [(1,)]
3
Example 48
Project: PyHDB Source File: test_cursor.py
@pytest.mark.hanatest
def test_received_last_resultset_part_resets_after_execute(connection):
# The private attribute was not reseted to False after
# executing another statement
cursor = connection.cursor()
cursor.execute("SELECT 1 FROM DUMMY")
# Result is very small we got everything direct into buffer
assert cursor._received_last_resultset_part
cursor.execute("SELECT VIEW_NAME FROM PUBLIC.VIEWS")
# Result is not small enouth for single resultset part
assert not cursor._received_last_resultset_part
3
Example 49
Project: PyHDB Source File: test_dummy_sql.py
@pytest.mark.hanatest
def test_dummy_sql_to_date(connection):
today = datetime.date.today()
cursor = connection.cursor()
cursor.execute("SELECT to_date(%s) FROM DUMMY", (today,))
result = cursor.fetchone()
assert result[0] == today
0
Example 50
Project: PyHDB Source File: test_connection.py
@pytest.mark.hanatest
def test_fixture_connection(connection):
# Smoke test of the connection fixture
pass