@@ -663,32 +663,32 @@ def test_suggest_terms(self):
663
663
args , kwargs = self .solr ._send_request .call_args
664
664
self .assertTrue (args [1 ].startswith ("fakehandler" ))
665
665
666
- def test__build_doc (self ):
666
+ def test__build_xml_doc (self ):
667
667
doc = {
668
668
"id" : "doc_1" ,
669
669
"title" : "Example doc ☃ 1" ,
670
670
"price" : 12.59 ,
671
671
"popularity" : 10 ,
672
672
}
673
673
doc_xml = force_unicode (
674
- ElementTree .tostring (self .solr ._build_doc (doc ), encoding = "utf-8" )
674
+ ElementTree .tostring (self .solr ._build_xml_doc (doc ), encoding = "utf-8" )
675
675
)
676
676
self .assertIn ('<field name="title">Example doc ☃ 1</field>' , doc_xml )
677
677
self .assertIn ('<field name="id">doc_1</field>' , doc_xml )
678
678
self .assertEqual (len (doc_xml ), 152 )
679
679
680
- def test__build_doc_with_sets (self ):
680
+ def test__build_xml_doc_with_sets (self ):
681
681
doc = {"id" : "doc_1" , "title" : "Set test doc" , "tags" : {"alpha" , "beta" }}
682
682
doc_xml = force_unicode (
683
- ElementTree .tostring (self .solr ._build_doc (doc ), encoding = "utf-8" )
683
+ ElementTree .tostring (self .solr ._build_xml_doc (doc ), encoding = "utf-8" )
684
684
)
685
685
self .assertIn ('<field name="id">doc_1</field>' , doc_xml )
686
686
self .assertIn ('<field name="title">Set test doc</field>' , doc_xml )
687
687
self .assertIn ('<field name="tags">alpha</field>' , doc_xml )
688
688
self .assertIn ('<field name="tags">beta</field>' , doc_xml )
689
689
self .assertEqual (len (doc_xml ), 144 )
690
690
691
- def test__build_doc_with_sub_docs (self ):
691
+ def test__build_xml_doc_with_sub_docs (self ):
692
692
sub_docs = [
693
693
{
694
694
"id" : "sub_doc_1" ,
@@ -710,7 +710,7 @@ def test__build_doc_with_sub_docs(self):
710
710
"popularity" : 10 ,
711
711
"_doc" : sub_docs ,
712
712
}
713
- doc_xml = self .solr ._build_doc (doc )
713
+ doc_xml = self .solr ._build_xml_doc (doc )
714
714
self .assertEqual (doc_xml .find ("*[@name='id']" ).text , doc ["id" ])
715
715
716
716
children_docs = doc_xml .findall ("doc" )
@@ -719,6 +719,19 @@ def test__build_doc_with_sub_docs(self):
719
719
self .assertEqual (children_docs [0 ].find ("*[@name='id']" ).text , sub_docs [0 ]["id" ])
720
720
self .assertEqual (children_docs [1 ].find ("*[@name='id']" ).text , sub_docs [1 ]["id" ])
721
721
722
+ def test_build_json_doc_matches_xml (self ):
723
+ doc = {
724
+ "id" : "doc_1" ,
725
+ "title" : "" ,
726
+ "price" : 12.59 ,
727
+ "popularity" : 10
728
+ }
729
+
730
+ doc_json = self .solr ._build_json_doc (doc )
731
+ doc_xml = self .solr ._build_xml_doc (doc )
732
+ self .assertNotIn ("title" , doc_json )
733
+ self .assertIsNone (doc_xml .find ("*[name='title']" ))
734
+
722
735
def test_add (self ):
723
736
self .assertEqual (len (self .solr .search ("doc" )), 3 )
724
737
self .assertEqual (len (self .solr .search ("example" )), 2 )
0 commit comments