Ticket #6533: syndication-escapingtest.diff

File syndication-escapingtest.diff, 2.6 KB (added by Julian Bez, 16 years ago)
  • tests/regressiontests/syndication/models.py

     
     1from django.db import models
     2import datetime
     3
     4class Article(models.Model):
     5    title = models.CharField(max_length=250)
     6    text = models.TextField()
     7   
     8    def __unicode__(self):
     9        return self.title
     10   
     11    def get_absolute_url(self):
     12        return "/%s/" % self.id
  • tests/regressiontests/syndication/tests.py

     
    22
    33from django.test import TestCase
    44from django.test.client import Client
     5from models import Article
    56
    67class SyndicationFeedTest(TestCase):
    78    def test_complex_base_url(self):
     
    1213        c = Client()
    1314        response = c.get('/syndication/feeds/complex/')
    1415        self.assertEquals(response.status_code, 404)
     16       
     17    def test_escaping(self):
     18        """
     19        Tests that titles are escaped correctly
     20        """
     21        a1 = Article.objects.create(title='Article 1')
     22        a2 = Article.objects.create(title='Cool: 1 > 2!')
     23        a3 = Article.objects.create(title='M & M')
     24        c = Client()
     25        response = c.get('/syndication/feeds/articles/')
     26        self.assertContains(response, "Cool: 1 > 2")
     27        self.assertContains(response, "M & M")
  • tests/regressiontests/syndication/urls.py

     
    11from django.conf.urls.defaults import patterns
     2from django.contrib.syndication import feeds
    23from django.core.exceptions import ObjectDoesNotExist
    3 from django.contrib.syndication import feeds
     4from models import Article
    45
     6class ArticleFeed(feeds.Feed):   
     7    title = "Articles"
     8    link = "/articles/"
    59
     10    def items(self):
     11        return Article.objects.order_by('id')
     12
    613class ComplexFeed(feeds.Feed):
    714    def get_object(self, bits):
    815        if len(bits) != 1:
    916            raise ObjectDoesNotExist
    1017        return None
    1118
    12 
    1319urlpatterns = patterns('',
    1420    (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {
    1521        'feed_dict': dict(
    1622            complex = ComplexFeed,
     23            articles = ArticleFeed,
    1724        )}),
    1825)
Back to Top