Skip to content

Commit 42d46e8

Browse files
author
Nathan Gabrielson
committed
sqlAlchemy integration tests
1 parent 4969f87 commit 42d46e8

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

testing/PostgresDockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ COPY ./testing/postgres-client-tests/ruby/Gemfile.lock /postgres-client-tests/ru
7878
WORKDIR /postgres-client-tests/ruby
7979
RUN gem install bundler -v 2.1.4 && bundle install
8080

81+
# install sqlalchemy
82+
RUN pip3 install --no-cache-dir sqlalchemy==2.0.46
83+
8184
# install doltgres from source
8285
WORKDIR /root/building
8386
COPY go.mod doltgresql/

testing/postgres-client-tests/postgres-client-tests.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ teardown() {
7171
@test "python postgres: psycopg2 client" {
7272
cd $BATS_TEST_DIRNAME/python
7373
python3 psycopg2_test.py $USER $PORT
74+
}
75+
76+
@test "python postgres: sqlalcchemy client" {
77+
cd $BATS_TEST_DIRNAME/python
78+
python3 sqlalchemy-test.py $USER $PORT
7479
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import sqlalchemy
2+
import psycopg2
3+
4+
from sqlalchemy.engine import Engine
5+
from sqlalchemy import create_engine
6+
from sqlalchemy import text
7+
8+
import sys
9+
10+
QUERY_RESPONSE = [
11+
{"create table test (pk int, \"value\" int, primary key(pk))": []},
12+
{"describe test": [
13+
('pk', 'integer', 'NO', 'PRI', None, ''),
14+
('value', 'integer', 'YES', '', None, '')
15+
]},
16+
{"insert into test (pk, value) values (0,0)": ()},
17+
{"select * from test": [(0, 0)]},
18+
{"select dolt_add('-A');": [(['0'],)]},
19+
{"select dolt_commit('-m', 'my commit')": [('',)]},
20+
{"select COUNT(*) FROM dolt_log": [(3,)]},
21+
{"select dolt_checkout('-b', 'mybranch')": [(['0', "Switched to branch 'mybranch'"],)]},
22+
{"insert into test (pk, value) values (1,1)": []},
23+
{"select dolt_commit('-a', '-m', 'my commit2')": [('',)]},
24+
{"select dolt_checkout('main')": [(['0', "Switched to branch 'main'"],)]},
25+
{"select dolt_merge('mybranch')": [('',1,0,)]},
26+
{"select COUNT(*) FROM dolt_log": [(4,)]},
27+
]
28+
29+
30+
def main():
31+
user = sys.argv[1]
32+
port = int(sys.argv[2])
33+
34+
conn_string_base = "postgresql+psycopg2://"
35+
36+
engine = create_engine(conn_string_base +
37+
"{user}:password@127.0.0.1:{port}/postgres".format(user=user,
38+
port=port)
39+
)
40+
41+
with engine.connect() as con:
42+
for query_response in QUERY_RESPONSE:
43+
query = list(query_response.keys())[0]
44+
exp_results = query_response[query]
45+
46+
result_proxy = con.execute(text(query))
47+
48+
try:
49+
results = result_proxy.fetchall()
50+
if (results != exp_results) and ("dolt_commit" not in query) and ("dolt_merge" not in query):
51+
print("Query:")
52+
print(query)
53+
print("Expected:")
54+
print(exp_results)
55+
print("Received:")
56+
print(results)
57+
sys.exit(1)
58+
# You can't call fetchall on an insert
59+
# so we'll just ignore the exception
60+
except sqlalchemy.exc.ResourceClosedError:
61+
pass
62+
63+
con.close()
64+
sys.exit(0)
65+
66+
67+
main()

0 commit comments

Comments
 (0)