Example #1
0
 def test_complex_as_string(self):
     proc = kojihub.QueryProcessor(**self.complex_arguments)
     actual = " ".join([token for token in str(proc).split() if token])
     expected = "SELECT something FROM awesome JOIN morestuff" \
                " GROUP BY awesome.aha ORDER BY something OFFSET 10 LIMIT 3"
     self.assertEqual(actual, expected)
     args2 = self.complex_arguments.copy()
     args2['enable_group'] = False
     proc = kojihub.QueryProcessor(**args2)
     actual = " ".join([token for token in str(proc).split() if token])
     expected = "SELECT something FROM awesome JOIN morestuff" \
                " ORDER BY something OFFSET 10 LIMIT 3"
     self.assertEqual(actual, expected)
Example #2
0
 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', {})
Example #3
0
 def getQuery(self, *args, **kwargs):
     query = kojihub.QueryProcessor(*args, **kwargs)
     query.execute = mock.MagicMock()
     query.executeOne = mock.MagicMock()
     query.executeOne.return_value = {'user_tags': 0}
     self.queries.append(query)
     return query
Example #4
0
 def test_simple_as_string(self):
     proc = kojihub.QueryProcessor(
         columns=['something'],
         tables=['awesome'],
     )
     actual = " ".join([token for token in str(proc).split() if token])
     expected = "SELECT something FROM awesome"
     self.assertEqual(actual, expected)
Example #5
0
 def test_simple_count_with_execution(self, context):
     cursor = mock.MagicMock()
     context.cnx.cursor.return_value = cursor
     cursor.fetchall.return_value = [('some count', )]
     args = self.simple_arguments.copy()
     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', {})
     self.assertEqual(results, 'some count')
Example #6
0
 def test_simple_execution_with_iterate(self, context):
     cursor = mock.MagicMock()
     context.cnx.cursor.return_value = cursor
     cursor.fetchall.return_value = [
         ('value number 1', ),
         ('value number 2', ),
         ('value number 3', ),
     ]
     proc = kojihub.QueryProcessor(**self.simple_arguments)
     generator = proc.iterate()
     calls = cursor.execute.mock_calls
     result = next(generator)
     # two calls so far..
     self.assertEqual(result, {'something': 'value number 1'})
     self.assertEqual(len(calls), 2)
     result = next(generator)
     # still two.
     self.assertEqual(result, {'something': 'value number 2'})
     self.assertEqual(len(calls), 2)
     # now three.
     result = next(generator)
     self.assertEqual(result, {'something': 'value number 3'})
Example #7
0
 def test_empty_as_string(self):
     proc = kojihub.QueryProcessor()
     actual = str(proc)
     self.assertIn("SELECT", actual)
     self.assertIn("FROM", actual)
Example #8
0
 def test_instantiation_with_cols_and_aliases(self):
     proc = kojihub.QueryProcessor(columns=['wat'], aliases=['zap'])
     assert 'zap' in proc.colsByAlias
     assert proc.colsByAlias['zap'] == 'wat'
     assert len(proc.colsByAlias) == 1
Example #9
0
 def test_basic_instantiation(self):
     kojihub.QueryProcessor()  # No exception!
Example #10
0
 def test_complex_as_string(self):
     proc = kojihub.QueryProcessor(**self.complex_arguments)
     actual = " ".join([token for token in str(proc).split() if token])
     expected = "SELECT something FROM awesome JOIN morestuff ORDER BY something OFFSET 10 LIMIT 3"
     self.assertEqual(actual, expected)