~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/contrib/gis/tests/geoapp/test_feeds.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import absolute_import
 
1
from __future__ import unicode_literals
2
2
 
 
3
from unittest import skipUnless
3
4
from xml.dom import minidom
4
5
 
5
6
from django.conf import settings
6
7
from django.contrib.sites.models import Site
7
8
from django.contrib.gis.geos import HAS_GEOS
8
9
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
9
 
from django.test import TestCase
10
 
from django.utils.unittest import skipUnless
 
10
from django.test import TestCase, modify_settings
11
11
 
12
12
if HAS_GEOS:
13
13
    from .models import City
14
14
 
15
15
 
 
16
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.sites'})
16
17
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
17
18
class GeoFeedTest(TestCase):
18
19
 
20
21
 
21
22
    def setUp(self):
22
23
        Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
23
 
        self.old_Site_meta_installed = Site._meta.installed
24
 
        Site._meta.installed = True
25
 
 
26
 
    def tearDown(self):
27
 
        Site._meta.installed = self.old_Site_meta_installed
28
24
 
29
25
    def assertChildNodes(self, elem, expected):
30
26
        "Taken from syndication/tests.py."
31
 
        actual = set([n.nodeName for n in elem.childNodes])
 
27
        actual = set(n.nodeName for n in elem.childNodes)
32
28
        expected = set(expected)
33
29
        self.assertEqual(actual, expected)
34
30
 
49
45
        # Incrementing through the feeds.
50
46
        for feed in [feed1, feed2]:
51
47
            # Ensuring the georss namespace was added to the <rss> element.
52
 
            self.assertEqual(feed.getAttribute('xmlns:georss'),  'http://www.georss.org/georss')
 
48
            self.assertEqual(feed.getAttribute('xmlns:georss'), 'http://www.georss.org/georss')
53
49
            chan = feed.getElementsByTagName('channel')[0]
54
50
            items = chan.getElementsByTagName('item')
55
51
            self.assertEqual(len(items), City.objects.count())
69
65
 
70
66
        for feed in [feed1, feed2]:
71
67
            # Ensuring the georsss namespace was added to the <feed> element.
72
 
            self.assertEqual(feed.getAttribute('xmlns:georss'),  'http://www.georss.org/georss')
 
68
            self.assertEqual(feed.getAttribute('xmlns:georss'), 'http://www.georss.org/georss')
73
69
            entries = feed.getElementsByTagName('entry')
74
70
            self.assertEqual(len(entries), City.objects.count())
75
71
 
92
88
            self.assertChildNodes(item, ['title', 'link', 'description', 'guid', 'geo:lat', 'geo:lon'])
93
89
 
94
90
        # Boxes and Polygons aren't allowed in W3C Geo feeds.
95
 
        self.assertRaises(ValueError, self.client.get, '/feeds/w3cgeo2/') # Box in <channel>
96
 
        self.assertRaises(ValueError, self.client.get, '/feeds/w3cgeo3/') # Polygons in <entry>
 
91
        self.assertRaises(ValueError, self.client.get, '/feeds/w3cgeo2/')  # Box in <channel>
 
92
        self.assertRaises(ValueError, self.client.get, '/feeds/w3cgeo3/')  # Polygons in <entry>