| 1 |
# Copyright (C) 2008 John Paulett (john -at- paulett.org) |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is licensed as described in the file COPYING, which |
| 5 |
# you should have received as part of this distribution. |
| 6 |
from helper import SkippableTest |
| 7 |
|
| 8 |
import jsonpickle |
| 9 |
|
| 10 |
RSS_DOC = """<?xml version="1.0" encoding="utf-8"?> |
| 11 |
<feed xmlns="http://www.w3.org/2005/Atom" |
| 12 |
xml:base="http://example.org/" xml:lang="en"> |
| 13 |
<title type="text">Sample Feed</title> |
| 14 |
<subtitle type="html">For documentation <em>only</em></subtitle> |
| 15 |
<link rel="alternate" type="html" href="/"/> |
| 16 |
<link rel="self" type="application/atom+xml" |
| 17 |
href="http://www.example.org/atom10.xml"/> |
| 18 |
<rights type="html"><p>Copyright 2005, Mark Pilgrim</p><</rights> |
| 19 |
|
| 20 |
<generator uri="http://example.org/generator/" version="4.0"> |
| 21 |
Sample Toolkit |
| 22 |
</generator> |
| 23 |
<id>tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml</id> |
| 24 |
<updated>2005-11-09T11:56:34Z</updated> |
| 25 |
<entry> |
| 26 |
<title>First entry title</title> |
| 27 |
<link rel="alternate" href="/entry/3"/> |
| 28 |
<link rel="related" type="text/html" href="http://search.example.com/"/> |
| 29 |
|
| 30 |
<link rel="via" type="text/html" |
| 31 |
href="http://toby.example.com/examples/atom10"/> |
| 32 |
<link rel="enclosure" type="video/mpeg4" |
| 33 |
href="http://www.example.com/movie.mp4" length="42301"/> |
| 34 |
<id>tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml:3</id> |
| 35 |
<published>2005-11-09T00:23:47Z</published> |
| 36 |
<updated>2005-11-09T11:56:34Z</updated> |
| 37 |
<author> |
| 38 |
<name>Mark Pilgrim</name> |
| 39 |
|
| 40 |
<uri>http://diveintomark.org/</uri> |
| 41 |
<email>[email protected]</email> |
| 42 |
</author> |
| 43 |
<contributor> |
| 44 |
<name>Joe</name> |
| 45 |
<uri>http://example.org/joe/</uri> |
| 46 |
<email>[email protected]</email> |
| 47 |
|
| 48 |
</contributor> |
| 49 |
<contributor> |
| 50 |
<name>Sam</name> |
| 51 |
<uri>http://example.org/sam/</uri> |
| 52 |
<email>[email protected]</email> |
| 53 |
</contributor> |
| 54 |
<summary type="text">Watch out for nasty tricks</summary> |
| 55 |
|
| 56 |
<content type="xhtml" xml:base="http://example.org/entry/3" |
| 57 |
xml:lang="en-US"> |
| 58 |
<div xmlns="http://www.w3.org/1999/xhtml"> |
| 59 |
Watch out for <span style=" |
| 60 |
background: url(javascript:window.location='http://example.org/') |
| 61 |
"> |
| 62 |
nasty tricks</span> |
| 63 |
</div> |
| 64 |
</content> |
| 65 |
</entry> |
| 66 |
</feed>""" |
| 67 |
|
| 68 |
|
| 69 |
class FeedParserTestCase(SkippableTest): |
| 70 |
def setUp(self): |
| 71 |
try: |
| 72 |
import feedparser |
| 73 |
|
| 74 |
self.should_skip = False |
| 75 |
self.doc = feedparser.parse(RSS_DOC) |
| 76 |
except ImportError: |
| 77 |
self.should_skip = True |
| 78 |
return |
| 79 |
|
| 80 |
def test(self): |
| 81 |
if self.should_skip: |
| 82 |
return self.skip('feedparser module not available, please install') |
| 83 |
pickled = jsonpickle.encode(self.doc) |
| 84 |
unpickled = jsonpickle.decode(pickled) |
| 85 |
assert self.doc['feed']['title'] == unpickled['feed']['title'] |