예제 #1
0
 def test_succeed_build_calc_query(self):
     table = 'example1'
     limit = 1000
     spec = {
         u'filter': {},
         u'meta': {
             u'grp': {
                 u'sort': u'sum(val1)',
                 u'asc': True,
                 u'stat': {
                     u'stat': u'sum',
                     u'name': u'sum(val1)',
                     u'key': u'val1'
                 }
             }
         },
         u'trans': [],
         u'stats': {
             u'stats': [{
                 u'stat': u'sum',
                 u'name': u'sum(val1)',
                 u'key': u'val1'
             }],
             u'groups': [u'grp']
         },
         u'select': [u'grp', u'sum(val1)']
     }
     result = [(u'A', ), (u'B', )]
     query, params = QueryBuilder.build_calc_query(table, spec, limit,
                                                   result)
     self.assertEqual(
         query,
         "SELECT grp, sum(val1) FROM example1 WHERE grp in (?,?) GROUP BY grp LIMIT ?"
     )
     self.assertEqual(params, [u'A', u'B', '1000'])
예제 #2
0
 def test_succeed_build_sort_query(self):
     table = 'example1'
     spec = {
         u'filter': {},
         u'meta': {
             u'grp': {
                 u'sort': u'sum(val1)',
                 u'asc': True,
                 u'stat': {
                     u'stat': u'sum',
                     u'name': u'sum(val1)',
                     u'key': u'val1'
                 }
             }
         },
         u'trans': [],
         u'stats': {
             u'stats': [{
                 u'stat': u'sum',
                 u'name': u'sum(val1)',
                 u'key': u'val1'
             }],
             u'groups': [u'grp']
         },
         u'select': [u'grp', u'sum(val1)']
     }
     query, params = QueryBuilder.build_sort_query(table, spec)
     self.assertEqual(
         query, 'SELECT grp FROM example1 GROUP BY grp ORDER BY ? ASC ')
     self.assertEqual(params, [u'sum(val1)'])
예제 #3
0
파일: tests.py 프로젝트: Nouhi/polychart2
 def test_succeed_build_calc_query(self):
   table = 'example1'
   limit = 1000
   spec = {u'filter': {}, u'meta': {u'grp': {u'sort': u'sum(val1)', u'asc': True, u'stat': {u'stat': u'sum', u'name': u'sum(val1)', u'key': u'val1'}}}, u'trans': [], u'stats': {u'stats': [{u'stat': u'sum', u'name': u'sum(val1)', u'key': u'val1'}], u'groups': [u'grp']}, u'select': [u'grp', u'sum(val1)']}
   result = [(u'A',), (u'B',)]
   query, params = QueryBuilder.build_calc_query(table, spec, limit, result)
   self.assertEqual(query, "SELECT grp, sum(val1) FROM example1 WHERE grp in (?,?) GROUP BY grp LIMIT ?")
   self.assertEqual(params, [u'A', u'B', '1000'])
예제 #4
0
파일: tests.py 프로젝트: Nouhi/polychart2
 def test_succeed_build_sort_query(self):
   table = 'example1'
   spec = {u'filter': {}, u'meta': {u'grp': {u'sort': u'sum(val1)', u'asc': True, u'stat': {u'stat': u'sum', u'name': u'sum(val1)', u'key': u'val1'}}}, u'trans': [], u'stats': {u'stats': [{u'stat': u'sum', u'name': u'sum(val1)', u'key': u'val1'}], u'groups': [u'grp']}, u'select': [u'grp', u'sum(val1)']}
   query, params = QueryBuilder.build_sort_query(table, spec)
   self.assertEqual(query, 'SELECT grp FROM example1 GROUP BY grp ORDER BY ? ASC ')
   self.assertEqual(params, [u'sum(val1)'])