def test_queryset_render_testmodel_no_kwargs(self): """Tests that querysets can be rendered without kwargs. Takes our own test model and xmlify it with no kwargs causing it's own __xml__ method to be used to render the XML. """ tmpl = BLANK % """ <xsl:copy-of select="xdjango:foo%d()"/> """ % self.time transformer = xslt.Transformer(tmpl) from models import XSLTTestModel testobject = XSLTTestModel( name = "name%s" % self.time, about = "about%s" % self.time, count = 10 ) testobject.save() # Do the query and pull back the xml xml = XSLTTestModel.objects.filter( name="name%s" % self.time ) xmlified = xsltmanagers.xmlify(xml, use_values=False) c = Context({ 'foo%d' % self.time: xmlified }) res = transformer(context=c) assertXpath( res, '//xslttestmodels/xslttestmodel/name[text()="name%s"]' % self.time, )
def test_queryset_render_persists(self): """Tests that queryset __xml__ method attachment works. The __xml__ method, attached by using the xml() method, should 'stick' to a queryset through further child-querysets. """ tmpl = BLANK % """ <xsl:copy-of select="xdjango:foo%d()"/> """ % self.time transformer = xslt.Transformer(tmpl) from models import XSLTTestModel for i in range(1,20): testobject = XSLTTestModel( name = "name%s" % (int(self.time) * i), about = "about%s" % (int(self.time) * i), count = i ) testobject.save() # Do the query - this qs should have an 'xml' method base_qs = XSLTTestModel.objects.filter( name="name%s" % self.time ) # Make a first sub-qs to check the xml method is being cloned qs = base_qs.filter(count__lte=12) # Check it has the xml method self.assert_("xml" in qs.__dict__) # Call the 'xml' method to store the xml to be generated and return a new qs qs_from_xml = qs.xml(name="name", about_text="about", count="count") # Check it has the __xml__ method self.assert_("__xml__" in qs_from_xml.__dict__) # Make another qs from the 'xml' decorated one selected = qs_from_xml.filter(count__lte=3) # Check the sub-queryset has the __xml__ method self.assert_("__xml__" in selected.__dict__) xml_result = _qs_eval_helper(selected) self.assert_(re.search(""" name="name%s"[ /]""" % self.time, xml_result)) c = Context({ 'foo%d' % self.time: selected }) res = transformer(context=c) assertXpath( res, '//xslttestmodels/xslttestmodel[@name="name%s"]' % self.time, ) assertXpath( res, '//xslttestmodels/xslttestmodel[@about_text="about%s"]' % self.time, )
def test_queryset_render_testmodel(self): """Tests that querysets can be rendered. Takes our own test model and uses the model's built in manager which monkey patches all querysets coming out of it. """ tmpl = BLANK % """ <xsl:copy-of select="xdjango:foo%d()"/> """ % self.time transformer = xslt.Transformer(tmpl) from models import XSLTTestModel testobject = XSLTTestModel( name = "name%s" % self.time, about = "about%s" % self.time, count = 10 ) testobject.save() # Do the query and pull back the xml xml = XSLTTestModel.objects.filter( name="name%s" % self.time ).xml( name="name", about_text="about", count="count" ) c = Context({ 'foo%d' % self.time: xml }) res = transformer(context=c) assertXpath( res, '//xslttestmodels/xslttestmodel[@name="name%s"]' % self.time, ) assertXpath( res, '//xslttestmodels/xslttestmodel[@about_text="about%s"]' % self.time, )