Example #1
0
 def test_get_feeds_from_url_existing(self):
     # test get_feeds_from_url from existing feed, should return feed w/out
     # requesting
     feed = Feed.objects.create(site_url='http://example.com',
                                feed_url='http://example.com/feed/')
     self.assertListEqual(
         Feed.get_feeds_from_url('http://example.com/feed/'), [
             feed,
         ])
Example #2
0
    def test_get_feeds_from_url_from_HTML_page_hit_max(self):
        # test get_feeds_from_url from HTML page, number of feeds in page should hit default max
        start = Feed.objects.count()
        feed_urls = ''
        for x in range(MAX_FEEDS + 1):
            feed_urls += '<link rel="alternate" type="application/atom+xml" href="http://example.com/feed%s">' % x
        with requests_mock.Mocker() as mock:
            mock.get('http://example.com/',
                     text="""
<!DOCTYPE html>
<html>
    <head>
        %s
    </head>
    <body>
    </body>
</html>
                """ % feed_urls,
                     status_code=200,
                     headers={'content-type': 'text/html'})
            Feed.get_feeds_from_url('http://example.com/')
            self.assertEqual(Feed.objects.count() - start, MAX_FEEDS)
Example #3
0
    def test_get_feeds_from_url_from_feed(self):
        # test get_feeds_from_url from feed, should return input URL
        url = 'http://example.com/feed/'
        self.assertEqual(Feed.objects.filter(feed_url=url).count(), 0)
        with requests_mock.Mocker() as mock:
            mock.get(url,
                     text="""
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Example Feed</title>
    <link href="http://example.org/feed/" rel="self" />
    <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
    <updated>2003-12-13T18:30:02Z</updated>

    <entry>
        <title>Atom-Powered Robots Run Amok</title>
        <link href="http://example.org/2003/12/13/atom03" />
        <link rel="alternate" type="text/html"
            href="http://example.org/2003/12/13/atom03.html"/>
        <link rel="edit" href="http://example.org/2003/12/13/atom03/edit"/>
        <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
        <updated>2003-12-13T18:30:02Z</updated>
        <summary>Some text.</summary>
        <content type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>This is the entry content.</p>
            </div>
        </content>
        <author>
            <name>John Doe</name>
            <email>[email protected]</email>
        </author>
    </entry>
</feed>
                """,
                     status_code=200,
                     headers={'content-type': 'application/atom+xml;weird'})
            self.assertListEqual(
                Feed.get_feeds_from_url('http://example.com/feed/'), [
                    Feed.objects.get(feed_url=url),
                ])
Example #4
0
    def test_get_feeds_from_url_from_HTML_page(self):
        # test get_feeds_from_url from HTML page, should return rel link for feed
        url = 'http://example.com/feed/'
        self.assertEqual(Feed.objects.filter(feed_url=url).count(), 0)
        with requests_mock.Mocker() as mock:
            mock.get('http://example.com/',
                     text="""
<!DOCTYPE html>
<html>
    <head>
        <link rel="alternate" type="application/atom+xml" href="%s">
    </head>
    <body>
    </body>
</html>
                """ % url,
                     status_code=200,
                     headers={'content-type': 'text/html'})
            self.assertListEqual(
                Feed.get_feeds_from_url('http://example.com/'),
                [
                    Feed.objects.get(feed_url=url),
                ],
            )
Example #5
0
 def test_get_feeds_from_url_HTTP_error(self):
     # testing get_feeds_from_url with HTTP error, should return None
     with requests_mock.Mocker() as mock:
         mock.get('http://example.com/feed/', text='', status_code=400)
         self.assertEqual(
             [], Feed.get_feeds_from_url('http://example.com/feed/'))