Skip to content

Commit

Permalink
Added child aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed May 2, 2014
1 parent 62065dd commit 3006af6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -12,6 +12,7 @@ Changelog
- Renamed Item.find_rlinks() to Item.find_child_links()
- Changed '--no-rlink-check' to '--no-child-check'
- Added Item.find_child_items() and Item.find_child_documents()
- Added aliases to Item: parent_links, child_links/items/documents

0.5 (2014/04/25)
----------------
Expand Down
16 changes: 16 additions & 0 deletions doorstop/core/item.py
Expand Up @@ -345,6 +345,16 @@ def links(self, value):
"""Set the list of item IDs this item links to."""
self._data['links'] = set(value)

@property
def parent_links(self):
"""Get a list of the item IDs this item links to."""
return self.links # alias

@parent_links.setter
def parent_links(self, value):
"""Set the list of item IDs this item links to."""
self.links = value # alias

# actions ################################################################

@auto_save
Expand Down Expand Up @@ -545,6 +555,8 @@ def find_child_links(self, find_all=True):
identifiers = [item.id for item in items]
return identifiers

child_links = property(find_child_links)

def find_child_items(self, find_all=True):
"""Get a list of items that link to this item.
Expand All @@ -556,6 +568,8 @@ def find_child_items(self, find_all=True):
items, _ = self._find_child_objects(find_all=find_all)
return items

child_items = property(find_child_items)

def find_child_documents(self):
"""Get a list of documents that should link to this item's document.
Expand All @@ -565,6 +579,8 @@ def find_child_documents(self):
_, documents = self._find_child_objects(find_all=False)
return documents

child_documents = property(find_child_documents)

def _find_child_objects(self, find_all=True):
"""Get lists of child items and child documents.
Expand Down
18 changes: 12 additions & 6 deletions doorstop/core/test/test_item.py
Expand Up @@ -317,6 +317,15 @@ def test_unlink_by_item(self):
self.item.unlink(item)
self.assertEqual([], self.item.links)

def test_links_alias(self):
"""Verify 'parent_links' is an alias for links."""
links1 = ['alias1']
links2 = ['alias2']
self.item.parent_links = links1
self.assertEqual(links1, self.item.links)
self.item.links = links2
self.assertEqual(links2, self.item.parent_links)

def test_find_ref(self):
"""Verify an item's reference can be found."""
self.item.ref = "REF" + "123" # to avoid matching in this file
Expand Down Expand Up @@ -379,12 +388,9 @@ def mock_iter2(self): # pylint: disable=W0613

def test_find_child_objects_standalone(self):
"""Verify a standalone item has no child objects."""
links = self.item.find_child_links()
items = self.item.find_child_items()
documents = self.item.find_child_documents()
self.assertEqual([], links)
self.assertEqual([], items)
self.assertEqual([], documents)
self.assertEqual([], self.item.child_links)
self.assertEqual([], self.item.child_items)
self.assertEqual([], self.item.child_documents)

def test_invalid_file_name(self):
"""Verify an invalid file name cannot be a requirement."""
Expand Down

0 comments on commit 3006af6

Please sign in to comment.