diff --git a/tests/test_op_sql_execute.py b/tests/test_op_sql_execute.py index 9d61232..cb2744a 100644 --- a/tests/test_op_sql_execute.py +++ b/tests/test_op_sql_execute.py @@ -5,6 +5,11 @@ class SQLExecuteTestCase(BaseTarantoolTestCase): + def _compat_field_name(self, field_name: str) -> str: + if self.conn.version >= (3, 0): + return field_name + return field_name.upper() + @ensure_version(min=(2, 0)) async def test__sql_basic(self): res = await self.conn.execute("select 1, 2") @@ -24,7 +29,10 @@ async def test__sql_with_param(self): async def test__sql_with_param_cols(self): res = await self.conn.execute("select 1 as a, 2 as b where 1 = ?", [1]) - self.assertResponseEqualKV(res, [{"a": 1, "b": 2}], "Body ok") + self.assertResponseEqualKV(res, [{ + self._compat_field_name("a"): 1, + self._compat_field_name("b"): 2, + }], "Body ok") @ensure_version(min=(2, 0)) async def test__sql_with_param_cols2(self): @@ -32,7 +40,10 @@ async def test__sql_with_param_cols2(self): "select 1 as a, 2 as b where 1 = ? and 2 = ?", [1, 2] ) - self.assertResponseEqualKV(res, [{"a": 1, "b": 2}], "Body ok") + self.assertResponseEqualKV(res, [{ + self._compat_field_name("a"): 1, + self._compat_field_name("b"): 2, + }], "Body ok") @ensure_version(min=(2, 0)) async def test__sql_with_param_cols_maps(self): @@ -44,16 +55,22 @@ async def test__sql_with_param_cols_maps(self): ], ) - self.assertResponseEqualKV(res, [{"a": 1, "b": 2}], "Body ok") + self.assertResponseEqualKV(res, [{ + self._compat_field_name("a"): 1, + self._compat_field_name("b"): 2, + }], "Body ok") @ensure_version(min=(2, 0)) async def test__sql_with_param_cols_maps_and_positional(self): res = await self.conn.execute( - "select 1 as a, 2 as b " "where 1 = :p1 and 2 = :p2 and 3 = ? and 4 = ?", + "select 1 as a, 2 as b where 1 = :p1 and 2 = :p2 and 3 = ? and 4 = ?", [{":p1": 1}, {":p2": 2}, 3, 4], ) - self.assertResponseEqualKV(res, [{"a": 1, "b": 2}], "Body ok") + self.assertResponseEqualKV(res, [{ + self._compat_field_name("a"): 1, + self._compat_field_name("b"): 2, + }], "Body ok") @ensure_version(min=(2, 0)) async def test__sql_insert(self): @@ -127,10 +144,10 @@ async def test__sql_select(self): res = await self.conn.execute("select * from sql_space") self.assertEqual(2, res.rowcount, "rowcount is surely ok") - self.assertEqual(1, res.body[0]["id"]) - self.assertEqual("one", res.body[0]["name"]) - self.assertEqual(2, res.body[1]["id"]) - self.assertEqual("two", res.body[1]["name"]) + self.assertEqual(1, res.body[0][self._compat_field_name("id")]) + self.assertEqual("one", res.body[0][self._compat_field_name("name")]) + self.assertEqual(2, res.body[1][self._compat_field_name("id")]) + self.assertEqual("two", res.body[1][self._compat_field_name("name")]) @ensure_version(min=(2, 0)) async def test__sql_delete_multiple(self): @@ -166,9 +183,9 @@ async def test__metadata_names(self): self.assertIsNotNone(res.metadata.fields) self.assertEqual(2, len(res.metadata.fields)) - self.assertEqual("a", res.metadata.fields[0].name) + self.assertEqual(self._compat_field_name("a"), res.metadata.fields[0].name) self.assertEqual("integer", res.metadata.fields[0].type) - self.assertEqual("b", res.metadata.fields[1].name) + self.assertEqual(self._compat_field_name("b"), res.metadata.fields[1].name) self.assertEqual("integer", res.metadata.fields[1].type) @ensure_version(min=(2, 0)) @@ -181,13 +198,13 @@ async def test__metadata_actual_space(self): res = await self.conn.execute("select * from sql_space") self.assertEqual(2, res.rowcount, "rowcount is ok") self.assertEqual(2, len(res.metadata.fields)) - self.assertEqual("id", res.metadata.fields[0].name) + self.assertEqual(self._compat_field_name("id"), res.metadata.fields[0].name) self.assertEqual("integer", res.metadata.fields[0].type) self.assertIsNone(res.metadata.fields[0].is_nullable) self.assertIsNone(res.metadata.fields[0].is_autoincrement) self.assertIsNone(res.metadata.fields[0].collation) - self.assertEqual("name", res.metadata.fields[1].name) + self.assertEqual(self._compat_field_name("name"), res.metadata.fields[1].name) self.assertEqual("string", res.metadata.fields[1].type) self.assertIsNone(res.metadata.fields[1].is_nullable) self.assertIsNone(res.metadata.fields[1].is_autoincrement) @@ -207,13 +224,13 @@ async def test__sql_select_full_metadata(self): try: res = await self.conn.execute("select * from sql_space") self.assertEqual(2, len(res.metadata.fields)) - self.assertEqual("id", res.metadata.fields[0].name) + self.assertEqual(self._compat_field_name("id"), res.metadata.fields[0].name) self.assertEqual("integer", res.metadata.fields[0].type) self.assertEqual(False, res.metadata.fields[0].is_nullable) self.assertEqual(None, res.metadata.fields[1].is_autoincrement) self.assertIsNone(res.metadata.fields[0].collation) - self.assertEqual("name", res.metadata.fields[1].name) + self.assertEqual(self._compat_field_name("name"), res.metadata.fields[1].name) self.assertEqual("string", res.metadata.fields[1].type) self.assertEqual(True, res.metadata.fields[1].is_nullable) self.assertEqual(None, res.metadata.fields[1].is_autoincrement)