forked from sqlobject/sqlobject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_exceptions.py
More file actions
36 lines (27 loc) · 1.04 KB
/
Copy pathtest_exceptions.py
File metadata and controls
36 lines (27 loc) · 1.04 KB
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
import pytest
from sqlobject import SQLObject, StringCol
from sqlobject.dberrors import DuplicateEntryError, ProgrammingError
from sqlobject.tests.dbtest import getConnection, raises, setupClass, supports
########################################
# Table aliases and self-joins
########################################
class SOTestException(SQLObject):
name = StringCol(unique=True, length=100)
class SOTestExceptionWithNonexistingTable(SQLObject):
pass
def test_exceptions():
if not supports("exceptions"):
pytest.skip("exceptions aren't supported")
setupClass(SOTestException)
SOTestException(name="test")
raises(DuplicateEntryError, SOTestException, name="test")
connection = getConnection()
if connection.module.__name__ != 'psycopg2':
return
SOTestExceptionWithNonexistingTable.setConnection(connection)
try:
list(SOTestExceptionWithNonexistingTable.select())
except ProgrammingError as e:
assert e.args[0].code == '42P01'
else:
assert False, "DID NOT RAISE"