Exemplo n.º 1
0
 def test_regex_instr_expression(self):
     Alphabet.objects.create(d="ABBC")
     ab = (Alphabet.objects.annotate(
         d_double_pos=RegexpInstr("d", Value(r"[b]{2}"))).filter(
             d_double_pos__gt=0).get())
     assert ab.d == "ABBC"
     assert ab.d_double_pos == 2
Exemplo n.º 2
0
 def test_regex_instr(self):
     Alphabet.objects.create(d="ABC")
     Alphabet.objects.create(d="ABBC")
     ab = (Alphabet.objects.annotate(
         d_double_pos=RegexpInstr('d', r'[b]{2}')).filter(
             d_double_pos__gt=0).get())
     assert ab.d == "ABBC"
     assert ab.d_double_pos == 2
Exemplo n.º 3
0
 def test_regex_instr_update(self):
     Alphabet.objects.create(d="A string to search")
     Alphabet.objects.create(d="Something to query")
     Alphabet.objects.create(d="Please do inspect me")
     Alphabet.objects.update(a=RegexpInstr("d", r"search|query|inspect") - 1)
     all_abs = Alphabet.objects.all().order_by("id")
     assert all_abs[0].a == 12
     assert all_abs[1].a == 13
     assert all_abs[2].a == 10