Beispiel #1
0
def test_feed_from_annotations_description():
    """The feed should use the given description for its description field."""
    feed = rss.feed_from_annotations(
        [], _annotation_url(), mock.Mock(), "", "", "The Web. Annotated"
    )

    assert feed["description"] == "The Web. Annotated"
Beispiel #2
0
def test_feed_from_annotations_with_1_annotation(factories):
    """If there's 1 annotation it should return 1 entry."""
    feed = rss.feed_from_annotations(
        [factories.Annotation()], _annotation_url(), mock.Mock(), "", "", ""
    )

    assert len(feed["entries"]) == 1
Beispiel #3
0
def test_feed_from_annotations_title():
    """The feed should use the given title for its title field."""
    feed = rss.feed_from_annotations(
        [], _annotation_url(), mock.Mock(), "", "Hypothesis Stream", ""
    )

    assert feed["title"] == "Hypothesis Stream"
Beispiel #4
0
def test_feed_from_annotations_link():
    """The feed should use the given html_url for its html_url field."""
    feed = rss.feed_from_annotations(
        [], _annotation_url(), mock.Mock(), 'http://Hypothes.is/stream', '',
        '')

    assert feed['html_url'] == 'http://Hypothes.is/stream'
Beispiel #5
0
def render_rss(request, annotations, rss_url, html_url, title, description):
    """Return a rendered RSS feed of the given annotations.

    :param annotations: The list of annotations to render as the feed's items
    :type annotations: list of dicts

    :param rss_url: The URL that this RSS feed will be served at
    :type rss_url: string

    :param html_url: The URL of the HTML page that this RSS feed is a feed of
    :type html_url: string

    :param title: The title of this RSS feed
    :type title: unicode

    :param description: The description of this RSS feed
    :type description: unicode

    :rtype: pyramid.response.Response

    """
    request.response.content_type = "application/rss+xml"

    def annotation_url(annotation):
        """Return the HTML permalink URL for the given annotation."""
        return request.route_url('annotation', id=annotation["id"])

    feed = rss.feed_from_annotations(
        annotations=annotations, annotation_url=annotation_url,
        rss_url=rss_url, html_url=html_url, title=title,
        description=description)

    return renderers.render_to_response(
        'h:templates/rss.xml.jinja2', {"feed": feed}, request=request)
Beispiel #6
0
def test_feed_from_annotations_item_author():
    """Feed items should include the annotation's author."""
    annotation = factories.Annotation(username="******")

    feed = rss.feed_from_annotations(
        [annotation], _annotation_url(), mock.Mock(), '', '', '')

    assert feed['entries'][0]['author'] == {'name': 'janebloggs'}
Beispiel #7
0
def test_feed_annotations_pubDate():
    """It should render the pubDates of annotations correctly."""
    ann = _annotation(created=datetime.datetime(year=2015, month=3, day=11, hour=10, minute=43, second=54))

    feed = rss.feed_from_annotations(
        [ann], _annotation_url(), mock.Mock(), '', '', '')

    assert feed['entries'][0]['pubDate'] == 'Wed, 11 Mar 2015 10:43:54 -0000'
Beispiel #8
0
def test_feed_from_annotations_item_titles():
    """Feed items should include the annotation's document's title."""
    annotation = factories.Annotation()

    feed = rss.feed_from_annotations(
        [annotation], _annotation_url(), mock.Mock(), '', '', '')

    assert feed['entries'][0]['title'] == annotation['document']['title']
Beispiel #9
0
def test_feed_from_annotations_html_links():
    """Items should include links to the annotations' HTML pages."""
    annotation_url = _annotation_url()

    feed = rss.feed_from_annotations(
        [factories.Annotation()], annotation_url, mock.Mock(), '', '', '')

    item = feed['entries'][0]
    assert item['link'] == annotation_url.return_value
Beispiel #10
0
def test_feed_from_annotations_item_titles(factories):
    """Feed items should include the annotation's document's title."""
    document = factories.Document(title='Hello, World')
    annotation = factories.Annotation(document=document)

    feed = rss.feed_from_annotations(
        [annotation], _annotation_url(), mock.Mock(), '', '', '')

    assert feed['entries'][0]['title'] == annotation.document.title
Beispiel #11
0
def test_feed_from_annotations_item_guid():
    """Feed items should use the annotation's HTML URL as their GUID."""
    feed = rss.feed_from_annotations(
        [factories.Annotation(
            id='id',
            created=datetime.datetime(year=2015, month=3, day=11).isoformat())
         ], _annotation_url(), mock.Mock(), '', '', '')

    assert feed['entries'][0]['guid'] == 'tag:hypothes.is,2015-09:id'
Beispiel #12
0
def test_feed_from_annotations_item_author():
    """Feed items should include the annotation's author."""
    annotation = _annotation()

    feed = rss.feed_from_annotations(
        [annotation], _annotation_url(), mock.Mock(), "", "", ""
    )

    assert feed["entries"][0]["author"] == {"name": "janebloggs"}
Beispiel #13
0
def test_feed_from_annotations_item_descriptions():
    """Feed items should include a description of the annotation."""
    with mock.patch("h.test.factories.api_models.Annotation.description",
                    new_callable=mock.PropertyMock) as description:
        feed = rss.feed_from_annotations(
            [factories.Annotation()], _annotation_url(), mock.Mock(), '', '', '')

        assert feed['entries'][0]['description'] == (
            description.return_value)
Beispiel #14
0
def test_feed_from_annotations_with_3_annotations():
    """If there are 3 annotations it should return 3 entries."""
    annotations = [factories.Annotation(), factories.Annotation(),
                   factories.Annotation()]

    feed = rss.feed_from_annotations(
        annotations, _annotation_url(), mock.Mock(), '', '', '')

    assert len(feed['entries']) == 3
Beispiel #15
0
def test_feed_from_annotations_item_guid(factories):
    """Feed items should use the annotation's HTML URL as their GUID."""
    annotation = factories.Annotation(
        created=datetime.datetime(year=2015, month=3, day=11))

    feed = rss.feed_from_annotations(
        [annotation], _annotation_url(), mock.Mock(), '', '', '')

    assert feed['entries'][0]['guid'] == (
        'tag:hypothes.is,2015-09:' + annotation.id)
Beispiel #16
0
def test_feed_from_annotations_item_descriptions(factories):
    """Feed items should include a description of the annotation."""
    with mock.patch(
        "h.feeds.rss.presenters.AnnotationHTMLPresenter.description",
        new_callable=mock.PropertyMock,
    ) as description:
        feed = rss.feed_from_annotations(
            [factories.Annotation()], _annotation_url(), mock.Mock(), "", "", ""
        )

        assert feed["entries"][0]["description"] == (description.return_value)
Beispiel #17
0
def test_feed_from_annotations_with_3_annotations(factories):
    """If there are 3 annotations it should return 3 entries."""
    annotations = [
        factories.Annotation(),
        factories.Annotation(),
        factories.Annotation()
    ]

    feed = rss.feed_from_annotations(annotations, _annotation_url(),
                                     mock.Mock(), '', '', '')

    assert len(feed['entries']) == 3
Beispiel #18
0
def test_feed_from_annotations_pubDate():
    """The pubDate should be the updated time of the most recent annotation."""
    annotations = [
        _annotation(updated=datetime.datetime(year=2015, month=3, day=11, hour=10, minute=45, second=54, microsecond=537626)),
        _annotation(updated=datetime.datetime(year=2015, month=2, day=11, hour=10, minute=43, second=54, microsecond=537626)),
        _annotation(updated=datetime.datetime(year=2015, month=1, day=11, hour=10, minute=43, second=54, microsecond=537626))
    ]

    feed = rss.feed_from_annotations(
        annotations, _annotation_url(), mock.Mock(), '', '', '')

    assert feed['pubDate'] == 'Wed, 11 Mar 2015 10:45:54 -0000'
Beispiel #19
0
def test_feed_from_annotations_pubDate():
    """The pubDate should be the updated time of the most recent annotation."""
    annotations = [
        factories.Annotation(updated='2015-03-11T10:45:54.537626+00:00'),
        factories.Annotation(updated='2015-02-11T10:43:54.537626+00:00'),
        factories.Annotation(updated='2015-01-11T10:43:54.537626+00:00')
    ]

    feed = rss.feed_from_annotations(
        annotations, _annotation_url(), mock.Mock(), '', '', '')

    assert feed['pubDate'] == 'Wed, 11 Mar 2015 10:45:54 UTC'
Beispiel #20
0
def test_feed_from_annotations_pubDate():
    """The pubDate should be the updated time of the most recent annotation."""
    annotations = [
        _annotation(
            updated=datetime.datetime(
                year=2015,
                month=3,
                day=11,
                hour=10,
                minute=45,
                second=54,
                microsecond=537626,
            )
        ),
        _annotation(
            updated=datetime.datetime(
                year=2015,
                month=2,
                day=11,
                hour=10,
                minute=43,
                second=54,
                microsecond=537626,
            )
        ),
        _annotation(
            updated=datetime.datetime(
                year=2015,
                month=1,
                day=11,
                hour=10,
                minute=43,
                second=54,
                microsecond=537626,
            )
        ),
    ]

    feed = rss.feed_from_annotations(
        annotations, _annotation_url(), mock.Mock(), "", "", ""
    )

    assert feed["pubDate"] == "Wed, 11 Mar 2015 10:45:54 -0000"
Beispiel #21
0
def render_rss(  # pylint:disable=too-many-arguments
        request, annotations, rss_url, html_url, title, description):
    """
    Return a rendered RSS feed of the given annotations.

    :param annotations: The list of annotations to render as the feed's items
    :type annotations: list of dicts

    :param rss_url: The URL that this RSS feed will be served at
    :type rss_url: string

    :param html_url: The URL of the HTML page that this RSS feed is a feed of
    :type html_url: string

    :param title: The title of this RSS feed
    :type title: unicode

    :param description: The description of this RSS feed
    :type description: unicode

    :rtype: pyramid.response.Response

    """
    def annotation_url(annotation):
        """Return the HTML permalink URL for the given annotation."""
        return request.route_url("annotation", id=annotation.id)

    feed = rss.feed_from_annotations(
        annotations=annotations,
        annotation_url=annotation_url,
        rss_url=rss_url,
        html_url=html_url,
        title=title,
        description=description,
    )

    response = renderers.render_to_response("h:templates/rss.xml.jinja2",
                                            {"feed": feed},
                                            request=request)
    response.content_type = "application/rss+xml"
    return response
Beispiel #22
0
def test_feed_from_annotations_title():
    """The feed should use the given title for its title field."""
    feed = rss.feed_from_annotations(
        [], _annotation_url(), mock.Mock(), '', 'Hypothesis Stream', '')

    assert feed['title'] == 'Hypothesis Stream'
Beispiel #23
0
def test_feed_from_annotations_link():
    """The feed should use the given html_url for its html_url field."""
    feed = rss.feed_from_annotations([], _annotation_url(), mock.Mock(),
                                     'http://Hypothes.is/stream', '', '')

    assert feed['html_url'] == 'http://Hypothes.is/stream'
Beispiel #24
0
def test_feed_from_annotations_with_0_annotations():
    """If there are no annotations it should return [] for entries."""
    feed = rss.feed_from_annotations([], _annotation_url(), mock.Mock(), '',
                                     '', '')

    assert feed['entries'] == []
Beispiel #25
0
def test_feed_from_annotations_with_1_annotation():
    """If there's 1 annotation it should return 1 entry."""
    feed = rss.feed_from_annotations(
        [factories.Annotation()], _annotation_url(), mock.Mock(), '', '', '')

    assert len(feed['entries']) == 1
Beispiel #26
0
def test_feed_from_annotations_description():
    """The feed should use the given description for its description field."""
    feed = rss.feed_from_annotations([], _annotation_url(), mock.Mock(), '',
                                     '', 'The Web. Annotated')

    assert feed['description'] == 'The Web. Annotated'
Beispiel #27
0
def test_feed_from_annotations_title():
    """The feed should use the given title for its title field."""
    feed = rss.feed_from_annotations([], _annotation_url(), mock.Mock(), "",
                                     "Hypothesis Stream", "")

    assert feed["title"] == "Hypothesis Stream"
Beispiel #28
0
def test_feed_from_annotations_title():
    """The feed should use the given title for its title field."""
    feed = rss.feed_from_annotations([], _annotation_url(), mock.Mock(), '',
                                     'Hypothesis Stream', '')

    assert feed['title'] == 'Hypothesis Stream'
Beispiel #29
0
def test_feed_from_annotations_with_0_annotations():
    """If there are no annotations it should return [] for entries."""
    feed = rss.feed_from_annotations(
        [], _annotation_url(), mock.Mock(), '', '', '')

    assert feed['entries'] == []