Ticket #6533: syndication-escapingtest.diff
File syndication-escapingtest.diff, 2.6 KB (added by , 16 years ago) |
---|
-
tests/regressiontests/syndication/models.py
1 from django.db import models 2 import datetime 3 4 class 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
2 2 3 3 from django.test import TestCase 4 4 from django.test.client import Client 5 from models import Article 5 6 6 7 class SyndicationFeedTest(TestCase): 7 8 def test_complex_base_url(self): … … 12 13 c = Client() 13 14 response = c.get('/syndication/feeds/complex/') 14 15 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
1 1 from django.conf.urls.defaults import patterns 2 from django.contrib.syndication import feeds 2 3 from django.core.exceptions import ObjectDoesNotExist 3 from django.contrib.syndication import feeds4 from models import Article 4 5 6 class ArticleFeed(feeds.Feed): 7 title = "Articles" 8 link = "/articles/" 5 9 10 def items(self): 11 return Article.objects.order_by('id') 12 6 13 class ComplexFeed(feeds.Feed): 7 14 def get_object(self, bits): 8 15 if len(bits) != 1: 9 16 raise ObjectDoesNotExist 10 17 return None 11 18 12 13 19 urlpatterns = patterns('', 14 20 (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', { 15 21 'feed_dict': dict( 16 22 complex = ComplexFeed, 23 articles = ArticleFeed, 17 24 )}), 18 25 )