コード例 #1
0
 def test_q_blank_resolve(self):
     qset = Q() | Q() | Q()
     qset |= Q(Status='new')
     self.assertEqual(
         qset.resolve(),
         "(Status = 'new')"
     )
コード例 #2
0
 def test_q_nested(self):
     qset = (
         Q(Status="backlog")
         & Q(Id__gt=300000)
         | Q(Status="new")
         & Q(Owner="User")
     )
     self.assertEqual(
         qset.resolve(),
         "((Status = 'backlog' AND Id > 300000) OR "
         "(Status = 'new' AND Owner = 'User'))"
     )
コード例 #3
0
    def test_node_iter(self):
        q = Q(blank=True, field=10, query='blank')
        self.assertIsInstance(q.__iter__(), GeneratorType)
        entries = [x for x in q.__iter__()]

        self.assertEqual(len(entries), 3)
        self.assertIn(('blank', True), entries)
        self.assertIn(('field', 10), entries)
        self.assertIn(('query', 'blank'), entries)
コード例 #4
0
 def test_q_simple(self):
     if sys.version_info[:2] >= (3, 6):
         #: works in python3.4-3.5 too, but order is unpredictable
         #: to test it
         query = Q(Status='backlog', Subject__contains='[topic]',
                   Owner='Nobody')
         #: kwargs order saves according to PEP 468
         self.assertEqual(
             query.resolve(),
             "(Status = 'backlog' AND Subject LIKE '[topic]' "
             "AND Owner = 'Nobody')"
         )
     else:
         #: reverse order for older python versions so there's no good idea
         #: to test properly
         query = (
             Q(Status='backlog') & Q(Subject__contains='[topic]')
         ) & Q(Owner='Nobody')
         self.assertEqual(
             query.resolve(),
             "(Status = 'backlog' AND Subject LIKE '[topic]' "
             "AND Owner = 'Nobody')"
         )
コード例 #5
0
 def test_q_complex(self):
     qset = (
         Q(Status='new') & Q(Owner='Nobody') & Q(Owner="User")
     ) | ~Q(Subject__contains='[topic]') & Q(Id__lt=3) & Q(Id__gt=1)
     self.assertEqual(
         qset.resolve(),
         "((Status = 'new' AND Owner = 'Nobody' AND Owner = 'User') OR "
         "((Subject NOT LIKE '[topic]') AND Id < 3 AND Id > 1))"
     )
コード例 #6
0
 def test_node_deepcopy(self):
     q = Q(blank=True)
     new_q = deepcopy(q)
     self.assertEqual(q.children, new_q.children)
コード例 #7
0
 def test_node_add__use_new_instance(self):
     source = Q(field=10)
     q = (
         Q(blank=True) | Q(blank=False)
     ).add(source, connector_type=Q.AND)
     self.assertEqual(len(q.children), 1)
コード例 #8
0
 def test_node_add__squash(self):
     q = Q(blank=True)
     q.add(('blank', False), connector_type=Q.AND, squash=False)
     self.assertEqual(len(q.children), 2)
コード例 #9
0
 def test_node_contains(self):
     qset = Q(blank=True, empty=False)
     self.assertIn(Q(blank=True).children[0], qset)
コード例 #10
0
def op_and(left, right):
    return Q(left) & Q(right)
コード例 #11
0
def op_lt(left, right):
    return Q(**{'%s__lt' % left: right})
コード例 #12
0
 def test_q_negative(self):
     qset = ~Q(Status="backlog") | ~Q(Owner="Nobody")
     query = qset.resolve()
     self.assertEqual(query, "((Status != 'backlog') OR (Owner != 'Nobody'))")
コード例 #13
0
 def test_node_repr(self):
     q = Q(blank=True)
     self.assertEqual(repr(q), "<Q: (AND: ('blank', True))>")
コード例 #14
0
    def test_node_str(self):
        q = Q(blank=True)
        self.assertEqual(str(q), "(AND: ('blank', True))")

        q = ~Q(blank=True)
        self.assertEqual(str(q), "(NOT (AND: ('blank', True)))")
コード例 #15
0
def op_matches(left, right, negate=False):
    if negate:
        return ~Q(**{'%s__contains' % left: right})
    return Q(**{'%s__contains' % left: right})
コード例 #16
0
def op_gt(left, right, negate=False):
    return Q(**{'%s__gt' % left: right})
コード例 #17
0
 def test_combine(self):
     q = Q(blank=True)
     with self.assertRaises(TypeError) as err:
         q._combine(other=['wrong data chunk'], connector=Q.AND)
コード例 #18
0
def op_or(left, right):
    return Q(left) | Q(right)
コード例 #19
0
 def test_node_is_blank(self):
     self.assertFalse(Q())
コード例 #20
0
def op_is(left, right, negate=False):
    if negate:
        return ~Q(**{left: right})
    return Q(**{left: right})
コード例 #21
0
 def test_node_add__duplicate(self):
     q = Q(blank=True)
     q.add(('blank', True), connector_type=Q.AND)
     self.assertEqual(len(q.children), 1)