@@ -41,19 +41,19 @@ def setUpClass(cls):
4141 "ts" : "2020-09-17 13:49:32.780180" ,
4242 } for i in range (2048 )]
4343 )
44- except aurora_data_api .DatabaseError as e :
45- if e .args [0 ] != MySQLErrorCodes .ER_PARSE_ERROR :
46- raise
44+ except aurora_data_api .MySQLError .ER_PARSE_ERROR :
4745 cls .using_mysql = True
4846 cur .execute ("DROP TABLE IF EXISTS aurora_data_api_test" )
49- cur .execute (
50- "CREATE TABLE aurora_data_api_test (id SERIAL, name TEXT, birthday DATE, num NUMERIC(10, 5))"
51- )
47+ cur .execute ("CREATE TABLE aurora_data_api_test "
48+ "(id SERIAL, name TEXT, birthday DATE, num NUMERIC(10, 5), ts TIMESTAMP)" )
5249 cur .executemany (
53- "INSERT INTO aurora_data_api_test(name, birthday, num) VALUES (:name, :birthday, :num)" , [{
50+ ("INSERT INTO aurora_data_api_test(name, birthday, num, ts) VALUES "
51+ "(:name, :birthday, :num, CAST(:ts AS DATETIME))" ),
52+ [{
5453 "name" : "row{}" .format (i ),
5554 "birthday" : "2000-01-01" ,
56- "num" : decimal .Decimal ("%d.%d" % (i , i ))
55+ "num" : decimal .Decimal ("%d.%d" % (i , i )),
56+ "ts" : "2020-09-17 13:49:32.780180" ,
5757 } for i in range (2048 )]
5858 )
5959
@@ -64,7 +64,8 @@ def tearDownClass(cls):
6464
6565 def test_invalid_statements (self ):
6666 with aurora_data_api .connect (database = self .db_name ) as conn , conn .cursor () as cur :
67- with self .assertRaisesRegex (aurora_data_api .DatabaseError , "syntax" ):
67+ with self .assertRaises ((aurora_data_api .exceptions .PostgreSQLError .ER_SYNTAX_ERR ,
68+ aurora_data_api .MySQLError .ER_PARSE_ERROR )):
6869 cur .execute ("selec * from table" )
6970
7071 def test_iterators (self ):
@@ -83,8 +84,10 @@ def test_iterators(self):
8384 expect_row0 = (1 ,
8485 'row0' ,
8586 datetime .date (2000 , 1 , 1 ) if self .using_mysql else '{"x": 0, "y": "0", "z": [0, 0, 1]}' ,
86- decimal .Decimal (0 ),
87- datetime .datetime (2020 , 9 , 17 , 13 , 49 , 32 , 780180 ))
87+ decimal .Decimal (0.0 ),
88+ datetime .datetime (2020 , 9 , 17 , 13 , 49 , 33 )
89+ if self .using_mysql
90+ else datetime .datetime (2020 , 9 , 17 , 13 , 49 , 32 , 780180 ))
8891 i = 0
8992 cursor .execute ("select * from aurora_data_api_test" )
9093 for f in cursor :
@@ -142,12 +145,11 @@ def test_postgres_exceptions(self):
142145 return
143146 with aurora_data_api .connect (database = self .db_name ) as conn , conn .cursor () as cur :
144147 table = "aurora_data_api_nonexistent_test_table"
145- with self .assertRaises (aurora_data_api .DatabaseError ) as e :
148+ with self .assertRaises (aurora_data_api .exceptions . PostgreSQLError . ER_UNDEF_TABLE ) as e :
146149 sql = f"select * from { table } "
147150 cur .execute (sql )
148- self .assertEqual (e .exception .args , (PostgreSQLErrorCodes .ER_UNDEF_TABLE ,
149- f'relation "{ table } " does not exist' ,
150- 15 ))
151+ self .assertTrue (f'relation "{ table } " does not exist' in str (e .exception ))
152+ self .assertTrue (isinstance (e .exception .response , dict ))
151153
152154 def test_rowcount (self ):
153155 with aurora_data_api .connect (database = self .db_name ) as conn , conn .cursor () as cur :
0 commit comments