Пример #1
0
    def test_is_data(self):
        operand = Operand(TestModel.test_field_one)
        self.assertFalse(operand.is_data())

        operand = Operand(Condition(TestModel.test_field_one,
                                    TestModel.test_field_two, Operator('=')))
        self.assertFalse(operand.is_data())

        operand = Operand(EmptyOperand())
        self.assertFalse(operand.is_data())

        operand = Operand(1)
        self.assertTrue(operand.is_data())
Пример #2
0
    def test_to_str(self, field_to_str, condition_to_str):
        condition_to_str.return_value = 'test_condition'
        field_to_str.return_value = 'test_field'

        operand = Operand(Condition(TestModel.test_field_one,
                          TestModel.test_field_two, Operator('=')))
        self.assertEqual(operand.to_str(), 'test_condition')
        self.assertTrue(condition_to_str.called)

        operand = Operand(TestModel.test_field_one)
        self.assertEqual(operand.to_str(), 'test_field')
        self.assertTrue(field_to_str.called)

        operand = Operand(1)
        self.assertEqual(operand.to_str(), '%s')

        operand = Operand(None)
        self.assertEqual(operand.to_str(), '%s')

        operand = Operand(EmptyOperand())
        self.assertEqual(operand.to_str(), '')
Пример #3
0
 def test__validate(self, _operators):
     _operators.AND = Operator('TEST_AND')
     self.assertRaises(exceptions.ConditionError, self.condition._validate,
                       TestModelTwo.test_field_one,
                       TestModelTwo.test_field_two, _operators.AND)
Пример #4
0
 def setUp(self):
     self.condition = Condition(TestModel.test_field_one,
                                TestModelTwo.test_field_two, Operator('='))
Пример #5
0
 def test_is_not_null(self):
     self.operators.IS_NULL = Operator('TEST_IS_NOT_NULL')
     condition = self.first_instance.is_not_null()
     self.assertIsInstance(condition, Condition)
     self.assertEqual(condition._operator, self.operators.IS_NOT_NULL)
Пример #6
0
 def test_in_(self):
     self.operators.IN = Operator('TEST_IN')
     condition = self.first_instance.in_([1, 2, 3])
     self.assertIsInstance(condition, Condition)
     self.assertEqual(condition._operator, self.operators.IN)
Пример #7
0
 def test_lt(self):
     self.operators.EQ = Operator('TEST_LT')
     condition = self.first_instance < self.second_instance
     self.assertIsInstance(condition, Condition)
     self.assertEqual(condition._operator, self.operators.LT)
Пример #8
0
 def test_ge(self):
     self.operators.EQ = Operator('TEST_GE')
     condition = self.first_instance >= self.second_instance
     self.assertIsInstance(condition, Condition)
     self.assertEqual(condition._operator, self.operators.GE)
Пример #9
0
 def test_or(self):
     self.operators.AND = Operator('TEST_OR')
     condition = self.first_instance | self.second_instance
     self.assertIsInstance(condition, Condition)
     self.assertEqual(condition._operator, self.operators.OR)
Пример #10
0
from elysium.query.operator import Operator

AND = Operator('AND')
OR = Operator('OR')
EQ = Operator('=')
NE = Operator('<>')
GE = Operator('>=')
GT = Operator('>')
LE = Operator('<=')
LT = Operator('<')
IN = Operator('IN')
IS_NULL = Operator('IS NULL')
IS_NOT_NULL = Operator('IS NOT NULL')