sqlobject 3.13.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. sqlobject/__init__.py +15 -0
  2. sqlobject/__version__.py +8 -0
  3. sqlobject/boundattributes.py +124 -0
  4. sqlobject/cache.py +376 -0
  5. sqlobject/classregistry.py +138 -0
  6. sqlobject/col.py +2187 -0
  7. sqlobject/compat.py +59 -0
  8. sqlobject/conftest.py +64 -0
  9. sqlobject/constraints.py +77 -0
  10. sqlobject/converters.py +278 -0
  11. sqlobject/dbconnection.py +1137 -0
  12. sqlobject/dberrors.py +54 -0
  13. sqlobject/declarative.py +211 -0
  14. sqlobject/events.py +365 -0
  15. sqlobject/firebird/__init__.py +8 -0
  16. sqlobject/firebird/firebirdconnection.py +463 -0
  17. sqlobject/include/__init__.py +1 -0
  18. sqlobject/include/hashcol.py +109 -0
  19. sqlobject/include/tests/__init__.py +1 -0
  20. sqlobject/include/tests/test_hashcol.py +84 -0
  21. sqlobject/index.py +189 -0
  22. sqlobject/inheritance/__init__.py +551 -0
  23. sqlobject/inheritance/iteration.py +106 -0
  24. sqlobject/inheritance/tests/__init__.py +1 -0
  25. sqlobject/inheritance/tests/test_aggregates.py +23 -0
  26. sqlobject/inheritance/tests/test_asdict.py +48 -0
  27. sqlobject/inheritance/tests/test_deep_inheritance.py +114 -0
  28. sqlobject/inheritance/tests/test_destroy_cascade.py +23 -0
  29. sqlobject/inheritance/tests/test_foreignKey.py +94 -0
  30. sqlobject/inheritance/tests/test_indexes.py +42 -0
  31. sqlobject/inheritance/tests/test_inheritance.py +164 -0
  32. sqlobject/inheritance/tests/test_inheritance_tree.py +50 -0
  33. sqlobject/joins.py +656 -0
  34. sqlobject/main.py +1880 -0
  35. sqlobject/manager/__init__.py +1 -0
  36. sqlobject/manager/command.py +1309 -0
  37. sqlobject/maxdb/__init__.py +8 -0
  38. sqlobject/maxdb/maxdbconnection.py +320 -0
  39. sqlobject/maxdb/readme.txt +27 -0
  40. sqlobject/mssql/__init__.py +8 -0
  41. sqlobject/mssql/mssqlconnection.py +417 -0
  42. sqlobject/mysql/__init__.py +8 -0
  43. sqlobject/mysql/mysqlconnection.py +562 -0
  44. sqlobject/postgres/__init__.py +8 -0
  45. sqlobject/postgres/pgconnection.py +619 -0
  46. sqlobject/sqlbuilder.py +1655 -0
  47. sqlobject/sqlite/__init__.py +8 -0
  48. sqlobject/sqlite/sqliteconnection.py +418 -0
  49. sqlobject/sresults.py +377 -0
  50. sqlobject/styles.py +174 -0
  51. sqlobject/sybase/__init__.py +8 -0
  52. sqlobject/sybase/sybaseconnection.py +183 -0
  53. sqlobject/tests/__init__.py +1 -0
  54. sqlobject/tests/dbtest.py +363 -0
  55. sqlobject/tests/test_ForeignKey.py +133 -0
  56. sqlobject/tests/test_ForeignKey_cascade.py +150 -0
  57. sqlobject/tests/test_NoneValuedResultItem.py +33 -0
  58. sqlobject/tests/test_SQLMultipleJoin.py +65 -0
  59. sqlobject/tests/test_SQLRelatedJoin.py +114 -0
  60. sqlobject/tests/test_SingleJoin.py +30 -0
  61. sqlobject/tests/test_aggregates.py +75 -0
  62. sqlobject/tests/test_aliases.py +49 -0
  63. sqlobject/tests/test_asdict.py +18 -0
  64. sqlobject/tests/test_auto.py +218 -0
  65. sqlobject/tests/test_basic.py +359 -0
  66. sqlobject/tests/test_blob.py +34 -0
  67. sqlobject/tests/test_boundattributes.py +67 -0
  68. sqlobject/tests/test_cache.py +57 -0
  69. sqlobject/tests/test_class_hash.py +22 -0
  70. sqlobject/tests/test_columns_order.py +18 -0
  71. sqlobject/tests/test_combining_joins.py +47 -0
  72. sqlobject/tests/test_comparison.py +24 -0
  73. sqlobject/tests/test_compat.py +10 -0
  74. sqlobject/tests/test_complex_sorting.py +77 -0
  75. sqlobject/tests/test_constraints.py +43 -0
  76. sqlobject/tests/test_converters.py +276 -0
  77. sqlobject/tests/test_create_drop.py +29 -0
  78. sqlobject/tests/test_csvexport.py +101 -0
  79. sqlobject/tests/test_csvimport.py +21 -0
  80. sqlobject/tests/test_cyclic_reference.py +55 -0
  81. sqlobject/tests/test_datetime.py +171 -0
  82. sqlobject/tests/test_dbconnection.py +17 -0
  83. sqlobject/tests/test_decimal.py +63 -0
  84. sqlobject/tests/test_declarative.py +83 -0
  85. sqlobject/tests/test_default_style.py +65 -0
  86. sqlobject/tests/test_delete.py +74 -0
  87. sqlobject/tests/test_distinct.py +36 -0
  88. sqlobject/tests/test_empty.py +22 -0
  89. sqlobject/tests/test_enum.py +75 -0
  90. sqlobject/tests/test_events.py +142 -0
  91. sqlobject/tests/test_exceptions.py +40 -0
  92. sqlobject/tests/test_expire.py +29 -0
  93. sqlobject/tests/test_groupBy.py +45 -0
  94. sqlobject/tests/test_identity.py +29 -0
  95. sqlobject/tests/test_indexes.py +100 -0
  96. sqlobject/tests/test_inheritance.py +35 -0
  97. sqlobject/tests/test_joins.py +160 -0
  98. sqlobject/tests/test_joins_conditional.py +143 -0
  99. sqlobject/tests/test_jsonbcol.py +53 -0
  100. sqlobject/tests/test_jsoncol.py +56 -0
  101. sqlobject/tests/test_lazy.py +165 -0
  102. sqlobject/tests/test_md5.py +13 -0
  103. sqlobject/tests/test_mysql.py +50 -0
  104. sqlobject/tests/test_new_joins.py +165 -0
  105. sqlobject/tests/test_parse_uri.py +147 -0
  106. sqlobject/tests/test_paste.py +92 -0
  107. sqlobject/tests/test_perConnection.py +20 -0
  108. sqlobject/tests/test_pickle.py +42 -0
  109. sqlobject/tests/test_picklecol.py +44 -0
  110. sqlobject/tests/test_postgres.py +82 -0
  111. sqlobject/tests/test_reparent_sqlmeta.py +33 -0
  112. sqlobject/tests/test_schema.py +30 -0
  113. sqlobject/tests/test_select.py +218 -0
  114. sqlobject/tests/test_select_through.py +63 -0
  115. sqlobject/tests/test_setters.py +23 -0
  116. sqlobject/tests/test_slice.py +59 -0
  117. sqlobject/tests/test_sorting.py +80 -0
  118. sqlobject/tests/test_sqlbuilder.py +134 -0
  119. sqlobject/tests/test_sqlbuilder_dbspecific.py +66 -0
  120. sqlobject/tests/test_sqlbuilder_importproxy.py +55 -0
  121. sqlobject/tests/test_sqlbuilder_joins_instances.py +90 -0
  122. sqlobject/tests/test_sqlite.py +160 -0
  123. sqlobject/tests/test_sqlmeta_idName.py +52 -0
  124. sqlobject/tests/test_sqlobject_admin.py +38 -0
  125. sqlobject/tests/test_string_id.py +79 -0
  126. sqlobject/tests/test_style.py +36 -0
  127. sqlobject/tests/test_subqueries.py +142 -0
  128. sqlobject/tests/test_transactions.py +122 -0
  129. sqlobject/tests/test_unicode.py +84 -0
  130. sqlobject/tests/test_uuidcol.py +40 -0
  131. sqlobject/tests/test_validation.py +125 -0
  132. sqlobject/tests/test_views.py +159 -0
  133. sqlobject/util/__init__.py +1 -0
  134. sqlobject/util/csvexport.py +210 -0
  135. sqlobject/util/csvimport.py +366 -0
  136. sqlobject/util/moduleloader.py +35 -0
  137. sqlobject/util/threadinglocal.py +6 -0
  138. sqlobject/versioning/__init__.py +120 -0
  139. sqlobject/versioning/test/__init__.py +0 -0
  140. sqlobject/versioning/test/test_version.py +183 -0
  141. sqlobject/views.py +151 -0
  142. sqlobject/wsgi_middleware.py +109 -0
  143. sqlobject-3.13.1.data/scripts/sqlobject-admin +36 -0
  144. sqlobject-3.13.1.data/scripts/sqlobject-convertOldURI +19 -0
  145. sqlobject-3.13.1.dist-info/METADATA +177 -0
  146. sqlobject-3.13.1.dist-info/RECORD +149 -0
  147. sqlobject-3.13.1.dist-info/WHEEL +6 -0
  148. sqlobject-3.13.1.dist-info/entry_points.txt +4 -0
  149. sqlobject-3.13.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,147 @@
1
+ import os
2
+ from sqlobject.dbconnection import DBConnection
3
+ from sqlobject.sqlite.sqliteconnection import SQLiteConnection
4
+
5
+
6
+ ########################################
7
+ # Test _parseURI
8
+ ########################################
9
+
10
+
11
+ def test_parse():
12
+ _parseURI = DBConnection._parseURI
13
+
14
+ user, password, host, port, path, args = _parseURI("mysql://host/database")
15
+ assert user is None
16
+ assert password is None
17
+ assert host == "host"
18
+ assert port is None
19
+ assert path == "/database"
20
+ assert args == {}
21
+
22
+ user, password, host, port, path, args = _parseURI(
23
+ "mysql://user:pass%20word@host/database?unix_socket=/var/mysql/socket")
24
+ assert user == "user"
25
+ assert password == "pass word"
26
+ assert host == "host"
27
+ assert port is None
28
+ assert path == "/database"
29
+ assert args == {"unix_socket": "/var/mysql/socket"}
30
+
31
+ user, password, host, port, path, args = \
32
+ _parseURI("postgres://user@host/database")
33
+ assert user == "user"
34
+ assert password is None
35
+ assert host == "host"
36
+ assert port is None
37
+ assert path == "/database"
38
+ assert args == {}
39
+
40
+ user, password, host, port, path, args = \
41
+ _parseURI("postgres://host:5432/database")
42
+ assert user is None
43
+ assert password is None
44
+ assert host == "host"
45
+ assert port == 5432
46
+ assert path == "/database"
47
+ assert args == {}
48
+
49
+ user, password, host, port, path, args = \
50
+ _parseURI("postgres:///full/path/to/socket/database")
51
+ assert user is None
52
+ assert password is None
53
+ assert host is None
54
+ assert port is None
55
+ assert path == "/full/path/to/socket/database"
56
+ assert args == {}
57
+
58
+ user, password, host, port, path, args = \
59
+ _parseURI("postgres://us%3Aer:p%40ssword@host/database")
60
+ assert user == "us:er"
61
+ assert password == "p@ssword"
62
+ assert host == "host"
63
+ assert port is None
64
+ assert path == "/database"
65
+ assert args == {}
66
+
67
+ user, password, host, port, path, args = \
68
+ _parseURI("sqlite:///full/path/to/database")
69
+ assert user is None
70
+ assert password is None
71
+ assert host is None
72
+ assert port is None
73
+ assert path == "/full/path/to/database"
74
+ assert args == {}
75
+
76
+ user, password, host, port, path, args = _parseURI("sqlite:/:memory:")
77
+ assert user is None
78
+ assert password is None
79
+ assert host is None
80
+ assert port is None
81
+ assert path == "/:memory:"
82
+ assert args == {}
83
+
84
+ if os.name == 'nt':
85
+ user, password, host, port, path, args = \
86
+ _parseURI("sqlite:/C|/full/path/to/database")
87
+ assert user is None
88
+ assert password is None
89
+ assert host is None
90
+ assert port is None
91
+ assert path == "C:/full/path/to/database"
92
+ assert args == {}
93
+
94
+ user, password, host, port, path, args = \
95
+ _parseURI("sqlite:///C:/full/path/to/database")
96
+ assert user is None
97
+ assert password is None
98
+ assert host is None
99
+ assert port is None
100
+ assert path == "C:/full/path/to/database"
101
+ assert args == {}
102
+
103
+
104
+ def test_uri():
105
+ connection = DBConnection()
106
+ connection.close = lambda: None
107
+
108
+ connection.dbName, connection.host, connection.port, \
109
+ connection.user, connection.password, connection.db = \
110
+ 'mysql', 'host', None, None, None, 'database'
111
+ assert connection.uri() == "mysql://host/database"
112
+
113
+ connection.dbName, connection.host, connection.port, \
114
+ connection.user, connection.password, connection.db = \
115
+ 'mysql', 'host', None, 'user', 'pass word', 'database'
116
+ assert connection.uri() == "mysql://user:pass%20word@host/database"
117
+
118
+ connection.dbName, connection.host, connection.port, \
119
+ connection.user, connection.password, connection.db = \
120
+ 'postgres', 'host', None, 'user', None, 'database'
121
+ assert connection.uri() == "postgres://user@host/database"
122
+
123
+ connection.dbName, connection.host, connection.port, \
124
+ connection.user, connection.password, connection.db = \
125
+ 'postgres', 'host', 5432, None, None, 'database'
126
+ assert connection.uri() == "postgres://host:5432/database"
127
+
128
+ connection.dbName, connection.host, connection.port, \
129
+ connection.user, connection.password, connection.db = \
130
+ 'postgres', None, None, None, None, '/full/path/to/socket/database'
131
+ assert connection.uri() == "postgres:///full/path/to/socket/database"
132
+
133
+ connection.dbName, connection.host, connection.port, \
134
+ connection.user, connection.password, connection.db = \
135
+ 'postgres', 'host', None, 'us:er', 'p@ssword', 'database'
136
+ assert connection.uri() == "postgres://us%3Aer:p%40ssword@host/database"
137
+
138
+ connection = SQLiteConnection(None)
139
+ connection.filename = '/full/path/to/database'
140
+ assert connection.uri() == "sqlite:///full/path/to/database"
141
+
142
+ connection.filename = ':memory:'
143
+ assert connection.uri() == "sqlite:/:memory:"
144
+
145
+ if os.name == 'nt':
146
+ connection.filename = 'C:/full/path/to/database'
147
+ assert connection.uri() == "sqlite:///C%3A/full/path/to/database"
@@ -0,0 +1,92 @@
1
+ from __future__ import print_function
2
+ import pytest
3
+
4
+ from sqlobject import sqlhub, SQLObject, StringCol
5
+ try:
6
+ from sqlobject.wsgi_middleware import make_middleware
7
+ except ImportError:
8
+ pytestmark = pytest.mark.skipif(True, reason='These tests require Paste')
9
+ from .dbtest import getConnection, getConnectionURI, setupClass
10
+
11
+
12
+ class NameOnly(SQLObject):
13
+ name = StringCol()
14
+
15
+
16
+ def makeapp(abort=False, begin=False, fail=False):
17
+ def app(environ, start_response):
18
+ NameOnly(name='app1')
19
+ if fail == 'early':
20
+ assert 0
21
+ start_response('200 OK', [('content-type', 'text/plain')])
22
+ if begin:
23
+ environ['sqlobject.begin']()
24
+ NameOnly(name='app2')
25
+ if abort:
26
+ environ['sqlobject.abort']()
27
+ if fail:
28
+ assert 0
29
+ return ['ok']
30
+ return app
31
+
32
+
33
+ def makestack(abort=False, begin=False, fail=False, **kw):
34
+ app = makeapp(abort=abort, begin=begin, fail=fail)
35
+ app = make_middleware(app, {}, database=getConnectionURI(), **kw)
36
+ return app
37
+
38
+
39
+ def runapp(**kw):
40
+ print('-' * 8)
41
+ app = makestack(**kw)
42
+ env = {}
43
+
44
+ def start_response(*args):
45
+ pass
46
+
47
+ try:
48
+ list(app(env, start_response))
49
+ return True
50
+ except AssertionError:
51
+ return False
52
+
53
+
54
+ def setup():
55
+ setupClass(NameOnly)
56
+ getConnection().query('DELETE FROM name_only')
57
+ NameOnly._connection = sqlhub
58
+
59
+
60
+ def names():
61
+ names = [n.name for n in NameOnly.select(connection=getConnection())]
62
+ names.sort()
63
+ return names
64
+
65
+
66
+ def test_fail():
67
+ setup()
68
+ assert not runapp(fail=True, use_transaction=True)
69
+ assert names() == []
70
+ setup()
71
+ assert not runapp(fail=True, use_transaction=False)
72
+ assert names() == ['app1', 'app2']
73
+ setup()
74
+ assert not runapp(fail=True, begin=True, use_transaction=True)
75
+ assert names() == ['app1']
76
+
77
+
78
+ def test_other():
79
+ setup()
80
+ assert runapp(fail=False, begin=True, use_transaction=True)
81
+ assert names() == ['app1', 'app2']
82
+ setup()
83
+ # @@: Dammit, I can't get these to pass because I can't get the
84
+ # stupid table to clear itself. setupClass() sucks. When I
85
+ # fix it I'll take this disabling out:
86
+ pytest.skip("Oops...")
87
+ assert names() == []
88
+ assert runapp(fail=False, begin=True, abort=True, use_transaction=True)
89
+ assert names() == ['app1']
90
+ setup()
91
+ assert runapp(use_transaction=True)
92
+ assert names() == ['app1', 'app2']
@@ -0,0 +1,20 @@
1
+ from sqlobject import SQLObject, StringCol
2
+ from sqlobject.tests.dbtest import getConnection
3
+
4
+
5
+ ########################################
6
+ # Per-instance connection
7
+ ########################################
8
+
9
+
10
+ class SOTestPerConnection(SQLObject):
11
+ test = StringCol()
12
+
13
+
14
+ def test_perConnection():
15
+ connection = getConnection()
16
+ SOTestPerConnection.dropTable(connection=connection, ifExists=True)
17
+ SOTestPerConnection.createTable(connection=connection)
18
+ SOTestPerConnection(test='test', connection=connection)
19
+ assert len(list(SOTestPerConnection.select(
20
+ SOTestPerConnection.q.test == 'test', connection=connection))) == 1
@@ -0,0 +1,42 @@
1
+ import pickle
2
+ import pytest
3
+ from sqlobject import IntCol, SQLObject, StringCol
4
+ from sqlobject.tests.dbtest import getConnection, raises, setupClass
5
+
6
+
7
+ ########################################
8
+ # Pickle instances
9
+ ########################################
10
+
11
+
12
+ class SOTestPickle(SQLObject):
13
+ question = StringCol()
14
+ answer = IntCol()
15
+
16
+
17
+ test_question = 'The Ulimate Question of Life, the Universe and Everything'
18
+ test_answer = 42
19
+
20
+
21
+ def test_pickleCol():
22
+ setupClass(SOTestPickle)
23
+ connection = SOTestPickle._connection
24
+ test = SOTestPickle(question=test_question, answer=test_answer)
25
+
26
+ pickle_data = pickle.dumps(test, pickle.HIGHEST_PROTOCOL)
27
+ connection.cache.clear()
28
+ test = pickle.loads(pickle_data)
29
+ test2 = connection.cache.tryGet(test.id, SOTestPickle)
30
+
31
+ assert test2 is test
32
+ assert test.question == test_question
33
+ assert test.answer == test_answer
34
+
35
+ if (connection.dbName == 'sqlite') and connection._memory:
36
+ pytest.skip("The following test requires a different connection")
37
+
38
+ test = SOTestPickle.get(
39
+ test.id,
40
+ # make a different DB URI and open another connection
41
+ connection=getConnection(registry=''))
42
+ raises(pickle.PicklingError, pickle.dumps, test, pickle.HIGHEST_PROTOCOL)
@@ -0,0 +1,44 @@
1
+ import pytest
2
+ from sqlobject import PickleCol, SQLObject
3
+ from sqlobject.tests.dbtest import setupClass, supports
4
+
5
+
6
+ ########################################
7
+ # Pickle columns
8
+ ########################################
9
+
10
+
11
+ class PickleData:
12
+ pi = 3.14156
13
+
14
+ def __init__(self):
15
+ self.question = \
16
+ 'The Ulimate Question of Life, the Universe and Everything'
17
+ self.answer = 42
18
+
19
+
20
+ class PickleContainer(SQLObject):
21
+ pickledata = PickleCol(default=None, length=256)
22
+
23
+
24
+ def test_pickleCol():
25
+ if not supports('blobData'):
26
+ pytest.skip("blobData isn't supported")
27
+ setupClass([PickleContainer], force=True)
28
+ mypickledata = PickleData()
29
+
30
+ ctnr = PickleContainer(pickledata=mypickledata)
31
+ iid = ctnr.id
32
+
33
+ PickleContainer._connection.cache.clear()
34
+
35
+ ctnr2 = PickleContainer.get(iid)
36
+ s2 = ctnr2.pickledata
37
+
38
+ assert isinstance(s2, PickleData)
39
+ assert isinstance(s2.pi, float)
40
+ assert isinstance(s2.question, str)
41
+ assert isinstance(s2.answer, int)
42
+ assert s2.pi == mypickledata.pi
43
+ assert s2.question == mypickledata.question
44
+ assert s2.answer == mypickledata.answer
@@ -0,0 +1,82 @@
1
+ import os
2
+ import pytest
3
+ from sqlobject import SQLObject, StringCol, IntCol
4
+ from sqlobject.sqlbuilder import Select, SOME
5
+ from sqlobject.tests.dbtest import getConnection, setupClass
6
+
7
+
8
+ ########################################
9
+ # Test PosgreSQL sslmode
10
+ ########################################
11
+
12
+
13
+ try:
14
+ connection = getConnection()
15
+ except (AttributeError, NameError):
16
+ # The module was imported during documentation building
17
+ pass
18
+ else:
19
+ if connection.dbName != "postgres":
20
+ pytestmark = pytest.mark.skip("These tests require PostgreSQL")
21
+
22
+
23
+ class SOTestSSLMode(SQLObject):
24
+ test = StringCol()
25
+
26
+
27
+ def test_sslmode():
28
+ setupClass(SOTestSSLMode)
29
+ connection = SOTestSSLMode._connection
30
+ if (not connection.module.__name__.startswith('psycopg')) or \
31
+ (os.name == 'nt'):
32
+ pytest.skip("The test requires PostgreSQL, psycopg and ssl mode; "
33
+ "also it doesn't work on w32")
34
+
35
+ connection = getConnection(sslmode='require')
36
+ SOTestSSLMode._connection = connection
37
+ test = SOTestSSLMode(test='test') # Connect to the DB to test sslmode
38
+
39
+ connection.cache.clear()
40
+ test = SOTestSSLMode.select()[0]
41
+ assert test.test == 'test'
42
+
43
+
44
+ ########################################
45
+ # Test PosgreSQL list{Database,Tables}
46
+ ########################################
47
+
48
+
49
+ class SOTestSOList(SQLObject):
50
+ pass
51
+
52
+
53
+ def test_list_databases():
54
+ assert connection.db in connection.listDatabases()
55
+
56
+
57
+ def test_list_tables():
58
+ setupClass(SOTestSOList)
59
+ assert SOTestSOList.sqlmeta.table in connection.listTables()
60
+
61
+
62
+ class SOTestSOME(SQLObject):
63
+ value = IntCol()
64
+
65
+
66
+ def test_SOME():
67
+ setupClass(SOTestSOME)
68
+ SOTestSOME(value=10)
69
+ SOTestSOME(value=20)
70
+ SOTestSOME(value=30)
71
+ assert len(list(SOTestSOME.select(
72
+ SOTestSOME.q.value > SOME(Select([SOTestSOME.q.value]))))) == 2
73
+
74
+
75
+ class SOTestPgidSize(SQLObject):
76
+ class sqlmeta:
77
+ idSize = 'BIG'
78
+
79
+
80
+ def test_idSize():
81
+ assert 'id BIGSERIAL PRIMARY KEY' \
82
+ in SOTestPgidSize.createTableSQL(connection=connection)[0]
@@ -0,0 +1,33 @@
1
+ from sqlobject import SQLObject, StringCol, sqlmeta
2
+ from sqlobject.tests.dbtest import setupClass
3
+
4
+ real_sqlmeta = sqlmeta
5
+
6
+
7
+ class Reparented1(SQLObject):
8
+
9
+ class sqlmeta:
10
+ table = 'reparented1'
11
+
12
+ dummy = StringCol()
13
+
14
+
15
+ class Reparented2(SQLObject):
16
+ class sqlmeta(object):
17
+ @classmethod
18
+ def setClass(cls, soClass):
19
+ # Well, it's pretty hard to call the superclass method
20
+ # when it's a classmethod and it's not actually your
21
+ # *current* superclass. Sigh
22
+ real_sqlmeta.setClass.__func__(cls, soClass)
23
+ cls.worked = True
24
+
25
+ dummy = StringCol()
26
+
27
+
28
+ def test_reparented():
29
+ setupClass([Reparented1, Reparented2])
30
+ assert Reparented1.sqlmeta.table == 'reparented1'
31
+ assert issubclass(Reparented1.sqlmeta, real_sqlmeta)
32
+ assert issubclass(Reparented2.sqlmeta, real_sqlmeta)
33
+ assert Reparented2.sqlmeta.worked
@@ -0,0 +1,30 @@
1
+ import pytest
2
+ from sqlobject import SQLObject, UnicodeCol
3
+ from sqlobject.tests.dbtest import getConnection, setupClass, supports
4
+
5
+
6
+ ########################################
7
+ # Schema per connection
8
+ ########################################
9
+
10
+
11
+ class SOTestSchema(SQLObject):
12
+ foo = UnicodeCol(length=200)
13
+
14
+
15
+ def test_connection_schema():
16
+ if not supports('schema'):
17
+ pytest.skip("schemas aren't supported")
18
+ conn = getConnection()
19
+ conn.schema = None
20
+ conn.query('CREATE SCHEMA test')
21
+ conn.schema = 'test'
22
+ conn.query('SET search_path TO test')
23
+ setupClass(SOTestSchema)
24
+ assert SOTestSchema._connection is conn
25
+ try:
26
+ SOTestSchema(foo='bar')
27
+ assert conn.queryAll("SELECT * FROM test.so_test_schema")
28
+ finally:
29
+ conn.schema = None
30
+ conn.query('SET search_path TO public')