forked from PyMySQL/mysqlclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_errors.py
56 lines (41 loc) · 1.35 KB
/
test_errors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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(f"DROP TABLE {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)")