Example #1
0
 def test_xmlextractvalue_invalid_xml(self):
     Alphabet.objects.create(d='{"this": "isNotXML"}')
     ab = (
         Alphabet.objects.annotate(ev=XMLExtractValue('d', '/some'))
                         .first()
     )
     assert ab.ev == ''
 def test_xmlextractvalue_expression(self):
     Alphabet.objects.create(d="<some><xml /></some>")
     evs = list(
         Alphabet.objects.annotate(
             ev=XMLExtractValue("d", Value("count(/some)"))).values_list(
                 "ev", flat=True))
     assert evs == ["1"]
Example #3
0
 def test_xmlextractvalue_simple(self):
     Alphabet.objects.create(d='<some><xml /></some>')
     Alphabet.objects.create(d='<someother><xml /></someother>')
     Alphabet.objects.create(d='<some></some><some></some>')
     evs = list(
         Alphabet.objects.annotate(ev=XMLExtractValue('d', 'count(/some)'))
                         .values_list('ev', flat=True),
     )
     assert evs == ['1', '0', '2']
Example #4
0
 def test_xmlextractvalue_simple(self):
     Alphabet.objects.create(d="<some><xml /></some>")
     Alphabet.objects.create(d="<someother><xml /></someother>")
     Alphabet.objects.create(d="<some></some><some></some>")
     evs = list(
         Alphabet.objects.annotate(
             ev=XMLExtractValue("d", "count(/some)")).values_list(
                 "ev", flat=True))
     assert evs == ["1", "0", "2"]