Code

Ticket #6533: syndication-escapingtest.diff

File syndication-escapingtest.diff, 2.6 KB (added by julianb, 6 years ago)
Line 
1Index: tests/regressiontests/syndication/models.py
2===================================================================
3--- tests/regressiontests/syndication/models.py (revision 8161)
4+++ tests/regressiontests/syndication/models.py (working copy)
5@@ -0,0 +1,12 @@
6+from django.db import models
7+import datetime
8+
9+class Article(models.Model):
10+    title = models.CharField(max_length=250)
11+    text = models.TextField()
12+   
13+    def __unicode__(self):
14+        return self.title
15+   
16+    def get_absolute_url(self):
17+        return "/%s/" % self.id
18Index: tests/regressiontests/syndication/tests.py
19===================================================================
20--- tests/regressiontests/syndication/tests.py  (revision 8161)
21+++ tests/regressiontests/syndication/tests.py  (working copy)
22@@ -2,6 +2,7 @@
23 
24 from django.test import TestCase
25 from django.test.client import Client
26+from models import Article
27 
28 class SyndicationFeedTest(TestCase):
29     def test_complex_base_url(self):
30@@ -12,3 +13,15 @@
31         c = Client()
32         response = c.get('/syndication/feeds/complex/')
33         self.assertEquals(response.status_code, 404)
34+       
35+    def test_escaping(self):
36+        """
37+        Tests that titles are escaped correctly
38+        """
39+        a1 = Article.objects.create(title='Article 1')
40+        a2 = Article.objects.create(title='Cool: 1 > 2!')
41+        a3 = Article.objects.create(title='M & M')
42+        c = Client()
43+        response = c.get('/syndication/feeds/articles/')
44+        self.assertContains(response, "Cool: 1 > 2")
45+        self.assertContains(response, "M & M")
46Index: tests/regressiontests/syndication/urls.py
47===================================================================
48--- tests/regressiontests/syndication/urls.py   (revision 8161)
49+++ tests/regressiontests/syndication/urls.py   (working copy)
50@@ -1,18 +1,25 @@
51 from django.conf.urls.defaults import patterns
52+from django.contrib.syndication import feeds
53 from django.core.exceptions import ObjectDoesNotExist
54-from django.contrib.syndication import feeds
55+from models import Article
56 
57+class ArticleFeed(feeds.Feed):   
58+    title = "Articles"
59+    link = "/articles/"
60 
61+    def items(self):
62+        return Article.objects.order_by('id')
63+
64 class ComplexFeed(feeds.Feed):
65     def get_object(self, bits):
66         if len(bits) != 1:
67             raise ObjectDoesNotExist
68         return None
69 
70-
71 urlpatterns = patterns('',
72     (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {
73         'feed_dict': dict(
74             complex = ComplexFeed,
75+            articles = ArticleFeed,
76         )}),
77 )