#3513 Return data when query execute asList with transform
Merged 2 years ago by tkopecek. Opened 2 years ago by jcupova.
jcupova/koji issue-3512  into  master

file modified
+1
@@ -9599,6 +9599,7 @@ 

                  data = [self.transform(row) for row in data]

                  # and then convert back to lists

                  data = [[row[f] for f in fields] for row in data]

+                 return data

          else:

              data = _multiRow(query, self.values, (self.aliases or self.columns))

              if self.transform is not None:

@@ -15,15 +15,15 @@ 

              aliases=['other'],

              tables=['awesome'],

              joins=['morestuff'],

-             #values=...

-             #transform=...

+             # values=...

+             # transform=...

              opts={

-                 #'countOnly': True,

+                 # 'countOnly': True,

                  'order': 'other',

                  'offset': 10,

                  'limit': 3,

                  'group': 'awesome.aha'

-                 #'rowlock': True,

+                 # 'rowlock': True,

              },

              enable_group=True

          )
@@ -71,14 +71,14 @@ 

                     " ORDER BY something OFFSET 10 LIMIT 3"

          self.assertEqual(actual, expected)

  

- 

      @mock.patch('kojihub.context')

      def test_simple_with_execution(self, context):

          cursor = mock.MagicMock()

          context.cnx.cursor.return_value = cursor

          proc = kojihub.QueryProcessor(**self.simple_arguments)

          proc.execute()

-         cursor.execute.assert_called_once_with('\nSELECT something\n  FROM awesome\n\n\n \n \n\n \n', {})

+         cursor.execute.assert_called_once_with(

+             '\nSELECT something\n  FROM awesome\n\n\n \n \n\n \n', {})

  

      @mock.patch('kojihub.context')

      def test_simple_count_with_execution(self, context):
@@ -89,7 +89,8 @@ 

          args['opts'] = {'countOnly': True}

          proc = kojihub.QueryProcessor(**args)

          results = proc.execute()

-         cursor.execute.assert_called_once_with('\nSELECT count(*)\n  FROM awesome\n\n\n \n \n\n \n', {})

+         cursor.execute.assert_called_once_with(

+             '\nSELECT count(*)\n  FROM awesome\n\n\n \n \n\n \n', {})

          self.assertEqual(results, 'some count')

  

          cursor.reset_mock()
@@ -102,8 +103,6 @@ 

              '  FROM awesome\n\n\n GROUP BY id\n \n\n \n) numrows', {})

          self.assertEqual(results, 'some count')

  

- 

- 

      @mock.patch('kojihub.context')

      def test_simple_execution_with_iterate(self, context):

          cursor = mock.MagicMock()
@@ -128,3 +127,17 @@ 

          result = next(generator)

          self.assertEqual(result, {'something': 'value number 3'})

  

+     @mock.patch('kojihub._multiRow')

+     def test_execution_as_list_transform(self, multirow):

+         multirow.return_value = [{'col1': 'result_1_col_1', 'col2': 'result_1_col_2'},

+                                  {'col1': 'result_2_col_1', 'col2': 'result_2_col_2'}]

+         args = dict(

+             columns=['col1', 'col2'],

+             tables=['table'],

+             opts={'asList': True},

+             transform=lambda x: x,

+         )

+         proc = kojihub.QueryProcessor(**args)

+         results = proc.execute()

+         self.assertEqual(

+             results, [['result_1_col_1', 'result_1_col_2'], ['result_2_col_1', 'result_2_col_2']])

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 years ago

Metadata Update from @tkopecek:
- Pull-request untagged with: testing-ready
- Pull-request tagged with: no_qe

2 years ago

Commit f4bb294 fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago