def test_distinct(self):
        ss = SelectStatement('table', distinct_fields=['field2'])
        ss.add_where_clause(WhereClause('field1', EqualsOperator(), 'b'))
        self.assertEqual(six.text_type(ss), 'SELECT DISTINCT "field2" FROM table WHERE "field1" = %(0)s', six.text_type(ss))

        ss = SelectStatement('table', distinct_fields=['field1', 'field2'])
        self.assertEqual(six.text_type(ss), 'SELECT DISTINCT "field1", "field2" FROM table')
Exemple #2
0
 def test_count(self):
     ss = SelectStatement('table', count=True, limit=10, order_by='d')
     ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
     self.assertEqual(
         six.text_type(ss),
         'SELECT COUNT(*) FROM table WHERE "a" = %(0)s LIMIT 10',
         six.text_type(ss))
     self.assertIn('LIMIT', six.text_type(ss))
     self.assertNotIn('ORDER', six.text_type(ss))
    def test_context_id_update(self):
        """ tests that the right things happen the the context id """
        ss = SelectStatement('table')
        ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
        self.assertEqual(ss.get_context(), {'0': 'b'})
        self.assertEqual(str(ss), 'SELECT * FROM table WHERE "a" = %(0)s')

        ss.update_context_id(5)
        self.assertEqual(ss.get_context(), {'5': 'b'})
        self.assertEqual(str(ss), 'SELECT * FROM table WHERE "a" = %(5)s')
    def test_context_id_update(self):
        """ tests that the right things happen the the context id """
        ss = SelectStatement('table')
        ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
        self.assertEqual(ss.get_context(), {'0': 'b'})
        self.assertEqual(str(ss), 'SELECT * FROM table WHERE "a" = %(0)s')

        ss.update_context_id(5)
        self.assertEqual(ss.get_context(), {'5': 'b'})
        self.assertEqual(str(ss), 'SELECT * FROM table WHERE "a" = %(5)s')
 def test_context(self):
     ss = SelectStatement('table')
     ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
     self.assertEqual(ss.get_context(), {'0': 'b'})
 def test_count(self):
     ss = SelectStatement('table', count=True, limit=10, order_by='d')
     ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
     self.assertEqual(six.text_type(ss), 'SELECT COUNT(*) FROM table WHERE "a" = %(0)s LIMIT 10', six.text_type(ss))
     self.assertIn('LIMIT', six.text_type(ss))
     self.assertNotIn('ORDER', six.text_type(ss))
 def test_where_clause_rendering(self):
     ss = SelectStatement('table')
     ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
     self.assertEqual(six.text_type(ss), 'SELECT * FROM table WHERE "a" = %(0)s', six.text_type(ss))
 def test_context(self):
     ss = SelectStatement('table')
     ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
     self.assertEqual(ss.get_context(), {'0': 'b'})
 def test_where_clause_rendering(self):
     ss = SelectStatement('table')
     ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))
     self.assertEqual(six.text_type(ss), 'SELECT * FROM table WHERE "a" = %(0)s', six.text_type(ss))