~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to tests/regressiontests/syndication/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
from xml.dom import minidom
4
 
from django.test import TestCase
5
 
from django.test.client import Client
6
 
from models import Entry
7
 
try:
8
 
    set
9
 
except NameError:
10
 
    from sets import Set as set
11
 
 
12
 
class SyndicationFeedTest(TestCase):
13
 
    fixtures = ['feeddata.json']
14
 
 
15
 
    def assertChildNodes(self, elem, expected):
16
 
        actual = set([n.nodeName for n in elem.childNodes])
17
 
        expected = set(expected)
18
 
        self.assertEqual(actual, expected)
19
 
 
20
 
    def test_rss_feed(self):
21
 
        response = self.client.get('/syndication/feeds/rss/')
22
 
        doc = minidom.parseString(response.content)
23
 
        
24
 
        # Making sure there's only 1 `rss` element and that the correct
25
 
        # RSS version was specified.
26
 
        feed_elem = doc.getElementsByTagName('rss')
27
 
        self.assertEqual(len(feed_elem), 1)
28
 
        feed = feed_elem[0]
29
 
        self.assertEqual(feed.getAttribute('version'), '2.0')
30
 
        
31
 
        # Making sure there's only one `channel` element w/in the
32
 
        # `rss` element.
33
 
        chan_elem = feed.getElementsByTagName('channel')
34
 
        self.assertEqual(len(chan_elem), 1)
35
 
        chan = chan_elem[0]
36
 
        self.assertChildNodes(chan, ['title', 'link', 'description', 'language', 'lastBuildDate', 'item'])
37
 
    
38
 
        items = chan.getElementsByTagName('item')
39
 
        self.assertEqual(len(items), Entry.objects.count())
40
 
        for item in items:
41
 
            self.assertChildNodes(item, ['title', 'link', 'description', 'guid'])
42
 
    
43
 
    def test_atom_feed(self):
44
 
        response = self.client.get('/syndication/feeds/atom/')
45
 
        doc = minidom.parseString(response.content)
46
 
        
47
 
        feed = doc.firstChild
48
 
        self.assertEqual(feed.nodeName, 'feed')
49
 
        self.assertEqual(feed.getAttribute('xmlns'), 'http://www.w3.org/2005/Atom') 
50
 
        self.assertChildNodes(feed, ['title', 'link', 'id', 'updated', 'entry'])        
51
 
        
52
 
        entries = feed.getElementsByTagName('entry')
53
 
        self.assertEqual(len(entries), Entry.objects.count())
54
 
        for entry in entries:
55
 
            self.assertChildNodes(entry, ['title', 'link', 'id', 'summary'])
56
 
            summary = entry.getElementsByTagName('summary')[0]
57
 
            self.assertEqual(summary.getAttribute('type'), 'html')
58
 
    
59
 
    def test_custom_feed_generator(self):
60
 
        response = self.client.get('/syndication/feeds/custom/')
61
 
        doc = minidom.parseString(response.content)
62
 
        
63
 
        feed = doc.firstChild
64
 
        self.assertEqual(feed.nodeName, 'feed')
65
 
        self.assertEqual(feed.getAttribute('django'), 'rocks')
66
 
        self.assertChildNodes(feed, ['title', 'link', 'id', 'updated', 'entry', 'spam'])        
67
 
        
68
 
        entries = feed.getElementsByTagName('entry')
69
 
        self.assertEqual(len(entries), Entry.objects.count())
70
 
        for entry in entries:
71
 
            self.assertEqual(entry.getAttribute('bacon'), 'yum')
72
 
            self.assertChildNodes(entry, ['title', 'link', 'id', 'summary', 'ministry'])
73
 
            summary = entry.getElementsByTagName('summary')[0]
74
 
            self.assertEqual(summary.getAttribute('type'), 'html')
75
 
        
76
 
    def test_complex_base_url(self):
77
 
        """
78
 
        Tests that that the base url for a complex feed doesn't raise a 500
79
 
        exception.
80
 
        """
81
 
        response = self.client.get('/syndication/feeds/complex/')
82
 
        self.assertEquals(response.status_code, 404)
83
 
 
84
 
    def test_title_escaping(self):
85
 
        """
86
 
        Tests that titles are escaped correctly in RSS feeds.
87
 
        """
88
 
        response = self.client.get('/syndication/feeds/rss/')
89
 
        doc = minidom.parseString(response.content)
90
 
        for item in doc.getElementsByTagName('item'):
91
 
            link = item.getElementsByTagName('link')[0]
92
 
            if link.firstChild.wholeText == 'http://example.com/blog/4/':
93
 
                title = item.getElementsByTagName('title')[0]
94
 
                self.assertEquals(title.firstChild.wholeText, u'A & B < C > D')
 
 
b'\\ No newline at end of file'