-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_postgres.py
More file actions
82 lines (56 loc) · 2.01 KB
/
Copy pathtest_postgres.py
File metadata and controls
82 lines (56 loc) · 2.01 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import pytest
from sqlobject import SQLObject, StringCol, IntCol
from sqlobject.sqlbuilder import Select, SOME
from sqlobject.tests.dbtest import getConnection, setupClass
########################################
# Test PosgreSQL sslmode
########################################
try:
connection = getConnection()
except (AttributeError, NameError):
# The module was imported during documentation building
pass
else:
if connection.dbName != "postgres":
pytestmark = pytest.mark.skip("These tests require PostgreSQL")
class SOTestSSLMode(SQLObject):
test = StringCol()
def test_sslmode():
setupClass(SOTestSSLMode)
connection = SOTestSSLMode._connection
if (not connection.module.__name__.startswith('psycopg')) or \
(os.name == 'nt'):
pytest.skip("The test requires PostgreSQL, psycopg and ssl mode; "
"also it doesn't work on w32")
connection = getConnection(sslmode='require')
SOTestSSLMode._connection = connection
test = SOTestSSLMode(test='test') # Connect to the DB to test sslmode
connection.cache.clear()
test = SOTestSSLMode.select()[0]
assert test.test == 'test'
########################################
# Test PosgreSQL list{Database,Tables}
########################################
class SOTestSOList(SQLObject):
pass
def test_list_databases():
assert connection.db in connection.listDatabases()
def test_list_tables():
setupClass(SOTestSOList)
assert SOTestSOList.sqlmeta.table in connection.listTables()
class SOTestSOME(SQLObject):
value = IntCol()
def test_SOME():
setupClass(SOTestSOME)
SOTestSOME(value=10)
SOTestSOME(value=20)
SOTestSOME(value=30)
assert len(list(SOTestSOME.select(
SOTestSOME.q.value > SOME(Select([SOTestSOME.q.value]))))) == 2
class SOTestPgidSize(SQLObject):
class sqlmeta:
idSize = 'BIG'
def test_idSize():
assert 'id BIGSERIAL PRIMARY KEY' \
in SOTestPgidSize.createTableSQL(connection=connection)[0]