Skip to content

Commit

Permalink
Document.get_by_uri() returns None on not found
Browse files Browse the repository at this point in the history
Close #123
  • Loading branch information
tilgovi committed May 16, 2015
1 parent 684bbfd commit 42dc78e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion annotator/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Document(es.Model):
def get_by_uri(cls, uri):
"""Returns the first document match for a given URI."""
results = cls._get_all_by_uris([uri])
return results[0] if len(results) > 0 else []
return results[0] if len(results) > 0 else None

@classmethod
def _get_all_by_uris(cls, uris):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ def test_get_by_uri(self):

doc = Document.get_by_uri("https://peerj.com/articles/53/")
assert doc
assert_equal(doc['title'], "document1")
assert_equal(doc['title'], "document1")

def test_get_by_uri_not_found(self):
assert Document.get_by_uri("bogus") is None

def test_uris(self):
d = Document({
Expand Down

0 comments on commit 42dc78e

Please sign in to comment.