Skip to content

Commit

Permalink
add test for microformats2.object_urls()
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Apr 17, 2016
1 parent 8f23e84 commit fe4121c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions granary/microformats2.py
Expand Up @@ -706,11 +706,11 @@ def tags_to_html(tags, classname):
for url, name in urls)


def object_urls(tag):
def object_urls(obj):
"""Returns an object's unique URLs, preserving order.
"""
return util.uniquify(util.trim_nulls(
[tag.get('url')] + [u.get('value') for u in tag.get('urls', [])]))
[obj.get('url')] + [u.get('value') for u in obj.get('urls', [])]))


def author_display_name(hcard):
Expand Down
16 changes: 16 additions & 0 deletions granary/test/test_microformats2.py
Expand Up @@ -471,3 +471,19 @@ def test_find_author(self):
</body>
""", url='http://123')))

def test_object_urls(self):
for expected, actor in (
([], {}),
([], {'displayName': 'foo'}),
([], {'url': None, 'urls': []}),
(['http://foo'], {'url': 'http://foo'}),
(['http://foo'], {'urls': [{'value': 'http://foo'}]}),
(['http://foo', 'https://bar', 'http://baz'], {
'url': 'http://foo',
'urls': [{'value': 'https://bar'},
{'value': 'http://foo'},
{'value': 'http://baz'},
],
}),
):
self.assertEquals(expected, microformats2.object_urls(actor))

0 comments on commit fe4121c

Please sign in to comment.