Exemple #1
0
 def test_init(self):
     self.assertRaises(TypeError, sql.Tree, '', sql.Node, sql.Node)
     self.assertRaises(TypeError, sql.Tree, sql.Node, '', sql.Node)
     self.assertRaises(TypeError, sql.Tree, sql.Node, sql.Node, '')
     self.assertEqual(sql.Tree(sql.Str('a'), sql.Str('b'), sql.Str('c')).tree, 'a')
     self.assertEqual(sql.Tree(sql.Str('a'), sql.Str('b'), sql.Str('c')).left, 'b')
     self.assertEqual(sql.Tree(sql.Str('a'), sql.Str('b'), sql.Str('c')).right, 'c')
Exemple #2
0
 def test_Or(self):
     b = sql.Or(sql.Str('a'), sql.Str('b'))
     self.assertTrue(b)
     self.assertTrue(sql.Or(sql.Str('a'), sql.Str('')))
     self.assertTrue(sql.Or(sql.Str(''), sql.Str('b')))
     self.assertFalse(sql.Or(sql.Str(''), sql.Str('')))
     self.assertEqual(b, 'a or b')
Exemple #3
0
 def test_And(self):
     a = sql.And(sql.Str('a'), sql.Str('b'))
     self.assertTrue(a)
     self.assertTrue(sql.And(sql.Str('a'), sql.Str('')))
     self.assertTrue(sql.And(sql.Str(''), sql.Str('b')))
     self.assertFalse(sql.And(sql.Str(''), sql.Str('')))
     self.assertEqual(a, 'a and b')
Exemple #4
0
    def test_where(self):
        self.assertRaises(TypeError, sql.Where, '=', 1, 'a')
        w = sql.Where('=', 'id', 3)
        self.assertTrue(w)
        self.assertTrue(sql.Where('=', 'id', sql.Value(None)))
        self.assertEqual(w.operation, sql.WHERE.EQUAL)
        self.assertEqual(w, 'id = 3')
        self.assertEqual(sql.Where('=', 'id', '3'), 'id = "3"')

        self.assertEqual(sql.WhereTrue(), '1')
        self.assertEqual(sql.WhereStr('abc'), 'abc')

        self.assertEqual(sql.WhereEqual('id', None), 'id is NULL')
        self.assertEqual(sql.WhereNotEqual('id', None), 'id is not NULL')
        self.assertEqual(sql.WhereLess('id', None), 'id < NULL')
        self.assertEqual(sql.WhereLessEqual('id', sql.Str('')), 'id <=')
        self.assertEqual(sql.WhereGreater('id', sql.Value()), 'id > NULL')
        self.assertEqual(sql.WhereGreaterEqual('id', sql.Key('id')), 'id >= `id`')
        self.assertEqual(sql.WhereIn('id', (1, None, False, '')), 'id in ( 1, NULL, False, "" )')
        self.assertEqual(sql.WhereNotIn('id', ()), 'id not in (  )')
        self.assertEqual(sql.WhereBetween('id', '', None), 'id between ""')
        self.assertEqual(sql.WhereNotBetween('id', '', False), 'id not between "" and False')
        self.assertEqual(sql.WhereLike('id', ''), 'id like ""')
        self.assertRaises(TypeError, sql.WhereNotLike, 'id', 1)
        self.assertEqual(sql.WhereNotLike('id', '%s'), 'id not like "%s"')
Exemple #5
0
 def test_to_sql(self):
     self.assertEqual(sql.Str('a'), 'a')
Exemple #6
0
 def test_is_equal(self):
     s_1 = sql.Str('')
     s_2 = sql.Str('1')
     self.assertEqual(s_1, '')
     self.assertNotEqual(s_1, s_2)
Exemple #7
0
 def test_is_true(self):
     s_1 = sql.Str('')
     s_2 = sql.Str('1')
     self.assertTrue(s_2)
     self.assertFalse(s_1)
Exemple #8
0
 def test_hash(self):
     s = sql.Str('a')
     self.assertEqual(hash(s), hash('a'))
Exemple #9
0
 def test_init(self):
     s = sql.Str('')
     self.assertEqual(s.str, '')
     self.assertEqual(s._str, s.str)
     self.assertEqual(type(s.str), str)
Exemple #10
0
 def test_Bracket(self):
     a = sql.Bracket(sql.Str('a'))
     self.assertTrue(a)
     self.assertFalse(sql.Bracket(sql.Str('')))
     self.assertEqual(a, '( a )')
     self.assertEqual(a.bracket(), '( ( a ) )')
Exemple #11
0
 def test_and_or_bracket(self):
     a = sql.Tree(sql.TREE.AND, sql.Str('a'), sql.Str('b'))
     self.assertEqual(a, 'a and b')
     self.assertEqual(a.and_(sql.Str('c')), 'a and b and c')
     self.assertEqual(a.or_(sql.Str('c')), 'a and b or c')
     self.assertEqual(a.bracket(), '( a and b )')
Exemple #12
0
 def test_sql(self):
     self.assertEqual(sql.Tree(sql.Str('a'), sql.Str('b'), sql.Str('c')), 'b a c')
     self.assertEqual(sql.Tree(sql.Str(''), sql.Str('b'), sql.Str('c')), 'b')
     self.assertEqual(sql.Tree(sql.Str('a'), sql.Str(''), sql.Str('c')), 'c')
     self.assertEqual(sql.Tree(sql.Str('a'), sql.Str('b'), sql.Str('')), 'b')
Exemple #13
0
 def test_bool(self):
     self.assertTrue(sql.Tree(sql.Str('a'), sql.Str('b'), sql.Str('c')))
     self.assertFalse(sql.Tree(sql.Str(''), sql.Str('b'), sql.Str('c')))
     self.assertTrue(sql.Tree(sql.Str('a'), sql.Str(''), sql.Str('c')))
     self.assertTrue(sql.Tree(sql.Str('a'), sql.Str('b'), sql.Str('')))
Exemple #14
0
 def test_iter(self):
     t, l, r = sql.Tree(sql.Str('a'), sql.Str('b'), sql.Str('c'))
     self.assertEqual(t, 'a')
     self.assertEqual(l, 'b')
     self.assertEqual(r, 'c')
Exemple #15
0
 def test_init(self):
     self.assertRaises(TypeError, sql.List, ('',))
     self.assertEqual(sql.List((sql.Str('a'),)), 'a')
     self.assertEqual(sql.List((sql.Value(),)), 'NULL')