mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 02:54:29 +08:00
56
tests/test_errors.py
Normal file
56
tests/test_errors.py
Normal file
@ -0,0 +1,56 @@
|
||||
import pytest
|
||||
import MySQLdb.cursors
|
||||
from configdb import connection_factory
|
||||
|
||||
|
||||
_conns = []
|
||||
_tables = []
|
||||
|
||||
|
||||
def connect(**kwargs):
|
||||
conn = connection_factory(**kwargs)
|
||||
_conns.append(conn)
|
||||
return conn
|
||||
|
||||
|
||||
def teardown_function(function):
|
||||
if _tables:
|
||||
c = _conns[0]
|
||||
cur = c.cursor()
|
||||
for t in _tables:
|
||||
cur.execute("DROP TABLE {}".format(t))
|
||||
cur.close()
|
||||
del _tables[:]
|
||||
|
||||
for c in _conns:
|
||||
c.close()
|
||||
del _conns[:]
|
||||
|
||||
|
||||
def test_null():
|
||||
"""Inserting NULL into non NULLABLE column"""
|
||||
# https://github.com/PyMySQL/mysqlclient/issues/535
|
||||
table_name = "test_null"
|
||||
conn = connect()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute(f"create table {table_name} (c1 int primary key)")
|
||||
_tables.append(table_name)
|
||||
|
||||
with pytest.raises(MySQLdb.IntegrityError):
|
||||
cursor.execute(f"insert into {table_name} values (null)")
|
||||
|
||||
|
||||
def test_duplicated_pk():
|
||||
"""Inserting row with duplicated PK"""
|
||||
# https://github.com/PyMySQL/mysqlclient/issues/535
|
||||
table_name = "test_duplicated_pk"
|
||||
conn = connect()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute(f"create table {table_name} (c1 int primary key)")
|
||||
_tables.append(table_name)
|
||||
|
||||
cursor.execute(f"insert into {table_name} values (1)")
|
||||
with pytest.raises(MySQLdb.IntegrityError):
|
||||
cursor.execute(f"insert into {table_name} values (1)")
|
Reference in New Issue
Block a user