コード例 #1
0
ファイル: tests.py プロジェクト: nicferrier/django-xslt
    def test_queryset_render_user(self):
        """Tests that querysets can be rendered.

        Takes a django User object and monkey_qs's it then test the
        xml is returned correctly.
        """
        tmpl = BLANK % """
        <xsl:copy-of select="xdjango:foo%d()"/>
        """ % self.time
        transformer = xslt.Transformer(tmpl)
        
        from django.contrib.auth.models import User
        user = User(
            username="******" % self.time,
            password="******" % self.time,
            first_name="first%s" % self.time
            )
        user.save()
        qs = xsltmanagers.monkey_qs(
            User.objects.filter(username="******" % self.time)
            )

        context_key = 'foo%d' % self.time
        xml = qs.xml(first_name="first_name", username="******")
        c = Context({ context_key: xml })
        res = transformer(context=c)
        assertXpath(
            res, 
            '//users/user[@first_name="first%s"]' % self.time,
            )
コード例 #2
0
ファイル: tests.py プロジェクト: nicferrier/django-xslt
    def test_queryset_render_non_values(self):
        """Tests that querysets can be rendered without using 'values'.

        Takes a django User object and monkey_qs's it then test the
        xml is returned correctly when we use a dynamic method and
        therefore specify no to 'use_values'
        """
        tmpl = BLANK % """
        <xsl:copy-of select="xdjango:foo%d()"/>
        """ % self.time
        transformer = xslt.Transformer(tmpl)
        
        from django.contrib.auth.models import User
        user = User(
            username="******" % self.time,
            password="******" % self.time,
            first_name="first%s" % self.time,
            last_name="last%s" % self.time
            )
        user.save()

        # Use objects and NOT values
        qs = xsltmanagers.monkey_qs(
            User.objects.filter(username="******" % self.time),
            use_values=False
            )

        context_key = 'foo%d' % self.time
        xml = qs.xml(full_name="get_full_name", username="******")
        c = Context({ context_key: xml })
        res = transformer(context=c)
        assertXpath(
            res, 
            '//users/user[@full_name="first%s last%s"]' % (self.time, self.time)
            )