File: feedparser_test.py

package info (click to toggle)
jsonpickle 3.0.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,184 kB
  • sloc: python: 6,088; javascript: 654; makefile: 90; sh: 17
file content (100 lines) | stat: -rw-r--r-- 3,153 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*- coding: utf-8 -*-
#
# Copyright (C) 2008 John Paulett (john -at- paulett.org)
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.

import unittest

from helper import SkippableTest

import jsonpickle

RSS_DOC = """<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
      xml:base="http://example.org/" xml:lang="en">
  <title type="text">Sample Feed</title>
  <subtitle type="html">For documentation &lt;em&gt;only&lt;/em&gt;</subtitle>
  <link rel="alternate" type="html" href="/"/>
  <link rel="self" type="application/atom+xml"
        href="http://www.example.org/atom10.xml"/>
  <rights type="html">&lt;p>Copyright 2005, Mark Pilgrim&lt;/p>&lt;</rights>

  <generator uri="http://example.org/generator/" version="4.0">
    Sample Toolkit
  </generator>
  <id>tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml</id>
  <updated>2005-11-09T11:56:34Z</updated>
  <entry>
    <title>First entry title</title>
    <link rel="alternate" href="/entry/3"/>
    <link rel="related" type="text/html" href="http://search.example.com/"/>

    <link rel="via" type="text/html"
          href="http://toby.example.com/examples/atom10"/>
    <link rel="enclosure" type="video/mpeg4"
          href="http://www.example.com/movie.mp4" length="42301"/>
    <id>tag:feedparser.org,2005-11-09:/docs/examples/atom10.xml:3</id>
    <published>2005-11-09T00:23:47Z</published>
    <updated>2005-11-09T11:56:34Z</updated>
    <author>
      <name>Mark Pilgrim</name>

      <uri>http://diveintomark.org/</uri>
      <email>mark@example.org</email>
    </author>
    <contributor>
      <name>Joe</name>
      <uri>http://example.org/joe/</uri>
      <email>joe@example.org</email>

    </contributor>
    <contributor>
      <name>Sam</name>
      <uri>http://example.org/sam/</uri>
      <email>sam@example.org</email>
    </contributor>
    <summary type="text">Watch out for nasty tricks</summary>

    <content type="xhtml" xml:base="http://example.org/entry/3"
             xml:lang="en-US">
      <div xmlns="http://www.w3.org/1999/xhtml">
        Watch out for <span style="
            background: url(javascript:window.location='http://example.org/')
        ">
            nasty tricks</span>
        </div>
    </content>
  </entry>
</feed>"""


class FeedParserTestCase(SkippableTest):
    def setUp(self):
        try:
            import feedparser

            self.should_skip = False
            self.doc = feedparser.parse(RSS_DOC)
        except ImportError:
            self.should_skip = True
            return

    def test(self):
        if self.should_skip:
            return self.skip('feedparser module not available, please install')
        pickled = jsonpickle.encode(self.doc)
        unpickled = jsonpickle.decode(pickled)
        self.assertEqual(self.doc['feed']['title'], unpickled['feed']['title'])


def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(FeedParserTestCase, 'test'))
    return suite


if __name__ == '__main__':
    unittest.main(defaultTest='suite')