Exemple #1
0
 def test_parse_sqla_and_or_conjunctions(self):
     r = parse_dictionary(
         {
             'or_':
             '[{"username": "******"}, {"and_": ['
             '{"username": "******"},{"ref": "smith"}]}]'
         }, self.model)
     self.assertEqual(
         str(r[0]), 'contacts.username = :username_1 OR '
         'contacts.username = :username_2 AND '
         'contacts.ref = :ref_1')
     self.assertEqual(type(r), list)
     self.assertEqual(type(r[0]), BooleanClauseList)
     self.assertEqual(r[0].operator, or_)
     self.assertEqual(len(r[0].clauses), 2)
     expected_expression = sqla_op.eq(self.model.username, 'john')
     self.assertTrue(expected_expression.compare(r[0].clauses[0]))
     second_op = r[0].clauses[1]
     self.assertEqual(type(second_op), BooleanClauseList)
     self.assertEqual(second_op.operator, and_)
     self.assertEqual(len(second_op.clauses), 2)
     expected_expression = sqla_op.eq(self.model.username, 'dylan')
     self.assertTrue(expected_expression.compare(second_op.clauses[0]))
     expected_expression = sqla_op.eq(self.model.ref, 'smith')
     self.assertTrue(expected_expression.compare(second_op.clauses[1]))
Exemple #2
0
 def test_or_bool_op(self):
     r = parse('username == "john" or prog == 5', self.model)
     self.assertEqual(type(r), list)
     self.assertEqual(type(r[0]), BooleanClauseList)
     self.assertEqual(r[0].operator, or_)
     self.assertEqual(len(r[0].clauses), 2)
     expected_expression = sqla_op.eq(self.model.username, 'john')
     self.assertTrue(expected_expression.compare(r[0].clauses[0]))
     expected_expression = sqla_op.eq(self.model.prog, 5)
     self.assertTrue(expected_expression.compare(r[0].clauses[1]))
Exemple #3
0
 def test_or_bool_op(self):
     r = parse('firstname == "john" or prog == 5', self.model)
     self.assertEqual(type(r), list)
     self.assertEqual(type(r[0]), BooleanClauseList)
     self.assertEqual(r[0].operator, or_)
     self.assertEqual(len(r[0].clauses), 2)
     expected_expression = sqla_op.eq(self.model.firstname, 'john')
     self.assertTrue(expected_expression.compare(r[0].clauses[0]))
     expected_expression = sqla_op.eq(self.model.prog, 5)
     self.assertTrue(expected_expression.compare(r[0].clauses[1]))
Exemple #4
0
 def test_parse_dictionary(self):
     r = parse_dictionary({'firstname': 'john', 'prog': 5}, self.model)
     self.assertEqual(type(r), list)
     self.assertTrue(len(r) == 2)
     expected_expression = sqla_op.eq(self.model.firstname, 'john')
     any_true = any(expected_expression.compare(elem) for elem in r)
     self.assertTrue(any_true)
     expected_expression = sqla_op.eq(self.model.prog, 5)
     any_true = any(expected_expression.compare(elem) for elem in r)
     self.assertTrue(any_true)
Exemple #5
0
 def test_parse_dictionary(self):
     r = parse_dictionary({'firstname': 'john', 'prog': 5}, self.model)
     self.assertEqual(type(r), list)
     self.assertTrue(len(r) == 2)
     expected_expression = sqla_op.eq(self.model.firstname, 'john')
     any_true = any(expected_expression.compare(elem) for elem in r)
     self.assertTrue(any_true)
     expected_expression = sqla_op.eq(self.model.prog, 5)
     any_true = any(expected_expression.compare(elem) for elem in r)
     self.assertTrue(any_true)
Exemple #6
0
 def test_nested_bool_op(self):
     r = parse('username == "john" or (prog == 5 and ref == "smith")',
               self.model)
     self.assertEqual(type(r), list)
     self.assertEqual(type(r[0]), BooleanClauseList)
     self.assertEqual(r[0].operator, or_)
     self.assertEqual(len(r[0].clauses), 2)
     expected_expression = sqla_op.eq(self.model.username, 'john')
     self.assertTrue(expected_expression.compare(r[0].clauses[0]))
     second_op = r[0].clauses[1]
     self.assertEqual(type(second_op), BooleanClauseList)
     self.assertEqual(second_op.operator, and_)
     self.assertEqual(len(second_op.clauses), 2)
     expected_expression = sqla_op.eq(self.model.prog, 5)
     self.assertTrue(expected_expression.compare(second_op.clauses[0]))
     expected_expression = sqla_op.eq(self.model.ref, 'smith')
     self.assertTrue(expected_expression.compare(second_op.clauses[1]))
Exemple #7
0
 def test_nested_bool_op(self):
     r = parse('firstname == "john" or (prog == 5 and lastname == "smith")',
               self.model)
     self.assertEqual(type(r), list)
     self.assertEqual(type(r[0]), BooleanClauseList)
     self.assertEqual(r[0].operator, or_)
     self.assertEqual(len(r[0].clauses), 2)
     expected_expression = sqla_op.eq(self.model.firstname, 'john')
     self.assertTrue(expected_expression.compare(r[0].clauses[0]))
     second_op = r[0].clauses[1]
     self.assertEqual(type(second_op), BooleanClauseList)
     self.assertEqual(second_op.operator, and_)
     self.assertEqual(len(second_op.clauses), 2)
     expected_expression = sqla_op.eq(self.model.prog, 5)
     self.assertTrue(expected_expression.compare(second_op.clauses[0]))
     expected_expression = sqla_op.eq(self.model.lastname, 'smith')
     self.assertTrue(expected_expression.compare(second_op.clauses[1]))
Exemple #8
0
 def test_parse_sqla_and_or_conjunctions(self):
     r = parse_dictionary(
         {'or_': '[{"firstname": "john"}, {"and_": ['
          '{"firstname": "dylan"},{"lastname": "smith"}]}]'}, self.model)
     self.assertEqual(str(r[0]),
                      'people.firstname = :firstname_1 OR '
                      'people.firstname = :firstname_2 AND '
                      'people.lastname = :lastname_1')
     self.assertEqual(type(r), list)
     self.assertEqual(type(r[0]), BooleanClauseList)
     self.assertEqual(r[0].operator, or_)
     self.assertEqual(len(r[0].clauses), 2)
     expected_expression = sqla_op.eq(self.model.firstname, 'john')
     self.assertTrue(expected_expression.compare(r[0].clauses[0]))
     second_op = r[0].clauses[1]
     self.assertEqual(type(second_op), BooleanClauseList)
     self.assertEqual(second_op.operator, and_)
     self.assertEqual(len(second_op.clauses), 2)
     expected_expression = sqla_op.eq(self.model.firstname, 'dylan')
     self.assertTrue(expected_expression.compare(second_op.clauses[0]))
     expected_expression = sqla_op.eq(self.model.lastname, 'smith')
     self.assertTrue(expected_expression.compare(second_op.clauses[1]))
Exemple #9
0
 def test_eq(self):
     expected_expression = sqla_op.eq(self.model.username, 'john')
     r = parse('username == john', self.model)
     self.assertEqual(type(r), list)
     self.assertTrue(len(r) == 1)
     self.assertTrue(expected_expression.compare(r[0]))
Exemple #10
0
 def test_eq(self):
     expected_expression = sqla_op.eq(self.model.firstname, 'john')
     r = parse('firstname == john', self.model)
     self.assertEqual(type(r), list)
     self.assertTrue(len(r) == 1)
     self.assertTrue(expected_expression.compare(r[0]))