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"
def test_with_no_annotations(): feed = atom_feed._feed_from_annotations( annotations=[], atom_url=None, annotation_url=_mock_annotation_url_function()) assert feed["entries"] == []
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"
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"] == ""
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"]
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
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"]
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
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"
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"]
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
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))
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"
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"
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"
def test_entry_content_is_escaped(): """'&', '<' and '>' should be escaped in entry contents.""" text = "An annotation with <code>HTML</code> in it, Ŷ" exact_text = "Some <b>web page</b> text ţ" 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>", "Ŷ", "ţ"]: assert s not in entry["content"]
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 ("<blockquote>{text}</blockquote>".format(text=text) in entry["content"])
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 ( "<blockquote>{text}</blockquote>".format(text=text) in entry["content"])
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"
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
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"]
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"]
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"]