PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/utils/feedgenerator.py

https://code.google.com/p/mango-py/
Python | 71 lines | 36 code | 10 blank | 25 comment | 0 complexity | bcc398283ce29efa854a2082cf0a92f5 MD5 | raw file
 1import datetime
 2
 3from django.utils import feedgenerator, tzinfo, unittest
 4
 5class FeedgeneratorTest(unittest.TestCase):
 6    """
 7    Tests for the low-level syndication feed framework.
 8    """
 9
10    def test_get_tag_uri(self):
11        """
12        Test get_tag_uri() correctly generates TagURIs.
13        """
14        self.assertEqual(
15            feedgenerator.get_tag_uri('http://example.org/foo/bar#headline', datetime.date(2004, 10, 25)),
16            u'tag:example.org,2004-10-25:/foo/bar/headline')
17
18    def test_get_tag_uri_with_port(self):
19        """
20        Test that get_tag_uri() correctly generates TagURIs from URLs with port
21        numbers.
22        """
23        self.assertEqual(
24            feedgenerator.get_tag_uri('http://www.example.org:8000/2008/11/14/django#headline', datetime.datetime(2008, 11, 14, 13, 37, 0)),
25            u'tag:www.example.org,2008-11-14:/2008/11/14/django/headline')
26
27    def test_rfc2822_date(self):
28        """
29        Test rfc2822_date() correctly formats datetime objects.
30        """
31        self.assertEqual(
32            feedgenerator.rfc2822_date(datetime.datetime(2008, 11, 14, 13, 37, 0)),
33            "Fri, 14 Nov 2008 13:37:00 -0000"
34        )
35
36    def test_rfc2822_date_with_timezone(self):
37        """
38        Test rfc2822_date() correctly formats datetime objects with tzinfo.
39        """
40        self.assertEqual(
41            feedgenerator.rfc2822_date(datetime.datetime(2008, 11, 14, 13, 37, 0, tzinfo=tzinfo.FixedOffset(datetime.timedelta(minutes=60)))),
42            "Fri, 14 Nov 2008 13:37:00 +0100"
43        )
44
45    def test_rfc3339_date(self):
46        """
47        Test rfc3339_date() correctly formats datetime objects.
48        """
49        self.assertEqual(
50            feedgenerator.rfc3339_date(datetime.datetime(2008, 11, 14, 13, 37, 0)),
51            "2008-11-14T13:37:00Z"
52        )
53
54    def test_rfc3339_date_with_timezone(self):
55        """
56        Test rfc3339_date() correctly formats datetime objects with tzinfo.
57        """
58        self.assertEqual(
59            feedgenerator.rfc3339_date(datetime.datetime(2008, 11, 14, 13, 37, 0, tzinfo=tzinfo.FixedOffset(datetime.timedelta(minutes=120)))),
60            "2008-11-14T13:37:00+02:00"
61        )
62
63    def test_atom1_mime_type(self):
64        """
65        Test to make sure Atom MIME type has UTF8 Charset parameter set
66        """
67        atom_feed = feedgenerator.Atom1Feed("title", "link", "description")
68        self.assertEqual(
69            atom_feed.mime_type, "application/atom+xml; charset=utf8"
70        )
71