Skip to content

Commit

Permalink
fix sql tests for tarantool < 3
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcoding committed May 5, 2024
1 parent 7beeb29 commit 08dc96c
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions tests/test_op_sql_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -24,15 +29,21 @@ 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):
res = await self.conn.execute(
"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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 08dc96c

Please sign in to comment.