Example #1
0
def fx_test_feeds():
    authors = [Person(name='vio')]
    feed = Feed(id='http://feedone.com/',
                authors=authors,
                title='Feed One',
                updated_at=datetime.datetime(2013,
                                             10,
                                             29,
                                             20,
                                             55,
                                             30,
                                             tzinfo=utc))
    updated_feed = Feed(id='http://feedone.com/',
                        authors=authors,
                        title=Text(value='Feed One'),
                        updated_at=datetime.datetime(2013,
                                                     10,
                                                     30,
                                                     20,
                                                     55,
                                                     30,
                                                     tzinfo=utc))
    entry = Entry(id='http://feedone.com/1',
                  authors=authors,
                  title=Text(value='Test Entry'),
                  updated_at=datetime.datetime(2013,
                                               10,
                                               30,
                                               20,
                                               55,
                                               30,
                                               tzinfo=utc))
    updated_feed.entries.append(entry)
    return feed, updated_feed
Example #2
0
def test_text_str():
    assert text_type(Text(type='text', value='Hello world')) == 'Hello world'
    assert (text_type(Text(type='text', value='<p>Hello <em>world</em></p>'))
            == '<p>Hello <em>world</em></p>')
    assert text_type(Text(type='html', value='Hello world')) == 'Hello world'
    assert (text_type(Text(type='html', value='<p>Hello <em>world</em></p>'))
            == 'Hello world')
Example #3
0
def fx_test_entries():
    entry1 = Entry(
        id='http://feed.com/entry1', title=Text(value='new1'),
        updated_at=datetime.datetime(2013, 1, 1, 0, 0, 0, tzinfo=utc))
    entry2 = Entry(
        id='http://feed.com/entry2', title=Text(value='new2'),
        updated_at=datetime.datetime(2013, 1, 1, 0, 0, 1, tzinfo=utc))
    return entry1, entry2
Example #4
0
def test_subscription_set_subscribe(subs):
    feed = Feed(id='urn:earthreader:test:test_subscription_set_subscribe',
                title=Text(value='Feed title'))
    feed.links.extend([
        Link(uri='http://example.com/index.xml',
             relation='self',
             mimetype='application/atom+xml'),
        Link(uri='http://example.com/',
             relation='alternate',
             mimetype='text/html')
    ])
    rv = subs.subscribe(feed, icon_uri='http://example.com/favicon.ico')
    sub = next(iter(subs))
    assert rv is sub
    assert sub.feed_id == '0691e2f0c3ea1d7fa9da48e14a46ac8077815ad3'
    assert sub.icon_uri == 'http://example.com/favicon.ico'
    assert sub.label == 'Feed title'
    assert sub.feed_uri == 'http://example.com/index.xml'
    assert sub.alternate_uri == 'http://example.com/'
    subs.remove(sub)
    assert not subs
    feed.links.append(
        Link(uri='http://example.com/favicon.ico', relation='shortcut icon'))
    rv = subs.subscribe(feed)
    assert rv is next(iter(subs))
    assert rv == sub
Example #5
0
def test_source():
    entry = read(Entry, [b'''
        <entry xmlns="http://www.w3.org/2005/Atom">
            <source>
                <title>Source of all knowledge</title>
                <id>urn:uuid:28213c50-f84c-11d9-8cd6-0800200c9a66</id>
                <updated>2003-12-13T17:46:27Z</updated>
                <category term="technology"/>
                <category term="business"/>
            </source>
            <title>Atom-Powered Robots Run Amok</title>
            <link href="http://example.org/2003/12/13/atom03"/>
            <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
            <updated>2003-12-13T18:30:02Z</updated>
            <summary>Some text.</summary>
        </entry>
    '''])
    source = entry.source
    assert isinstance(source, Source)
    assert source.title == Text(value='Source of all knowledge')
    assert source.id == 'urn:uuid:28213c50-f84c-11d9-8cd6-0800200c9a66'
    assert source.updated_at == datetime.datetime(2003, 12, 13, 17, 46, 27,
                                                  tzinfo=utc)
    categories = source.categories
    assert isinstance(categories[0], Category)
    assert categories[0].term == 'technology'
    assert isinstance(categories[1], Category)
    assert categories[1].term == 'business'
    assert len(categories) == 2
Example #6
0
def fx_filtering_entries(fx_test_stage):
    authors = [Person(name='vio')]
    now = datetime.datetime(2013, 10, 30, 20, 55, 30, tzinfo=utc)
    feed = Feed(id='http://feedone.com/feed/atom/', authors=authors,
                title=Text(value='Feed One'),
                updated_at=now)
    for i in range(10):
        feed.entries.append(
            Entry(id='http://feedone.com/feed/atom/' + str(i) + '/',
                  authors=authors,
                  title=Text(value=str(i + 1)),
                  updated_at=now + datetime.timedelta(days=1) * i)
        )
    for i in range(5):
        feed.entries[i].read = Mark(marked=True, updated_at=now)
    for i in range(3, 7):
        feed.entries[i].starred = Mark(marked=True, updated_at=now)
    with fx_test_stage as stage:
        stage.feeds[get_hash('http://feedone.com/feed/atom/')] = feed
        stage.subscriptions = read(SubscriptionList, opml_for_filtering)
Example #7
0
def test_feed_read(fx_feed):
    feed = fx_feed
    assert feed.title == Text(value='Example Feed')
    link = feed.links[0]
    assert isinstance(link, Link)
    assert link.relation == 'alternate'
    assert link.uri == 'http://example.org/'
    assert len(feed.links) == 1
    assert feed.updated_at == datetime.datetime(2003,
                                                12,
                                                13,
                                                18,
                                                30,
                                                2,
                                                tzinfo=utc)
    authors = feed.authors
    assert isinstance(authors[0], Person)
    assert authors[0].name == 'John Doe'
    assert isinstance(authors[1], Person)
    assert authors[1].name == 'Jane Doe'
    assert len(feed.authors) == 2
    assert feed.id == 'urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6'
    categories = feed.categories
    assert isinstance(categories[0], Category)
    assert categories[0].term == 'technology'
    assert isinstance(categories[1], Category)
    assert categories[1].term == 'business'
    assert len(categories) == 2
    assert feed.rights == Text(value='Public Domain')
    entries = feed.entries
    assert isinstance(entries[0], Entry)
    assert entries[0].title == Text(value='Atom-Powered Robots Run Amok')
    assert (list(entries[0].links) == [
        Link(uri='http://example.org/2003/12/13/atom03')
    ])
    assert entries[0].id == 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a'
    assert entries[0].updated_at == datetime.datetime(2003,
                                                      12,
                                                      13,
                                                      18,
                                                      30,
                                                      2,
                                                      tzinfo=utc)
    assert entries[0].summary == Text(value='Some text.')
    assert list(entries[0].authors) == [Person(name='Jane Doe')]
    assert isinstance(entries[1], Entry)
    assert entries[1].title == Text(value='Danger, Will Robinson!')
    assert (list(
        entries[1].links) == [Link(uri='http://example.org/2003/12/13/lost')])
    assert entries[1].id == 'urn:uuid:b12f2c10-ffc1-11d9-8cd6-0800200c9a66'
    assert entries[1].updated_at == datetime.datetime(2003,
                                                      12,
                                                      13,
                                                      18,
                                                      30,
                                                      2,
                                                      tzinfo=utc)
    assert entries[1].summary == Text(value="Don't Panic!")
    assert len(entries) == 2
Example #8
0
def test_entry_read():
    # http://www.intertwingly.net/wiki/pie/FormatTests
    entry = read(Entry, [
        b'''
        <entry xmlns="http://www.w3.org/2005/Atom">
            <title>Atom-Powered Robots Run Amok</title>
            <link href="http://example.org/2003/12/13/atom03"/>
            <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
            <updated>2003-12-13T18:30:02Z</updated>
            <summary>Some text.</summary>
            <category term="technology"/>
            <category term="business"/>
            <contributor>
                <name>John Smith</name>
            </contributor>
            <contributor>
                <name>Jane Doe</name>
            </contributor>
        </entry>
    '''
    ])
    assert entry.id == 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a'
    assert entry.title == Text(value='Atom-Powered Robots Run Amok')
    assert entry.updated_at == datetime.datetime(2003,
                                                 12,
                                                 13,
                                                 18,
                                                 30,
                                                 2,
                                                 tzinfo=utc)
    assert isinstance(entry.links[0], Link)
    assert entry.links[0].uri == 'http://example.org/2003/12/13/atom03'
    assert entry.links[0].relation == 'alternate'
    assert len(entry.links) == 1
    assert isinstance(entry.summary, Text)
    assert entry.summary.type == 'text'
    assert entry.summary.value == 'Some text.'
    assert isinstance(entry.categories[0], Category)
    assert entry.categories[0].term == 'technology'
    assert entry.categories[1].term == 'business'
    assert len(entry.categories) == 2
    assert isinstance(entry.contributors[0], Person)
    assert entry.contributors[0].name == 'John Smith'
    assert entry.contributors[1].name == 'Jane Doe'
    assert len(entry.contributors) == 2
Example #9
0
def test_add_as_subscription(subs):
    feed = Feed(id='urn:earthreader:test:test_subscription_set_subscribe',
                title=Text(value='Feed title'),
                links=[
                    Link(relation='self',
                         mimetype='application/atom+xml',
                         uri='http://example.com/atom.xml')
                ])
    result = CrawlResult('http://example.com/atom.xml',
                         feed,
                         hints={},
                         icon_url='http://example.com/favicon.ico')
    sub = result.add_as_subscription(subs)
    assert len(subs) == 1
    assert next(iter(subs)) is sub
    assert sub.feed_uri == result.url
    assert sub.label == feed.title.value
    assert sub.icon_uri == result.icon_url
Example #10
0
def test_sanitized_html():
    assert (Text(type='text',
                 value='Hello world').sanitized_html == 'Hello world')
    assert (Text(type='text',
                 value='Hello\nworld').sanitized_html == 'Hello<br>\nworld')
    assert (Text(type='text',
                 value='<p>Hello <em>world</em></p>').sanitized_html ==
            '&lt;p&gt;Hello &lt;em&gt;world&lt;/em&gt;&lt;/p&gt;')
    assert (Text(type='html',
                 value='Hello world').sanitized_html == 'Hello world')
    assert (Text(type='html',
                 value='<p>Hello <em>world</em></p>').sanitized_html ==
            '<p>Hello <em>world</em></p>')
    assert (Text(type='html',
                 value='<p>Hello</p><script>alert(1);</script>').sanitized_html
            == '<p>Hello</p>')
    assert (Text(type='html', value='<p>Hello</p><hr noshade>').sanitized_html
            == '<p>Hello</p><hr noshade>')
Example #11
0
def test_get_sanitized_html():
    text = Text(type='text', value='Hello world')
    assert text.get_sanitized_html() == text.sanitized_html == 'Hello world'
    text = Text(type='text', value='Hello\nworld')
    assert (text.get_sanitized_html() == text.sanitized_html ==
            'Hello<br>\nworld')
    text = Text(type='text', value='<p>Hello <em>world</em></p>')
    assert (text.get_sanitized_html() == text.sanitized_html ==
            '&lt;p&gt;Hello &lt;em&gt;world&lt;/em&gt;&lt;/p&gt;')
    text = Text(type='html', value='Hello world')
    assert (text.get_sanitized_html() == text.sanitized_html == 'Hello world')
    text = Text(type='html', value='<p>Hello <em>world</em></p>')
    assert (text.get_sanitized_html() == text.sanitized_html ==
            '<p>Hello <em>world</em></p>')
    text = Text(type='html', value='<p>Hello</p><script>alert(1);</script>')
    assert text.get_sanitized_html() == text.sanitized_html == '<p>Hello</p>'
    text = Text(type='html', value='<p>Hello</p><hr noshade>')
    assert (text.get_sanitized_html() == text.sanitized_html ==
            '<p>Hello</p><hr noshade>')
    text = Text(type='html', value='<a href="/abspath">abspath</a>')
    assert (text.get_sanitized_html(base_uri='http://localhost/path/') ==
            '<a href="http://localhost/abspath">abspath</a>')
Example #12
0
def test_entry_str():
    assert text_type(Entry(title=Text(value='Title desu'))) == 'Title desu'
    assert text_type(Entry()) == ''
Example #13
0
def xmls_for_next(request, fx_test_stage):
    opml = '''
    <opml version="1.0">
      <head>
        <title>test opml</title>
      </head>
      <body>
        <outline text="categoryone" title="categoryone">
            <outline type="atom" text="Feed One" title="Feed One"
            xmlUrl="http://feedone.com/" />
            <outline type="atom" text="Feed Two" title="Feed Two"
            xmlUrl="http://feedtwo.com/" />
        </outline>
        <outline type="atom" text="Feed Three" title="Feed Three"
        xmlUrl="http://feedthree.com/" />
        <outline type="atom" text="Feed Four" title="Feed Three"
        xmlUrl="http://feedthree.com/" />
      </body>
    </opml>
    '''
    authors = [Person(name='vio')]
    feed_one = Feed(id='http://feedone.com/', authors=authors,
                    title=Text(value='Feed One'),
                    updated_at=datetime.datetime(2013, 10, 30, 20, 55, 30,
                                                 tzinfo=utc))
    feed_two = Feed(id='http://feedtwo.com/', authors=authors,
                    title=Text(value='Feed Two'),
                    updated_at=datetime.datetime(2013, 10, 30, 21, 55, 30,
                                                 tzinfo=utc))
    feed_three = Feed(id='http://feedthree.com/', authors=authors,
                      title=Text(value='Feed Three'),
                      updated_at=datetime.datetime(2013, 10, 30, 21, 55, 30,
                                                   tzinfo=utc))
    feed_four = Feed(id='http://feedfour.com/', authors=authors,
                     title=Text(value='Feed Four'),
                     updated_at=datetime.datetime(2013, 10, 30, 21, 55, 30,
                                                  tzinfo=utc))
    for i in range(25):
        feed_one.entries.append(
            Entry(id='http://feedone.com/' + str(24 - i),
                  authors=authors,
                  title=Text(value='Feed One: Entry ' + str(24 - i)),
                  updated_at=datetime.datetime(2013, 10, 30, 20, 55, 30,
                                               tzinfo=utc) +
                  datetime.timedelta(days=-1)*i)
        )
        feed_two.entries.append(
            Entry(id='http://feedtwo.com/' + str(24 - i),
                  authors=authors,
                  title=Text(value='Feed Two: Entry ' + str(24 - i)),
                  updated_at=datetime.datetime(2013, 10, 30, 19, 55, 30,
                                               tzinfo=utc) +
                  datetime.timedelta(days=-1)*i)
        )
    for i in range(20):
        feed_three.entries.append(
            Entry(id='http://feedthree.com/' + str(19 - i),
                  authors=authors,
                  title=Text(value='Feed Three: Entry ' + str(19 - i)),
                  updated_at=datetime.datetime(2013, 10, 30, 20, 55, 30,
                                               tzinfo=utc) +
                  datetime.timedelta(days=-1)*i)
        )
    for i in range(50):
        feed_four.entries.append(
            Entry(id='http://feedfour.com/' + str(49 - i),
                  authors=authors,
                  title=Text(value='Feed Four: Entry ' + str(49 - i)),
                  updated_at=datetime.datetime(2013, 10, 30, 20, 55, 30,
                                               tzinfo=utc) +
                  datetime.timedelta(days=-1)*i)
        )
    for i in range(5):
        feed_two.entries[i].read = True
        feed_two.entries[i+15].read = True
    for i in range(20, 50):
        feed_four.entries[i].read = True
    subscriptions = read(SubscriptionList, opml)
    with fx_test_stage as stage:
        stage.subscriptions = subscriptions
        stage.feeds[get_hash('http://feedone.com/')] = feed_one
        stage.feeds[get_hash('http://feedtwo.com/')] = feed_two
        stage.feeds[get_hash('http://feedthree.com/')] = feed_three
        stage.feeds[get_hash('http://feedfour.com/')] = feed_four