diff options
author | slideon <adamkasztenny@gmail.com> | 2016-04-01 09:51:57 -0400 |
---|---|---|
committer | jan iversen <jani@documentfoundation.org> | 2016-04-04 06:39:39 +0000 |
commit | 9338e4f5b1ffcba2d5b0bd8960dd8795d8909ff1 (patch) | |
tree | ff725921c3adfbc3c993de003a4812a0550f4e59 /dbaccess/qa/python | |
parent | 157bfa806388053e573e97b26871d6de4d6dce52 (diff) |
tdf#97361 Refactor dbaccess test again
Remove duplicate code, add helper functions and constants
Change-Id: Ib8702e2ce9918b47a608f6eb6fd2af7fd4dd1d0d
Reviewed-on: https://gerrit.libreoffice.org/23727
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: jan iversen <jani@documentfoundation.org>
Diffstat (limited to 'dbaccess/qa/python')
-rw-r--r-- | dbaccess/qa/python/fdo84315.py | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/dbaccess/qa/python/fdo84315.py b/dbaccess/qa/python/fdo84315.py index a4bbc1b926b1..03acc0a92e2f 100644 --- a/dbaccess/qa/python/fdo84315.py +++ b/dbaccess/qa/python/fdo84315.py @@ -14,8 +14,6 @@ import unohelper from org.libreoffice.unotest import UnoInProcess class Fdo84315(unittest.TestCase): - _uno = None - _xDoc = None @classmethod def setUpClass(cls): @@ -28,47 +26,49 @@ class Fdo84315(unittest.TestCase): def tearDownClass(cls): cls._uno.tearDown() + def __test_Query(self, column_name, expected_type, xResultset): + self.assertTrue(xResultset) + xMeta = xResultset.MetaData + self.assertEqual(xMeta.ColumnCount, 1) + self.assertEqual(xResultset.findColumn(column_name), 1) + self.assertEqual(xMeta.getColumnName(1), column_name) + self.assertEqual(xMeta.getColumnType(1), expected_type) + return xMeta + + def __test_ResultSetInteger(self, xResultset, expected_values): + while xResultset.next(): + self.assertEqual(xResultset.getInt(1), expected_values.popleft()) + self.assertEqual(len(expected_values), 0) + + def __test_ResultSetString(self, xResultset, expected_values): + while xResultset.next(): + self.assertEqual(xResultset.getString(1), expected_values.popleft()) + self.assertEqual(len(expected_values), 0) + def test_fdo84315(self): xDoc = self.__class__._xDoc xDataSource = xDoc.DataSource xCon = xDataSource.getConnection('','') xStatement = xCon.createStatement() + NUMERIC = 2 + VAR_CHAR = 12 + INTEGER = 4 + xResultset = xStatement.executeQuery('SELECT "count" FROM "test_table"') expected_values = deque([42, 4711]) - self.assertTrue(xResultset) - xMeta = xResultset.MetaData - self.assertEqual(xMeta.ColumnCount, 1) - self.assertEqual(xResultset.findColumn("count"), 1) - self.assertEqual(xMeta.getColumnName(1), "count"); - self.assertEqual(xMeta.getColumnType(1), 2); # numeric - while xResultset.next(): - self.assertEqual(xResultset.getInt(1), expected_values.popleft()) - self.assertEqual(len(expected_values), 0) + xMeta = self.__test_Query('count', NUMERIC, xResultset) + self.__test_ResultSetInteger(xResultset, expected_values) xResultset = xStatement.executeQuery('SELECT "name" FROM "test_table"') expected_values = deque(['foo', 'bar']) - self.assertTrue(xResultset) - xMeta = xResultset.MetaData - self.assertEqual(xMeta.ColumnCount, 1) - self.assertEqual(xResultset.findColumn("name"), 1) - self.assertEqual(xMeta.getColumnName(1), "name"); - self.assertEqual(xMeta.getColumnType(1), 12); # varchar - while xResultset.next(): - self.assertEqual(xResultset.getString(1), expected_values.popleft()) - self.assertEqual(len(expected_values), 0) + xMeta = self.__test_Query('name', VAR_CHAR, xResultset) + self.__test_ResultSetString(xResultset, expected_values) xResultset = xStatement.executeQuery('SELECT "id" FROM "test_table"') expected_values = deque([0, 1]) - self.assertTrue(xResultset) - xMeta = xResultset.MetaData - self.assertEqual(xMeta.ColumnCount, 1) - self.assertEqual(xResultset.findColumn("id"), 1) - self.assertEqual(xMeta.getColumnName(1), "id"); - self.assertEqual(xMeta.getColumnType(1), 4); # integer - while xResultset.next(): - self.assertEqual(xResultset.getInt(1), expected_values.popleft()) - self.assertEqual(len(expected_values), 0) + xMeta = self.__test_Query('id', INTEGER, xResultset) + self.__test_ResultSetInteger(xResultset, expected_values) xCon.dispose() |