Ejemplo n.º 1
0
 def test_field_simple(self):
     Alphabet.objects.create(d='a')
     ab = Alphabet.objects.annotate(dp=Field('d', ['a', 'b'])).first()
     assert ab.dp == 1
     ab = Alphabet.objects.annotate(dp=Field('d', ['b', 'a'])).first()
     assert ab.dp == 2
     ab = Alphabet.objects.annotate(dp=Field('d', ['c', 'd'])).first()
     assert ab.dp == 0
Ejemplo n.º 2
0
 def test_field_simple(self):
     Alphabet.objects.create(d="a")
     ab = Alphabet.objects.annotate(dp=Field("d", ["a", "b"])).first()
     assert ab.dp == 1
     ab = Alphabet.objects.annotate(dp=Field("d", ["b", "a"])).first()
     assert ab.dp == 2
     ab = Alphabet.objects.annotate(dp=Field("d", ["c", "d"])).first()
     assert ab.dp == 0
Ejemplo n.º 3
0
 def test_order_by(self):
     Alphabet.objects.create(a=1, d='AAA')
     Alphabet.objects.create(a=2, d='CCC')
     Alphabet.objects.create(a=4, d='BBB')
     Alphabet.objects.create(a=3, d='BBB')
     avalues = list(
         Alphabet.objects.order_by(Field('d', ['AAA', 'BBB']),
                                   'a').values_list('a', flat=True), )
     assert avalues == [2, 1, 3, 4]
Ejemplo n.º 4
0
 def test_order_by(self):
     Alphabet.objects.create(a=1, d="AAA")
     Alphabet.objects.create(a=2, d="CCC")
     Alphabet.objects.create(a=4, d="BBB")
     Alphabet.objects.create(a=3, d="BBB")
     avalues = list(
         Alphabet.objects.order_by(Field("d", ["AAA", "BBB"]),
                                   "a").values_list("a", flat=True))
     assert avalues == [2, 1, 3, 4]
Ejemplo n.º 5
0
 def test_field_expression(self):
     Alphabet.objects.create(d="b")
     ab = Alphabet.objects.annotate(
         dp=Field("d", [Value("a"), Value("b")])).first()
     assert ab.dp == 2