velocity-python 0.0.109__py3-none-any.whl → 0.0.161__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.
- velocity/__init__.py +3 -1
- velocity/app/orders.py +3 -4
- velocity/app/tests/__init__.py +1 -0
- velocity/app/tests/test_email_processing.py +112 -0
- velocity/app/tests/test_payment_profile_sorting.py +191 -0
- velocity/app/tests/test_spreadsheet_functions.py +124 -0
- velocity/aws/__init__.py +3 -0
- velocity/aws/amplify.py +10 -6
- velocity/aws/handlers/__init__.py +2 -0
- velocity/aws/handlers/base_handler.py +248 -0
- velocity/aws/handlers/context.py +251 -2
- velocity/aws/handlers/exceptions.py +16 -0
- velocity/aws/handlers/lambda_handler.py +24 -85
- velocity/aws/handlers/mixins/__init__.py +16 -0
- velocity/aws/handlers/mixins/activity_tracker.py +181 -0
- velocity/aws/handlers/mixins/aws_session_mixin.py +192 -0
- velocity/aws/handlers/mixins/error_handler.py +192 -0
- velocity/aws/handlers/mixins/legacy_mixin.py +53 -0
- velocity/aws/handlers/mixins/standard_mixin.py +73 -0
- velocity/aws/handlers/response.py +1 -1
- velocity/aws/handlers/sqs_handler.py +28 -143
- velocity/aws/tests/__init__.py +1 -0
- velocity/aws/tests/test_lambda_handler_json_serialization.py +120 -0
- velocity/aws/tests/test_response.py +163 -0
- velocity/db/__init__.py +16 -4
- velocity/db/core/decorators.py +48 -13
- velocity/db/core/engine.py +187 -840
- velocity/db/core/result.py +33 -25
- velocity/db/core/row.py +15 -3
- velocity/db/core/table.py +493 -50
- velocity/db/core/transaction.py +28 -15
- velocity/db/exceptions.py +42 -18
- velocity/db/servers/base/__init__.py +9 -0
- velocity/db/servers/base/initializer.py +70 -0
- velocity/db/servers/base/operators.py +98 -0
- velocity/db/servers/base/sql.py +503 -0
- velocity/db/servers/base/types.py +135 -0
- velocity/db/servers/mysql/__init__.py +73 -0
- velocity/db/servers/mysql/operators.py +54 -0
- velocity/db/servers/{mysql_reserved.py → mysql/reserved.py} +2 -14
- velocity/db/servers/mysql/sql.py +718 -0
- velocity/db/servers/mysql/types.py +107 -0
- velocity/db/servers/postgres/__init__.py +59 -11
- velocity/db/servers/postgres/operators.py +34 -0
- velocity/db/servers/postgres/sql.py +474 -120
- velocity/db/servers/postgres/types.py +88 -2
- velocity/db/servers/sqlite/__init__.py +61 -0
- velocity/db/servers/sqlite/operators.py +52 -0
- velocity/db/servers/sqlite/reserved.py +20 -0
- velocity/db/servers/sqlite/sql.py +677 -0
- velocity/db/servers/sqlite/types.py +92 -0
- velocity/db/servers/sqlserver/__init__.py +73 -0
- velocity/db/servers/sqlserver/operators.py +47 -0
- velocity/db/servers/sqlserver/reserved.py +32 -0
- velocity/db/servers/sqlserver/sql.py +805 -0
- velocity/db/servers/sqlserver/types.py +114 -0
- velocity/db/servers/tablehelper.py +117 -91
- velocity/db/tests/__init__.py +1 -0
- velocity/db/tests/common_db_test.py +0 -0
- velocity/db/tests/postgres/__init__.py +1 -0
- velocity/db/tests/postgres/common.py +49 -0
- velocity/db/tests/postgres/test_column.py +29 -0
- velocity/db/tests/postgres/test_connections.py +25 -0
- velocity/db/tests/postgres/test_database.py +21 -0
- velocity/db/tests/postgres/test_engine.py +205 -0
- velocity/db/tests/postgres/test_general_usage.py +88 -0
- velocity/db/tests/postgres/test_imports.py +8 -0
- velocity/db/tests/postgres/test_result.py +19 -0
- velocity/db/tests/postgres/test_row.py +137 -0
- velocity/db/tests/postgres/test_row_comprehensive.py +720 -0
- velocity/db/tests/postgres/test_schema_locking.py +335 -0
- velocity/db/tests/postgres/test_schema_locking_unit.py +115 -0
- velocity/db/tests/postgres/test_sequence.py +34 -0
- velocity/db/tests/postgres/test_sql_comprehensive.py +462 -0
- velocity/db/tests/postgres/test_table.py +101 -0
- velocity/db/tests/postgres/test_table_comprehensive.py +646 -0
- velocity/db/tests/postgres/test_transaction.py +106 -0
- velocity/db/tests/sql/__init__.py +1 -0
- velocity/db/tests/sql/common.py +177 -0
- velocity/db/tests/sql/test_postgres_select_advanced.py +285 -0
- velocity/db/tests/sql/test_postgres_select_variances.py +517 -0
- velocity/db/tests/test_cursor_rowcount_fix.py +150 -0
- velocity/db/tests/test_db_utils.py +270 -0
- velocity/db/tests/test_postgres.py +448 -0
- velocity/db/tests/test_postgres_unchanged.py +81 -0
- velocity/db/tests/test_process_error_robustness.py +292 -0
- velocity/db/tests/test_result_caching.py +279 -0
- velocity/db/tests/test_result_sql_aware.py +117 -0
- velocity/db/tests/test_row_get_missing_column.py +72 -0
- velocity/db/tests/test_schema_locking_initializers.py +226 -0
- velocity/db/tests/test_schema_locking_simple.py +97 -0
- velocity/db/tests/test_sql_builder.py +165 -0
- velocity/db/tests/test_tablehelper.py +486 -0
- velocity/db/utils.py +129 -51
- velocity/misc/conv/__init__.py +2 -0
- velocity/misc/conv/iconv.py +5 -4
- velocity/misc/export.py +1 -4
- velocity/misc/merge.py +1 -1
- velocity/misc/tests/__init__.py +1 -0
- velocity/misc/tests/test_db.py +90 -0
- velocity/misc/tests/test_fix.py +78 -0
- velocity/misc/tests/test_format.py +64 -0
- velocity/misc/tests/test_iconv.py +203 -0
- velocity/misc/tests/test_merge.py +82 -0
- velocity/misc/tests/test_oconv.py +144 -0
- velocity/misc/tests/test_original_error.py +52 -0
- velocity/misc/tests/test_timer.py +74 -0
- velocity/misc/tools.py +0 -1
- {velocity_python-0.0.109.dist-info → velocity_python-0.0.161.dist-info}/METADATA +2 -2
- velocity_python-0.0.161.dist-info/RECORD +129 -0
- velocity/db/core/exceptions.py +0 -70
- velocity/db/servers/mysql.py +0 -641
- velocity/db/servers/sqlite.py +0 -968
- velocity/db/servers/sqlite_reserved.py +0 -208
- velocity/db/servers/sqlserver.py +0 -921
- velocity/db/servers/sqlserver_reserved.py +0 -314
- velocity_python-0.0.109.dist-info/RECORD +0 -56
- {velocity_python-0.0.109.dist-info → velocity_python-0.0.161.dist-info}/WHEEL +0 -0
- {velocity_python-0.0.109.dist-info → velocity_python-0.0.161.dist-info}/licenses/LICENSE +0 -0
- {velocity_python-0.0.109.dist-info → velocity_python-0.0.161.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from velocity.db.servers import postgres
|
|
3
|
+
import env
|
|
4
|
+
env.set()
|
|
5
|
+
|
|
6
|
+
test_db = "test_db_postgres"
|
|
7
|
+
engine = postgres.initialize(database=test_db)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CommonPostgresTest(unittest.TestCase):
|
|
11
|
+
"""
|
|
12
|
+
Base test class for PostgreSQL tests following the common pattern.
|
|
13
|
+
All PostgreSQL tests should inherit from this class.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def setUpClass(cls):
|
|
18
|
+
"""Set up the test database and create any common tables."""
|
|
19
|
+
@engine.transaction
|
|
20
|
+
def setup(tx):
|
|
21
|
+
tx.switch_to_database("postgres")
|
|
22
|
+
tx.execute(f"drop database if exists {test_db}", single=True)
|
|
23
|
+
|
|
24
|
+
# Create the test database
|
|
25
|
+
db = tx.database(test_db)
|
|
26
|
+
if not db.exists():
|
|
27
|
+
db.create()
|
|
28
|
+
db.switch()
|
|
29
|
+
|
|
30
|
+
# Call subclass-specific table creation with commit
|
|
31
|
+
if hasattr(cls, 'create_test_tables'):
|
|
32
|
+
cls.create_test_tables(tx)
|
|
33
|
+
|
|
34
|
+
setup()
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
def tearDownClass(cls):
|
|
38
|
+
"""Clean up the test database."""
|
|
39
|
+
@engine.transaction
|
|
40
|
+
def cleanup(tx):
|
|
41
|
+
tx.switch_to_database("postgres")
|
|
42
|
+
tx.execute(f"drop database if exists {test_db}", single=True)
|
|
43
|
+
|
|
44
|
+
cleanup()
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def create_test_tables(cls, tx):
|
|
48
|
+
"""Override this method in subclasses to create test-specific tables."""
|
|
49
|
+
pass
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from velocity.db.core.column import Column
|
|
3
|
+
from velocity.db.exceptions import DbColumnMissingError
|
|
4
|
+
from .common import CommonPostgresTest, engine, test_db
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@engine.transaction
|
|
8
|
+
@engine.transaction
|
|
9
|
+
class TestColumn(CommonPostgresTest):
|
|
10
|
+
|
|
11
|
+
@classmethod
|
|
12
|
+
def create_test_tables(cls, tx):
|
|
13
|
+
"""Create test tables for column tests."""
|
|
14
|
+
tx.table("mock_table").create(
|
|
15
|
+
columns={
|
|
16
|
+
"column1": int,
|
|
17
|
+
"column2": str,
|
|
18
|
+
"column3": str,
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
def test_init(self, tx):
|
|
23
|
+
column = tx.table("mock_table").column("column1")
|
|
24
|
+
self.assertIsInstance(column, Column)
|
|
25
|
+
self.assertEqual(column.name, "column1")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
unittest.main()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from .common import CommonPostgresTest, engine, test_db
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@engine.transaction
|
|
6
|
+
@engine.transaction
|
|
7
|
+
class TestConnections(CommonPostgresTest):
|
|
8
|
+
|
|
9
|
+
@classmethod
|
|
10
|
+
def create_test_tables(cls, tx):
|
|
11
|
+
"""Create test tables for connection tests."""
|
|
12
|
+
tx.table("mock_table").create(
|
|
13
|
+
columns={
|
|
14
|
+
"column1": int,
|
|
15
|
+
"column2": str,
|
|
16
|
+
"column3": str,
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
def test_init(self, tx):
|
|
20
|
+
# Test the initialization of the Database object
|
|
21
|
+
assert tx.table("mock_table").exists()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
unittest.main()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from velocity.db.core.database import Database
|
|
3
|
+
from .common import CommonPostgresTest, engine, test_db
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@engine.transaction
|
|
7
|
+
@engine.transaction
|
|
8
|
+
class TestDatabase(CommonPostgresTest):
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def create_test_tables(cls, tx):
|
|
12
|
+
"""No special tables needed for database tests."""
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
def test_init(self, tx):
|
|
16
|
+
# Test the initialization of the Database object
|
|
17
|
+
tx.database
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
unittest.main()
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import datetime
|
|
3
|
+
import unittest
|
|
4
|
+
from velocity.db.core.engine import Engine
|
|
5
|
+
from velocity.db.core.transaction import Transaction
|
|
6
|
+
from .common import CommonPostgresTest, engine, test_db
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@engine.transaction
|
|
10
|
+
class TestEngine(CommonPostgresTest):
|
|
11
|
+
@classmethod
|
|
12
|
+
def create_test_tables(cls, tx):
|
|
13
|
+
"""No special tables needed for engine tests."""
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
def test_engine_init(self, tx):
|
|
17
|
+
import psycopg2
|
|
18
|
+
from velocity.db.servers.postgres import SQL
|
|
19
|
+
|
|
20
|
+
# Test the engine instance from common test
|
|
21
|
+
assert engine.sql == SQL
|
|
22
|
+
assert engine.driver == psycopg2
|
|
23
|
+
|
|
24
|
+
def test_engine_attributes(self, tx):
|
|
25
|
+
import psycopg2
|
|
26
|
+
from velocity.db.servers.postgres import SQL
|
|
27
|
+
|
|
28
|
+
# Test private attributes
|
|
29
|
+
assert engine._Engine__sql == SQL
|
|
30
|
+
assert engine._Engine__driver == psycopg2
|
|
31
|
+
|
|
32
|
+
def test_connect(self, tx):
|
|
33
|
+
import psycopg2
|
|
34
|
+
|
|
35
|
+
assert engine.connect() != None
|
|
36
|
+
conn = engine.connect()
|
|
37
|
+
self.assertIsInstance(conn, psycopg2.extensions.connection)
|
|
38
|
+
|
|
39
|
+
def test_other_stuff(self, tx):
|
|
40
|
+
assert engine.version[:10] == "PostgreSQL"
|
|
41
|
+
|
|
42
|
+
timestamp = engine.timestamp
|
|
43
|
+
self.assertIsInstance(timestamp, datetime.datetime)
|
|
44
|
+
assert engine.user == os.environ["DBUser"]
|
|
45
|
+
assert test_db in engine.databases
|
|
46
|
+
assert "public" in engine.schemas
|
|
47
|
+
assert "information_schema" in engine.schemas
|
|
48
|
+
assert "public" == engine.current_schema
|
|
49
|
+
assert engine.current_database == test_db
|
|
50
|
+
assert [] == engine.views
|
|
51
|
+
assert [] == engine.tables
|
|
52
|
+
|
|
53
|
+
def test_process_error(self, tx):
|
|
54
|
+
local_engine = Engine(None, None, None) # Replace None with appropriate arguments
|
|
55
|
+
with self.assertRaises(
|
|
56
|
+
Exception
|
|
57
|
+
): # Replace Exception with the specific exception raised by process_error
|
|
58
|
+
local_engine.process_error(sql_stmt=None, sql_params=None)
|
|
59
|
+
# Add additional assertions as needed
|
|
60
|
+
|
|
61
|
+
def test_transaction_injection_1(self, tx):
|
|
62
|
+
@engine.transaction
|
|
63
|
+
def function():
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
function()
|
|
67
|
+
|
|
68
|
+
@engine.transaction
|
|
69
|
+
def function(_tx):
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
with self.assertRaises(NameError):
|
|
73
|
+
function()
|
|
74
|
+
|
|
75
|
+
@engine.transaction
|
|
76
|
+
def function(tx):
|
|
77
|
+
pass
|
|
78
|
+
|
|
79
|
+
with self.assertRaises(TypeError):
|
|
80
|
+
function(tx=3)
|
|
81
|
+
with self.assertRaises(TypeError):
|
|
82
|
+
function(tx=None)
|
|
83
|
+
|
|
84
|
+
def test_transaction_injection_function(self, tx):
|
|
85
|
+
with engine.transaction() as original:
|
|
86
|
+
|
|
87
|
+
@engine.transaction
|
|
88
|
+
def function(tx):
|
|
89
|
+
assert tx != None
|
|
90
|
+
assert tx != original
|
|
91
|
+
self.assertIsInstance(tx, Transaction)
|
|
92
|
+
|
|
93
|
+
function()
|
|
94
|
+
|
|
95
|
+
@engine.transaction
|
|
96
|
+
def function(tx):
|
|
97
|
+
assert tx != None
|
|
98
|
+
assert tx == original
|
|
99
|
+
self.assertIsInstance(tx, Transaction)
|
|
100
|
+
|
|
101
|
+
function(original)
|
|
102
|
+
|
|
103
|
+
@engine.transaction
|
|
104
|
+
def function(tx=None):
|
|
105
|
+
assert tx != None
|
|
106
|
+
assert tx != original
|
|
107
|
+
self.assertIsInstance(tx, Transaction)
|
|
108
|
+
|
|
109
|
+
function()
|
|
110
|
+
|
|
111
|
+
@engine.transaction
|
|
112
|
+
def function(tx=None):
|
|
113
|
+
assert tx != None
|
|
114
|
+
assert tx == original
|
|
115
|
+
self.assertIsInstance(tx, Transaction)
|
|
116
|
+
|
|
117
|
+
function(original)
|
|
118
|
+
|
|
119
|
+
@engine.transaction
|
|
120
|
+
def function(tx=None):
|
|
121
|
+
assert tx != None
|
|
122
|
+
assert tx == original
|
|
123
|
+
self.assertIsInstance(tx, Transaction)
|
|
124
|
+
|
|
125
|
+
function(tx=original)
|
|
126
|
+
|
|
127
|
+
@engine.transaction
|
|
128
|
+
def function(tx, a, b):
|
|
129
|
+
assert tx != None
|
|
130
|
+
assert tx != original
|
|
131
|
+
self.assertIsInstance(tx, Transaction)
|
|
132
|
+
|
|
133
|
+
function(1, 2)
|
|
134
|
+
|
|
135
|
+
@engine.transaction
|
|
136
|
+
def function(tx, a, b):
|
|
137
|
+
assert tx != None
|
|
138
|
+
assert tx == original
|
|
139
|
+
self.assertIsInstance(tx, Transaction)
|
|
140
|
+
|
|
141
|
+
function(original, 1, 2)
|
|
142
|
+
|
|
143
|
+
@engine.transaction
|
|
144
|
+
def function(tx, a, b):
|
|
145
|
+
assert tx != None
|
|
146
|
+
assert tx == original
|
|
147
|
+
self.assertIsInstance(tx, Transaction)
|
|
148
|
+
|
|
149
|
+
function(tx=original, a=1, b=2)
|
|
150
|
+
|
|
151
|
+
@engine.transaction
|
|
152
|
+
def function(tx, src, b):
|
|
153
|
+
assert tx != None
|
|
154
|
+
assert tx != src
|
|
155
|
+
self.assertIsInstance(tx, Transaction)
|
|
156
|
+
|
|
157
|
+
function(src=original, b=2)
|
|
158
|
+
|
|
159
|
+
@engine.transaction
|
|
160
|
+
def function(a, tx, b):
|
|
161
|
+
assert tx != None
|
|
162
|
+
assert tx != original
|
|
163
|
+
self.assertIsInstance(tx, Transaction)
|
|
164
|
+
|
|
165
|
+
function(1, 2)
|
|
166
|
+
|
|
167
|
+
@engine.transaction
|
|
168
|
+
def function(a, tx, b):
|
|
169
|
+
assert tx != None
|
|
170
|
+
assert tx == original
|
|
171
|
+
self.assertIsInstance(tx, Transaction)
|
|
172
|
+
|
|
173
|
+
function(1, original, 2)
|
|
174
|
+
|
|
175
|
+
def test_transaction_injection_class(self, tx):
|
|
176
|
+
test_class = self
|
|
177
|
+
with engine.transaction() as original:
|
|
178
|
+
|
|
179
|
+
@engine.transaction
|
|
180
|
+
class TestClass:
|
|
181
|
+
@engine.transaction
|
|
182
|
+
def __init__(self, tx):
|
|
183
|
+
assert tx != None
|
|
184
|
+
assert tx != original
|
|
185
|
+
test_class.assertIsInstance(tx, Transaction)
|
|
186
|
+
|
|
187
|
+
def first_method(self, tx):
|
|
188
|
+
assert tx != None
|
|
189
|
+
assert tx != original
|
|
190
|
+
test_class.assertIsInstance(tx, Transaction)
|
|
191
|
+
|
|
192
|
+
def second_method(self, tx):
|
|
193
|
+
assert tx != None
|
|
194
|
+
assert tx == original
|
|
195
|
+
test_class.assertIsInstance(tx, Transaction)
|
|
196
|
+
|
|
197
|
+
tc = TestClass()
|
|
198
|
+
|
|
199
|
+
tc.first_method()
|
|
200
|
+
tc.second_method(original)
|
|
201
|
+
self.assertRaises(AssertionError, tc.second_method)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if __name__ == "__main__":
|
|
205
|
+
unittest.main()
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import sys
|
|
3
|
+
import os
|
|
4
|
+
from .common import CommonPostgresTest, engine, test_db
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@engine.transaction
|
|
8
|
+
@engine.transaction
|
|
9
|
+
class TestFeatures(CommonPostgresTest):
|
|
10
|
+
|
|
11
|
+
@classmethod
|
|
12
|
+
def create_test_tables(cls, tx):
|
|
13
|
+
"""Clean up any existing tables for general usage tests."""
|
|
14
|
+
# Ensure clean state by dropping tables if they exist
|
|
15
|
+
tx.table("names").drop()
|
|
16
|
+
tx.table("addresses").drop()
|
|
17
|
+
|
|
18
|
+
def test_foreign_key(self, tx):
|
|
19
|
+
first = tx.table("names")
|
|
20
|
+
second = tx.table("addresses")
|
|
21
|
+
first.create(
|
|
22
|
+
{
|
|
23
|
+
"first_name": str,
|
|
24
|
+
"last_name": str,
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
second.create(
|
|
28
|
+
{
|
|
29
|
+
"address": str,
|
|
30
|
+
"address2": str,
|
|
31
|
+
"city": str,
|
|
32
|
+
"state": str,
|
|
33
|
+
"zipcode": str,
|
|
34
|
+
"country": str,
|
|
35
|
+
"name_id": int,
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
tx.commit()
|
|
39
|
+
second.create_foreign_key("name_id", "names", "sys_id")
|
|
40
|
+
first.insert(
|
|
41
|
+
{
|
|
42
|
+
"first_name": "John",
|
|
43
|
+
"last_name": "Doe",
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
tx.commit()
|
|
47
|
+
second.insert(
|
|
48
|
+
{
|
|
49
|
+
"address": "123 Main St",
|
|
50
|
+
"address2": "Apt 123",
|
|
51
|
+
"city": "New York",
|
|
52
|
+
"state": "NY",
|
|
53
|
+
"zipcode": "12345",
|
|
54
|
+
"country": "USA",
|
|
55
|
+
"name_id": 1001,
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
second.insert(
|
|
59
|
+
{
|
|
60
|
+
"address": "123 Main St",
|
|
61
|
+
"address2": "Apt 123",
|
|
62
|
+
"city": "New York",
|
|
63
|
+
"state": "NY",
|
|
64
|
+
"zipcode": "12345",
|
|
65
|
+
"country": "USA",
|
|
66
|
+
"name_id": 1001,
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
second.insert(
|
|
70
|
+
{
|
|
71
|
+
"address": "123 Main St",
|
|
72
|
+
"address2": "Apt 123",
|
|
73
|
+
"city": "New York",
|
|
74
|
+
"state": "NY",
|
|
75
|
+
"zipcode": "12345",
|
|
76
|
+
"country": "USA",
|
|
77
|
+
"name_id": 1001,
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
addresses = second.select(where={"name_id": 1001})
|
|
81
|
+
# for address in addresses:
|
|
82
|
+
# print(address)
|
|
83
|
+
|
|
84
|
+
first.drop()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
unittest.main()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from velocity.db.core.result import Result
|
|
3
|
+
from .common import CommonPostgresTest, engine, test_db
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@engine.transaction
|
|
7
|
+
@engine.transaction
|
|
8
|
+
class TestResult(CommonPostgresTest):
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def create_test_tables(cls, tx):
|
|
12
|
+
"""No special tables needed for result tests."""
|
|
13
|
+
pass
|
|
14
|
+
def test_result_all(self, tx):
|
|
15
|
+
result = tx.execute("SELECT current_timestamp")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
unittest.main()
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from velocity.db.core.row import Row
|
|
3
|
+
from .common import CommonPostgresTest, engine, test_db
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@engine.transaction
|
|
7
|
+
@engine.transaction
|
|
8
|
+
class TestRow(CommonPostgresTest):
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def create_test_tables(cls, tx):
|
|
12
|
+
"""Create test tables for row tests."""
|
|
13
|
+
# Create a test table for row operations
|
|
14
|
+
tx.table("test_users").create(
|
|
15
|
+
columns={
|
|
16
|
+
"name": str,
|
|
17
|
+
"age": int,
|
|
18
|
+
"email": str,
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
def test_init(self, tx):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
# def test_repr(self):
|
|
25
|
+
# expected = "{'sys_id': 1, 'sys_name': 'John', 'sys_age': 30}"
|
|
26
|
+
# self.assertEqual(repr(self.row), expected)
|
|
27
|
+
|
|
28
|
+
# def test_str(self):
|
|
29
|
+
# expected = "{'sys_id': 1, 'sys_name': 'John', 'sys_age': 30}"
|
|
30
|
+
# self.assertEqual(str(self.row), expected)
|
|
31
|
+
|
|
32
|
+
# def test_len(self):
|
|
33
|
+
# self.assertEqual(len(self.row), 1)
|
|
34
|
+
|
|
35
|
+
# def test_getitem(self):
|
|
36
|
+
# self.assertEqual(self.row['sys_name'], 'John')
|
|
37
|
+
|
|
38
|
+
# def test_setitem(self):
|
|
39
|
+
# with self.assertRaises(Exception):
|
|
40
|
+
# self.row['sys_id'] = 2
|
|
41
|
+
|
|
42
|
+
# def test_delitem(self):
|
|
43
|
+
# with self.assertRaises(Exception):
|
|
44
|
+
# del self.row['sys_id']
|
|
45
|
+
|
|
46
|
+
# def test_contains(self):
|
|
47
|
+
# self.assertTrue('sys_name' in self.row)
|
|
48
|
+
# self.assertFalse('sys_email' in self.row)
|
|
49
|
+
|
|
50
|
+
# def test_clear(self):
|
|
51
|
+
# self.row.clear()
|
|
52
|
+
# # Add assertions here to check if the row is cleared
|
|
53
|
+
|
|
54
|
+
# def test_keys(self):
|
|
55
|
+
# expected = ['sys_id', 'sys_name', 'sys_age']
|
|
56
|
+
# self.assertEqual(self.row.keys(), expected)
|
|
57
|
+
|
|
58
|
+
# def test_values(self):
|
|
59
|
+
# expected = [1, 'John', 30]
|
|
60
|
+
# self.assertEqual(self.row.values(), expected)
|
|
61
|
+
|
|
62
|
+
# def test_items(self):
|
|
63
|
+
# expected = [('sys_id', 1), ('sys_name', 'John'), ('sys_age', 30)]
|
|
64
|
+
# self.assertEqual(self.row.items(), expected)
|
|
65
|
+
|
|
66
|
+
# def test_get(self):
|
|
67
|
+
# self.assertEqual(self.row.get('sys_name'), 'John')
|
|
68
|
+
# self.assertEqual(self.row.get('sys_email'), None)
|
|
69
|
+
|
|
70
|
+
# def test_setdefault(self):
|
|
71
|
+
# self.assertEqual(self.row.setdefault('sys_name'), 'John')
|
|
72
|
+
# self.assertEqual(self.row.setdefault('sys_email', 'john@example.com'), 'john@example.com')
|
|
73
|
+
|
|
74
|
+
# def test_update(self):
|
|
75
|
+
# self.row.update({'sys_name': 'Jane', 'sys_age': 25})
|
|
76
|
+
# # Add assertions here to check if the row is updated
|
|
77
|
+
|
|
78
|
+
# def test_iterkeys(self):
|
|
79
|
+
# expected = ['sys_id', 'sys_name', 'sys_age']
|
|
80
|
+
# self.assertEqual(list(self.row.iterkeys()), expected)
|
|
81
|
+
|
|
82
|
+
# def test_itervalues(self):
|
|
83
|
+
# expected = [1, 'John', 30]
|
|
84
|
+
# self.assertEqual(list(self.row.itervalues()), expected)
|
|
85
|
+
|
|
86
|
+
# def test_iteritems(self):
|
|
87
|
+
# expected = [('sys_id', 1), ('sys_name', 'John'), ('sys_age', 30)]
|
|
88
|
+
# self.assertEqual(list(self.row.iteritems()), expected)
|
|
89
|
+
|
|
90
|
+
# def test_bool(self):
|
|
91
|
+
# self.assertTrue(bool(self.row))
|
|
92
|
+
|
|
93
|
+
# def test_copy(self):
|
|
94
|
+
# copied_row = self.row.copy()
|
|
95
|
+
# # Add assertions here to check if the row is copied correctly
|
|
96
|
+
|
|
97
|
+
# def test_to_dict(self):
|
|
98
|
+
# expected = {'sys_id': 1, 'sys_name': 'John', 'sys_age': 30}
|
|
99
|
+
# self.assertEqual(self.row.to_dict(), expected)
|
|
100
|
+
|
|
101
|
+
# def test_extract(self):
|
|
102
|
+
# expected = {'sys_id': 1, 'sys_name': 'John'}
|
|
103
|
+
# self.assertEqual(self.row.extract('sys_id', 'sys_name'), expected)
|
|
104
|
+
|
|
105
|
+
# def test_key_cols(self):
|
|
106
|
+
# expected = ['sys_id']
|
|
107
|
+
# self.assertEqual(self.row.key_cols, expected)
|
|
108
|
+
|
|
109
|
+
# def test_split(self):
|
|
110
|
+
# data, pk = self.row.split()
|
|
111
|
+
# # Add assertions here to check if the row is split correctly
|
|
112
|
+
|
|
113
|
+
# def test_data(self):
|
|
114
|
+
# data = self.row.data
|
|
115
|
+
# # Add assertions here to check if the data is extracted correctly
|
|
116
|
+
|
|
117
|
+
# def test_row(self):
|
|
118
|
+
# row = self.row.row('sys_id')
|
|
119
|
+
# # Add assertions here to check if the row is fetched correctly
|
|
120
|
+
|
|
121
|
+
# def test_match(self):
|
|
122
|
+
# other = {'sys_id': 1, 'sys_name': 'John', 'sys_age': 30}
|
|
123
|
+
# self.assertTrue(self.row.match(other))
|
|
124
|
+
# other = {'sys_id': 2, 'sys_name': 'Jane', 'sys_age': 25}
|
|
125
|
+
# self.assertFalse(self.row.match(other))
|
|
126
|
+
|
|
127
|
+
# def test_touch(self):
|
|
128
|
+
# self.row.touch()
|
|
129
|
+
# # Add assertions here to check if the row is touched correctly
|
|
130
|
+
|
|
131
|
+
# def test_delete(self):
|
|
132
|
+
# self.row.delete()
|
|
133
|
+
# # Add assertions here to check if the row is deleted correctly
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
if __name__ == "__main__":
|
|
137
|
+
unittest.main()
|