def test_rfc_minimal():
    expected_entry = AtomEntry(
        title=AtomTextConstruct(text_type=AtomTextType.text,
                                lang=None,
                                value='Atom-Powered Robots Run Amok'),
        id_='urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a',
        updated=datetime.datetime(2003, 12, 13, 18, 30, 2, tzinfo=tzutc()),
        authors=[AtomPerson(name='John Doe', uri=None, email=None)],
        contributors=[],
        links=[
            AtomLink(href='http://example.org/2003/12/13/atom03',
                     rel=None,
                     type_=None,
                     hreflang=None,
                     title=None,
                     length=None)
        ],
        categories=[],
        published=None,
        rights=None,
        summary=AtomTextConstruct(text_type=AtomTextType.text,
                                  lang=None,
                                  value='Some text.'),
        content=None,
        source=None)
    expected = AtomFeed(
        title=AtomTextConstruct(text_type=AtomTextType.text,
                                lang=None,
                                value='Example Feed'),
        id_='urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6',
        updated=datetime.datetime(2003, 12, 13, 18, 30, 2, tzinfo=tzutc()),
        authors=[AtomPerson(name='John Doe', uri=None, email=None)],
        contributors=[],
        links=[
            AtomLink(href='http://example.org/',
                     rel=None,
                     type_=None,
                     hreflang=None,
                     title=None,
                     length=None)
        ],
        categories=[],
        generator=None,
        subtitle=None,
        rights=None,
        icon=None,
        logo=None,
        entries=[expected_entry])
    assert parse_atom_file('tests/atom/rfc-minimal.xml') == expected
Exemplo n.º 2
0
def test_broken_empty_fields():
    # As a general rule, XML tags should not be empty. In practice optional
    # fields are sometimes present in the feed but with an empty tag
    parsed = parse_atom_file('tests/atom/broken-empty-summary.xml')
    assert parsed.entries[0].summary is None

    parsed = parse_atom_file('tests/atom/broken-empty-title.xml')
    assert parsed.title is None

    parsed = parse_atom_file('tests/atom/broken-empty-updated.xml')
    assert parsed.updated is None

    parsed = parse_atom_file('tests/atom/broken-empty-author.xml')
    assert parsed.authors == []
    assert parsed.entries[0].authors == []

    parsed = parse_atom_file('tests/atom/broken-missing-author-name.xml')
    assert parsed.authors == []
    assert parsed.entries[0].authors == []

    # Require fields (id...) that have empty tags should throw an error
    with pytest.raises(FeedParseError):
        parse_atom_file('tests/atom/broken-empty-id.xml')
Exemplo n.º 3
0
def test_rfc_unicode():

    expected_entry_1 = AtomEntry(
        title=AtomTextConstruct(text_type=AtomTextType.text,
                                lang=None,
                                value='Article n°1'),
        id_='http://richard.plop/2017/6/5/article-1',
        updated=datetime.datetime(2017, 6, 5, 0, 0, tzinfo=tzutc()),
        authors=[AtomPerson(name='Rïchàrd Plop', uri=None, email=None)],
        contributors=[],
        links=[
            AtomLink(href='http://richard.plop/2017/6/5/article-1',
                     rel=None,
                     type_=None,
                     hreflang=None,
                     title=None,
                     length=None)
        ],
        categories=[],
        published=None,
        rights=None,
        summary=None,
        content=AtomTextConstruct(text_type=AtomTextType.html,
                                  lang=None,
                                  value='<p></p>'),
        source=None)
    expected_entry_2 = AtomEntry(
        title=AtomTextConstruct(text_type=AtomTextType.text,
                                lang=None,
                                value='Unicode snowman'),
        id_='http://richard.plop/2017/6/5/article-2',
        updated=datetime.datetime(2016, 12, 29, 0, 0, tzinfo=tzutc()),
        authors=[AtomPerson(name='Rïchàrd Plop', uri=None, email=None)],
        contributors=[],
        links=[
            AtomLink(href='http://richard.plop/2017/6/5/unicode-snowman',
                     rel=None,
                     type_=None,
                     hreflang=None,
                     title=None,
                     length=None)
        ],
        categories=[],
        published=None,
        rights=None,
        summary=None,
        content=AtomTextConstruct(text_type=AtomTextType.text,
                                  lang=None,
                                  value='☃'),
        source=None)
    source_feed = AtomFeed(
        title=AtomTextConstruct(text_type=AtomTextType.text,
                                lang=None,
                                value='Example, Inc.'),
        id_='http://example.org/',
        updated=datetime.datetime(2003, 12, 13, 18, 30, 2, tzinfo=tzutc()),
        authors=[AtomPerson(name='Foo Bar', uri=None, email=None)],
        contributors=[],
        links=[],
        categories=[],
        generator=None,
        subtitle=None,
        rights=None,
        icon=None,
        logo=None,
        entries=[])
    expected_entry_3 = AtomEntry(
        title=AtomTextConstruct(text_type=AtomTextType.text,
                                lang=None,
                                value='Unicode snowman 3'),
        id_='http://richard.plop/2017/6/5/article-3',
        updated=datetime.datetime(2016, 12, 29, 0, 0, tzinfo=tzutc()),
        authors=[AtomPerson(name='Foo Bar', uri=None, email=None)],
        contributors=[],
        links=[
            AtomLink(href='http://richard.plop/2017/6/5/unicode-snowman',
                     rel=None,
                     type_=None,
                     hreflang=None,
                     title=None,
                     length=None)
        ],
        categories=[],
        published=None,
        rights=None,
        summary=None,
        content=AtomTextConstruct(text_type=AtomTextType.text,
                                  lang=None,
                                  value='☃'),
        source=source_feed)
    expected = AtomFeed(
        title=AtomTextConstruct(text_type=AtomTextType.text,
                                lang=None,
                                value="Rïchàrd Plop's blog"),
        id_='http://richard.plop/feed.atom',
        updated=datetime.datetime(2017, 6, 5, 0, 0, tzinfo=tzutc()),
        authors=[],
        contributors=[],
        links=[
            AtomLink(href='http://richard.plop/',
                     rel=None,
                     type_=None,
                     hreflang=None,
                     title=None,
                     length=None),
            AtomLink(href='http://richard.plop/feed.atom',
                     rel='self',
                     type_=None,
                     hreflang=None,
                     title=None,
                     length=None)
        ],
        categories=[AtomCategory(term='python', scheme=None, label='Python')],
        generator=AtomGenerator(name='Werkzeug', uri=None, version=None),
        subtitle=AtomTextConstruct(text_type=AtomTextType.text,
                                   lang=None,
                                   value="Rïchàrd Plop's personal blog."),
        rights=None,
        icon=None,
        logo=None,
        entries=[expected_entry_1, expected_entry_2, expected_entry_3])
    assert parse_atom_file('tests/atom/unicode.xml') == expected
def test_rfc_more_extensive():
    expected_entry = AtomEntry(
        title=AtomTextConstruct(text_type=AtomTextType.text,
                                lang=None,
                                value='Atom draft-07 snapshot'),
        id_='tag:example.org,2003:3.2397',
        updated=datetime.datetime(2005, 7, 31, 12, 29, 29, tzinfo=tzutc()),
        authors=[
            AtomPerson(name='Mark Pilgrim',
                       uri='http://example.org/',
                       email='*****@*****.**')
        ],
        contributors=[
            AtomPerson(name='Sam Ruby', uri=None, email=None),
            AtomPerson(name='Joe Gregorio', uri=None, email=None)
        ],
        links=[
            AtomLink(href='http://example.org/2005/04/02/atom',
                     rel='alternate',
                     type_='text/html',
                     hreflang=None,
                     title=None,
                     length=None),
            AtomLink(href='http://example.org/audio/ph34r_my_podcast.mp3',
                     rel='enclosure',
                     type_='audio/mpeg',
                     hreflang=None,
                     title=None,
                     length=1337)
        ],
        categories=[],
        published=datetime.datetime(2003,
                                    12,
                                    13,
                                    8,
                                    29,
                                    29,
                                    tzinfo=tzoffset(None, -14400)),
        rights=None,
        summary=None,
        content=AtomTextConstruct(text_type=AtomTextType.xhtml,
                                  lang=None,
                                  value=''),
        source=None)
    expected = AtomFeed(
        title=AtomTextConstruct(text_type=AtomTextType.text,
                                lang=None,
                                value='dive into mark'),
        id_='tag:example.org,2003:3',
        updated=datetime.datetime(2005, 7, 31, 12, 29, 29, tzinfo=tzutc()),
        authors=[],
        contributors=[],
        links=[
            AtomLink(href='http://example.org/',
                     rel='alternate',
                     type_='text/html',
                     hreflang='en',
                     title=None,
                     length=None),
            AtomLink(href='http://example.org/feed.atom',
                     rel='self',
                     type_='application/atom+xml',
                     hreflang=None,
                     title=None,
                     length=None)
        ],
        categories=[],
        generator=AtomGenerator(name='Example Toolkit',
                                uri='http://www.example.com/',
                                version='1.0'),
        subtitle=AtomTextConstruct(text_type=AtomTextType.html,
                                   lang=None,
                                   value='A <em>lot</em> of effort\n        '
                                   'went into making this effortless'),
        rights=AtomTextConstruct(text_type=AtomTextType.text,
                                 lang=None,
                                 value='Copyright (c) 2003, Mark Pilgrim'),
        icon=None,
        logo=None,
        entries=[expected_entry])
    assert (parse_atom_file('tests/atom/rfc-more-extensive.xml') == expected)
Exemplo n.º 5
0
def test_broken_missing_updated():
    # The RFC mandates that feed and entries have an updated date
    # but this is rarely the case in practice.
    parsed = parse_atom_file('tests/atom/broken-missing-updated.xml')
    assert parsed.updated is None
    assert parsed.entries[0].updated is None
Exemplo n.º 6
0
def test_broken_missing_author():
    # The RFC mandates that at least one of feed or entries must have an author
    # but this is rarely the case in practice.
    parsed = parse_atom_file('tests/atom/broken-xkcd.xml')
    assert parsed.authors == list()
    assert parsed.entries[0].authors == list()
Exemplo n.º 7
0
def test_broken_missing_author_name():
    with pytest.raises(FeedParseError):
        parse_atom_file('tests/atom/broken-missing-author-name.xml')
Exemplo n.º 8
0
def test_broken_missing_id():
    with pytest.raises(FeedParseError):
        parse_atom_file('tests/atom/broken-missing-id.xml')