Skip to content

Commit

Permalink
Made tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirk Makowski committed Aug 26, 2012
1 parent 81c2749 commit 1dd64f5
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 7 deletions.
5 changes: 5 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,5 @@
include README.rst tox.ini
global-include *.py
recursive-include tests *
recursive-exclude tests *.pyc

11 changes: 5 additions & 6 deletions setup.py
Expand Up @@ -5,7 +5,8 @@


NAME = 'feedgenerator-py3k'
PACKAGES = ['feedgenerator']
PACKAGES = ['feedgenerator', 'feedgenerator.django',
'feedgenerator.django.utils']
DESCRIPTION = 'Standalone version of django.utils.feedgenerator, compatible with Py3k'
LONG_DESCRIPTION = open('README.rst').read(),

Expand All @@ -27,7 +28,7 @@
AUTHOR = 'Django Software Foundation'
AUTHOR_EMAIL = 'foundation@djangoproject.com'
MAINTAINER = 'Dirk Makowski'
MAINTAINER_EMAIL= 'dm@parenchym.com'
MAINTAINER_EMAIL = 'dm@parenchym.com'
KEYWORDS = "feed atom rss".split(' ')
VERSION = '1.5.dev'

Expand All @@ -39,7 +40,8 @@
name=NAME,
version=VERSION,
packages=PACKAGES,

test_suite=TEST_SUITE,
install_requires=REQUIRES,
# metadata for upload to PyPI
author=AUTHOR,
author_email=AUTHOR_EMAIL,
Expand All @@ -50,7 +52,4 @@
keywords=KEYWORDS,
url=URL,
classifiers=CLASSIFIERS,
test_suite=TEST_SUITE,
install_requires=REQUIRES,

)
2 changes: 1 addition & 1 deletion test.rss
Expand Up @@ -3,4 +3,4 @@
Umlauts: äöüßÄÖÜ
Chinese: 老师是四十四,是不是?
Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin.
</description><language>en</language><lastBuildDate>Sat, 25 Aug 2012 23:03:26 -0000</lastBuildDate><item><title>Hello</title><link>http://www.holovaty.com/test/</link><description>Testing.</description></item></channel></rss>
</description><language>en</language><lastBuildDate>Sun, 26 Aug 2012 07:44:28 -0000</lastBuildDate><item><title>Hello</title><link>http://www.holovaty.com/test/</link><description>Testing.</description></item></channel></rss>
Empty file added tests/__init__.py
Empty file.
87 changes: 87 additions & 0 deletions tests/test_feedgenerator.py
@@ -0,0 +1,87 @@
# -*- encoding: utf-8 -*-

from __future__ import unicode_literals

import re
try:
import unittest2 as unittest
except ImportError:
import unittest

import six

import feedgenerator

FIXT_FEED = dict(
title="Poynter E-Media Tidbits",
link="http://www.poynter.org/column.asp?id=31",
description="""A group Weblog by the sharpest minds in online media/journalism/publishing.
Umlauts: äöüßÄÖÜ
Chinese: 老师是四十四,是不是?
Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin.
""",
language="en"
)
FIXT_ITEM = dict(
title="Hello",
link="http://www.holovaty.com/test/",
description="Testing."
)

FIXT_FEED_BYTES = dict(
title=six.b("Poynter E-Media Tidbits"),
link=six.b("http://www.poynter.org/column.asp?id=31"),
description=six.b("""A group Weblog by the sharpest minds in online media/journalism/publishing.
Umlauts: äöüßÄÖÜ
Chinese: 老师是四十四,是不是?
Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin.
"""),
language=six.b("en")
)
FIXT_ITEM_BYTES = dict(
title=six.b("Hello"),
link=six.b("http://www.holovaty.com/test/"),
description=six.b("Testing.")
)

EXPECTED_RESULT = """<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Poynter E-Media Tidbits</title><link>http://www.poynter.org/column.asp?id=31</link><description>A group Weblog by the sharpest minds in online media/journalism/publishing.
Umlauts: äöüßÄÖÜ
Chinese: 老师是四十四,是不是?
Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin.
</description><language>en</language><lastBuildDate>Sun, 26 Aug 2012 07:44:28 -0000</lastBuildDate><item><title>Hello</title><link>http://www.holovaty.com/test/</link><description>Testing.</description></item></channel></rss>"""

EXPECTED_RESULT_BYTES = six.b("""<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Poynter E-Media Tidbits</title><link>http://www.poynter.org/column.asp?id=31</link><description>A group Weblog by the sharpest minds in online media/journalism/publishing.
Umlauts: äöüßÄÖÜ
Chinese: 老师是四十四,是不是?
Finnish: Mustan kissan paksut posket. (ah, no special chars) Kärpänen sanoi kärpäselle: tuu kattoon kattoon ku kaveri tapettiin tapettiin.
</description><language>en</language><lastBuildDate>Sun, 26 Aug 2012 07:44:28 -0000</lastBuildDate><item><title>Hello</title><link>http://www.holovaty.com/test/</link><description>Testing.</description></item></channel></rss>""")

RE_BUILD_DATE = re.compile('<lastBuildDate>.*?</lastBuildDate>')

ENCODING = 'utf-8'


def build_expected_result(feed, expected_result, encoding):
d = feedgenerator.rfc2822_date(feed.latest_post_date())
return RE_BUILD_DATE.sub('<lastBuildDate>'+d+'</lastBuildDate>',
expected_result).encode(encoding)


class TestFeedGenerator(unittest.TestCase):

def test_001_default_encoding(self):
# Default encoding is unicode since we have imported unicode_literals!
feed = feedgenerator.Rss201rev2Feed(**FIXT_FEED)
feed.add_item(**FIXT_ITEM)
result = feed.writeString(ENCODING)
expected_result = build_expected_result(feed, EXPECTED_RESULT, ENCODING)
self.assertEqual(result, expected_result)

def test_002_bytes(self):
feed = feedgenerator.Rss201rev2Feed(**FIXT_FEED_BYTES)
feed.add_item(**FIXT_ITEM_BYTES)
result = feed.writeString(ENCODING)
expected_result = build_expected_result(feed, EXPECTED_RESULT_BYTES, ENCODING)
self.assertEqual(result, expected_result)
File renamed without changes.

0 comments on commit 1dd64f5

Please sign in to comment.