예제 #1
0
def test_default_feed_subtitle():
    """It should fall back to the default feed subtitle if none is given."""
    feed = atom_feed._feed_from_annotations(
        annotations=factories.Annotation.create_batch(3), atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["subtitle"] == "The Web. Annotated"
예제 #2
0
def test_with_no_annotations():
    feed = atom_feed._feed_from_annotations(
        annotations=[],
        atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["entries"] == []
예제 #3
0
def test_default_feed_subtitle():
    """It should fall back to the default feed subtitle if none is given."""
    feed = atom_feed._feed_from_annotations(
        annotations=factories.Annotation.create_batch(3), atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["subtitle"] == "The Web. Annotated"
예제 #4
0
def test_feed_subtitle():
    """A custom subtitle should be used as the feed subtitle if given."""
    feed = atom_feed._feed_from_annotations(
        subtitle="My Custom Feed Subtitle",
        annotations=factories.Annotation.create_batch(3), atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["subtitle"] == "My Custom Feed Subtitle"
예제 #5
0
def test_feed_subtitle():
    """A custom subtitle should be used as the feed subtitle if given."""
    feed = atom_feed._feed_from_annotations(
        subtitle="My Custom Feed Subtitle",
        annotations=factories.Annotation.create_batch(3), atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["subtitle"] == "My Custom Feed Subtitle"
예제 #6
0
def test_annotation_with_no_document_title():
    annotation = factories.Annotation()
    del annotation["document"]["title"]

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["entries"][0]["title"] == ""
예제 #7
0
def test_annotation_with_no_document_title():
    annotation = factories.Annotation()
    del annotation["document"]["title"]

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["entries"][0]["title"] == ""
예제 #8
0
def test_annotation_with_no_target():
    annotation = factories.Annotation()
    del annotation["target"]

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["entries"][0]["content"] == annotation["text"]
예제 #9
0
def test_annotation_with_no_target():
    annotation = factories.Annotation()
    del annotation["target"]

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["entries"][0]["content"] == annotation["text"]
예제 #10
0
def test_feed_id():
    """The feed should use its own URL as its id."""
    atom_url = "http://example.com/annotations.atom"

    feed = atom_feed._feed_from_annotations(
        annotations=factories.Annotation.create_batch(3),
        atom_url=atom_url,
        annotation_url=_mock_annotation_url_function())

    assert feed["id"] == atom_url
예제 #11
0
def test_feed_entries():
    """Feeds should contain the right entries in the right order."""
    annotations = [factories.Annotation(random_number=n) for n in range(1, 4)]

    feed = atom_feed._feed_from_annotations(
        annotations, atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert [entry["title"] for entry in feed["entries"]] == [
        "Example Document 1", "Example Document 2", "Example Document 3"]
예제 #12
0
def test_entry_updated_date():
    datestring = "2015-03-19T11:27:17.551191+00:00"
    annotation = factories.Annotation(updated=datestring)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["updated"] == datestring
예제 #13
0
def test_entry_author_name():
    """Entries should have an author name based on the annotation user name."""
    annotation = factories.Annotation(username="******")

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["author"]["name"] == "jon"
예제 #14
0
def test_entry_author_name():
    """Entries should have an author name based on the annotation user name."""
    annotation = factories.Annotation(username="******")

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["author"]["name"] == "jon"
예제 #15
0
def test_entry_updated_date():
    datestring = "2015-03-19T11:27:17.551191+00:00"
    annotation = factories.Annotation(updated=datestring)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["updated"] == datestring
예제 #16
0
def test_feed_entries():
    """Feeds should contain the right entries in the right order."""
    annotations = [factories.Annotation(random_number=n) for n in range(1, 4)]

    feed = atom_feed._feed_from_annotations(
        annotations, atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert [entry["title"] for entry in feed["entries"]] == [
        "Example Document 1", "Example Document 2", "Example Document 3"]
예제 #17
0
def test_feed_id():
    """The feed should use its own URL as its id."""
    atom_url = "http://example.com/annotations.atom"

    feed = atom_feed._feed_from_annotations(
        annotations=factories.Annotation.create_batch(3),
        atom_url=atom_url,
        annotation_url=_mock_annotation_url_function())

    assert feed["id"] == atom_url
예제 #18
0
def test_entry_content_includes_annotation_text():
    """The entry content should include the annotation note."""
    text = "A test annotation"
    annotation = factories.Annotation(text=text)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert text in entry["content"]
예제 #19
0
def test_entry_title():
    """Entries should have a title based on the annotated document's title."""
    title = "My Test Document"
    annotation = factories.Annotation(document_title=title)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["title"] == title
예제 #20
0
def test_annotation_with_no_text():
    text = "Some annotated text from a web page"
    annotation = factories.Annotation(exact_text=text)
    del annotation["text"]

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["entries"][0]["content"] == (
        "<blockquote>{text}</blockquote>".format(text=text))
예제 #21
0
def test_feed_html_link():
    """The given html_url should be used in a rel="alternate" link."""
    html_url = "http://www.example.com/annotations.html"
    feed = atom_feed._feed_from_annotations(
        html_url=html_url,
        annotations=factories.Annotation.create_batch(3), atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["links"][1]["href"] == html_url
    assert feed["links"][1]["rel"] == "alternate"
    assert feed["links"][1]["type"] == "text/html"
예제 #22
0
def test_entry_content_includes_annotation_text():
    """The entry content should include the annotation note."""
    text = "A test annotation"
    annotation = factories.Annotation(text=text)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert text in entry["content"]
예제 #23
0
def test_feed_self_link():
    """The given atom_url should be used in a rel="self" link."""
    atom_url = "http://www.example.com/annotations.atom"
    feed = atom_feed._feed_from_annotations(
        annotations=factories.Annotation.create_batch(3),
        atom_url=atom_url,
        annotation_url=_mock_annotation_url_function())

    assert feed["links"][0]["href"] == atom_url
    assert feed["links"][0]["rel"] == "self"
    assert feed["links"][0]["type"] == "application/atom+xml"
예제 #24
0
def test_entry_title():
    """Entries should have a title based on the annotated document's title."""
    title = "My Test Document"
    annotation = factories.Annotation(document_title=title)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["title"] == title
예제 #25
0
def test_annotation_with_no_text():
    text = "Some annotated text from a web page"
    annotation = factories.Annotation(exact_text=text)
    del annotation["text"]

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["entries"][0]["content"] == (
        "<blockquote>{text}</blockquote>".format(text=text))
예제 #26
0
def test_feed_html_link():
    """The given html_url should be used in a rel="alternate" link."""
    html_url = "http://www.example.com/annotations.html"
    feed = atom_feed._feed_from_annotations(
        html_url=html_url,
        annotations=factories.Annotation.create_batch(3), atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["links"][1]["href"] == html_url
    assert feed["links"][1]["rel"] == "alternate"
    assert feed["links"][1]["type"] == "text/html"
예제 #27
0
def test_feed_self_link():
    """The given atom_url should be used in a rel="self" link."""
    atom_url = "http://www.example.com/annotations.atom"
    feed = atom_feed._feed_from_annotations(
        annotations=factories.Annotation.create_batch(3),
        atom_url=atom_url,
        annotation_url=_mock_annotation_url_function())

    assert feed["links"][0]["href"] == atom_url
    assert feed["links"][0]["rel"] == "self"
    assert feed["links"][0]["type"] == "application/atom+xml"
예제 #28
0
def test_entry_id():
    """Entry IDs should be tag URIs based on domain, day and annotation ID."""
    annotation = factories.Annotation(
        id="12345",
        created=datetime.datetime(year=2015, month=3, day=19).isoformat())

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["id"] == "tag:example.com,2015-03-19:12345"
예제 #29
0
def test_entry_id():
    """Entry IDs should be tag URIs based on domain, day and annotation ID."""
    annotation = factories.Annotation(
        id="12345",
        created=datetime.datetime(year=2015, month=3, day=19).isoformat())

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["id"] == "tag:example.com,2015-03-19:12345"
예제 #30
0
def test_entry_content_is_escaped():
    """'&', '<' and '>' should be escaped in entry contents."""
    text = "An annotation with <code>HTML</code> in it, &#374;"
    exact_text = "Some <b>web page</b> text &#355;"
    annotation = factories.Annotation(text=text, exact_text=exact_text)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    for s in ["<code>", "</code>", "<b>", "</b>", "&#374;", "&#355;"]:
        assert s not in entry["content"]
예제 #31
0
def test_entry_content_includes_selected_text():
    """The entry content should include the selected text in a blockquote."""
    text = "Some annotated text from a web page"
    annotation = factories.Annotation(exact_text=text)

    feed = atom_feed._feed_from_annotations(
        [annotation],
        atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert ("&lt;blockquote&gt;{text}&lt;/blockquote&gt;".format(text=text)
            in entry["content"])
예제 #32
0
def test_entry_content_is_escaped():
    """'&', '<' and '>' should be escaped in entry contents."""
    text = "An annotation with <code>HTML</code> in it, &#374;"
    exact_text = "Some <b>web page</b> text &#355;"
    annotation = factories.Annotation(text=text, exact_text=exact_text)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    for s in ["<code>", "</code>", "<b>", "</b>", "&#374;", "&#355;"]:
        assert s not in entry["content"]
예제 #33
0
def test_entry_content_includes_selected_text():
    """The entry content should include the selected text in a blockquote."""
    text = "Some annotated text from a web page"
    annotation = factories.Annotation(exact_text=text)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert (
        "&lt;blockquote&gt;{text}&lt;/blockquote&gt;".format(text=text)
        in entry["content"])
예제 #34
0
def test_html_link():
    """Entries should have links to their HTML representation."""
    annotation = factories.Annotation()

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    matching_links = [l for l in entry["links"]
                      if l["href"] == "http://example.com/annotations/12345"]
    assert len(matching_links) == 1
    matching_link = matching_links[0]
    assert matching_link["rel"] == "alternate"
    assert matching_link["type"] == "text/html"
예제 #35
0
def test_html_link():
    """Entries should have links to their HTML representation."""
    annotation = factories.Annotation()

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    matching_links = [l for l in entry["links"]
                      if l["href"] == "http://example.com/annotations/12345"]
    assert len(matching_links) == 1
    matching_link = matching_links[0]
    assert matching_link["rel"] == "alternate"
    assert matching_link["type"] == "text/html"
예제 #36
0
def test_malformed_target():
    # This annotation has a broken target (a dict instead of a list), but we
    # shouldn't explode in this case.
    annotation = factories.Annotation()
    annotation['target'] = {
        'selector': [
            {'start': None, 'end': None, 'type': 'TextPositionSelector'},
            {'exact': None, 'prefix': None, 'type': 'TextQuoteSelector', 'suffix': None}
        ]
    }

    feed = atom_feed._feed_from_annotations(
        [annotation],
        atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert len(feed["entries"]) == 1
예제 #37
0
def test_annotation_with_targets():
    annotation = factories.Annotation()
    annotation2 = factories.Annotation()

    target1 = annotation["target"][0]
    target2 = annotation2["target"][0]

    annotation["target"] = [target1, target2]

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert len(feed["entries"][0]["links"]) == 3
    assert feed["entries"][0]["links"][1]["rel"] == "related"
    assert feed["entries"][0]["links"][1]["href"] == target1["source"]
    assert feed["entries"][0]["links"][2]["rel"] == "related"
    assert feed["entries"][0]["links"][2]["href"] == target2["source"]
예제 #38
0
def test_annotation_with_non_unicode_characters():
    username = u"seanh\u2119h"
    exact_text = u"Some selected \u01b4 non-ascii text"
    document_title = u"Non-ascii \u2602 title"
    text = u"Some non-ascii \u210c annotation text"
    annotation = factories.Annotation(username=username,
                                      exact_text=exact_text,
                                      document_title=document_title,
                                      text=text)

    feed = atom_feed._feed_from_annotations(
        [annotation],
        atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["author"]["name"] == username
    assert exact_text in entry["content"]
    assert entry["title"] == document_title
    assert text in entry["content"]
예제 #39
0
def test_annotation_with_non_unicode_characters():
    username = u"seanh\u2119h"
    exact_text = u"Some selected \u01b4 non-ascii text"
    document_title = u"Non-ascii \u2602 title"
    text = u"Some non-ascii \u210c annotation text"
    annotation = factories.Annotation(
        username=username,
        exact_text=exact_text,
        document_title=document_title,
        text=text)

    feed = atom_feed._feed_from_annotations(
        [annotation], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    entry = feed["entries"][0]
    assert entry["author"]["name"] == username
    assert exact_text in entry["content"]
    assert entry["title"] == document_title
    assert text in entry["content"]
예제 #40
0
def test_with_no_annotations():
    feed = atom_feed._feed_from_annotations(
        annotations=[], atom_url=None,
        annotation_url=_mock_annotation_url_function())

    assert feed["entries"] == []