11import pytest
22from sqlalchemy import *
3- from sqlalchemy import testing
43from sqlalchemy .testing import (
54 eq_ ,
65 fixtures ,
76)
7+ from sqlalchemy .testing .fixtures import config
88from sqlalchemy .testing .schema import (
99 Column ,
1010 Table ,
@@ -82,30 +82,33 @@ def fixtures(cls):
8282
8383
8484@pytest .mark .skipif (
85- testing .db .dialect .driver == "turbodbc" , reason = "not supported by turbodbc"
85+ config .db .dialect .driver == "turbodbc" , reason = "not supported by turbodbc"
8686)
8787class UpdateTest (_UpdateTestBase , fixtures .TablesTest ):
8888 __backend__ = True
8989
9090 def test_update_simple (self ):
9191 """test simple update and assert that exasol returns the right rowcount"""
9292 users = self .tables [f"{ self .schema } .users" ]
93- result = testing .db .execute (
94- users .update ().values (name = "peter" ).where (users .c .id == 10 )
95- )
96- expected = [(7 , "jack" ), (8 , "ed" ), (9 , "fred" ), (10 , "peter" )]
93+
94+ with config .db .begin () as conn :
95+ result = conn .execute (
96+ users .update ().values (name = "peter" ).where (users .c .id == 10 )
97+ )
98+
9799 assert result .rowcount == 1
98- self ._assert_users (users , expected )
100+ self ._assert_users (users , [( 7 , "jack" ), ( 8 , "ed" ), ( 9 , "fred" ), ( 10 , "peter" )] )
99101
100102 def test_update_simple_multiple_rows_rowcount (self ):
101103 """test simple update and assert that exasol returns the right rowcount"""
102104 users = self .tables [f"{ self .schema } .users" ]
103- result = testing .db .execute (
104- users .update ().values (name = "peter" ).where (users .c .id >= 9 )
105- )
106- expected = [(7 , "jack" ), (8 , "ed" ), (9 , "peter" ), (10 , "peter" )]
105+
106+ with config .db .begin () as conn :
107+ result = conn .execute (
108+ users .update ().values (name = "peter" ).where (users .c .id >= 9 )
109+ )
107110 assert result .rowcount == 2
108- self ._assert_users (users , expected )
111+ self ._assert_users (users , [( 7 , "jack" ), ( 8 , "ed" ), ( 9 , "peter" ), ( 10 , "peter" )] )
109112
110113 def test_update_executemany (self ):
111114 """test that update with executemany work as well, but rowcount
@@ -123,8 +126,8 @@ def test_update_executemany(self):
123126 {"oldname" : "fred" , "newname" : "fred2" },
124127 ]
125128
126- result = testing .db .execute ( stmt , values )
127- expected = [( 7 , "jack2" ), ( 8 , "ed" ), ( 9 , "fred2" ), ( 10 , "chuck" )]
129+ with config .db .begin () as conn :
130+ result = conn . execute ( stmt , values )
128131
129132 # Depending on the dialect it either reports that the affected rows information
130133 # is not available (-1) or it reports the actual number of updated/affected rows(2)
@@ -133,12 +136,15 @@ def test_update_executemany(self):
133136 expected_rowcount = [expected_rowcount_odbc , expected_rowcount_wss ]
134137 assert result .rowcount in expected_rowcount
135138
136- self ._assert_users (users , expected )
139+ self ._assert_users (
140+ users , [(7 , "jack2" ), (8 , "ed" ), (9 , "fred2" ), (10 , "chuck" )]
141+ )
137142
138143 def _assert_addresses (self , addresses , expected ):
139144 stmt = addresses .select ().order_by (addresses .c .id )
140- eq_ (testing .db .execute (stmt ).fetchall (), expected )
145+ eq_ (config .db .execute (stmt ).fetchall (), expected )
141146
142147 def _assert_users (self , users , expected ):
143148 stmt = users .select ().order_by (users .c .id )
144- eq_ (testing .db .execute (stmt ).fetchall (), expected )
149+ with config .db .connect () as conn :
150+ eq_ (conn .execute (stmt ).fetchall (), expected )
0 commit comments