diff --git a/superscore/tests/test_client.py b/superscore/tests/test_client.py index 316e386..fccd79d 100644 --- a/superscore/tests/test_client.py +++ b/superscore/tests/test_client.py @@ -195,7 +195,7 @@ def test_fill_depth(fill_depth: int): bknd = TestBackend([deep_coll]) client = Client(backend=bknd) - assert nest_depth(deep_coll) == 40 + assert nest_depth(deep_coll) == 20 deep_coll.swap_to_uuids() # for this test we want everything to be UUIDS for entry in bknd._entry_cache.values(): diff --git a/superscore/tests/test_views.py b/superscore/tests/test_views.py index c4c27ad..e987e29 100644 --- a/superscore/tests/test_views.py +++ b/superscore/tests/test_views.py @@ -234,7 +234,7 @@ def test_fill_uuids_nestable( assert all(not isinstance(c, UUID) for c in nested_coll.children) -def test_fill_uuids_entry_item(linac_backend: TestBackend): +def test_fill_uuids_entry_item(linac_backend: TestBackend, qtbot: QtBot): client = Client(backend=linac_backend) nested_coll = linac_backend.get_entry("441ff79f-4948-480e-9646-55a1462a5a70") assert not all(isinstance(c, UUID) for c in nested_coll.children) @@ -247,6 +247,19 @@ def test_fill_uuids_entry_item(linac_backend: TestBackend): original_depth = nest_depth(tree_model.root_item) assert original_depth == 1 - tree_model.root_item.fill_uuids(client) - new_depth = nest_depth(tree_model.root_item) - assert new_depth == 4 + # fill just the first child + # fill depth can depend on how the backend returns data. Backend may not + # be lazy, so we assert only child1's children have EntryItems + root_item = tree_model.root_item + child1 = root_item.child(0) + assert child1.childCount() == 0 + child1.fill_uuids(client) + assert child1.childCount() > 0 + assert root_item.child(1).childCount() == 0 + assert root_item.child(2).childCount() == 0 + + # filling the root item fills its children, which held uuids before + root_item.fill_uuids(client) + assert root_item.child(0).childCount() > 0 + assert root_item.child(1).childCount() > 0 + assert root_item.child(2).childCount() > 0 diff --git a/superscore/tests/test_window.py b/superscore/tests/test_window.py index 2d6d75f..2d057d6 100644 --- a/superscore/tests/test_window.py +++ b/superscore/tests/test_window.py @@ -39,7 +39,9 @@ def get_last_index(index): first_index = window.tree_view.model().index(0, 0) last_index = get_last_index(first_index) + # expand does not fetch more data by itself window.tree_view.expand(last_index) + window.tree_view.model().fetchMore(last_index) assert count_visible_items(window.tree_view) == 7 diff --git a/superscore/widgets/views.py b/superscore/widgets/views.py index c6cabf7..e8a4332 100644 --- a/superscore/widgets/views.py +++ b/superscore/widgets/views.py @@ -82,7 +82,11 @@ def fill_uuids(self, client: Optional[Client] = None) -> None: if isinstance(self._data, Nestable): if any(isinstance(child, UUID) for child in self._data.children): client.fill(self._data, fill_depth=2) - # re-construct child nodes + + # re-construct child EntryItems if there is a mismatch or if any + # hold UUIDs as _data + if (any(isinstance(e._data, UUID) for e in self._children) + or len(self._data.children) != self.childCount()): self.takeChildren() for child in self._data.children: logger.debug(f'adding filled child: {type(child)}({child.uuid})') @@ -224,10 +228,13 @@ def icon(self): return qta.icon(icon_id) -def build_tree(entry: Entry, parent: Optional[EntryItem] = None) -> EntryItem: +def build_tree( + entry: Union[Entry, Root, UUID], + parent: Optional[EntryItem] = None +) -> EntryItem: """ Walk down the ``entry`` tree and create an `EntryItem` for each, linking - them to their parents + them to their parents. Parameters ---------- @@ -242,6 +249,9 @@ def build_tree(entry: Entry, parent: Optional[EntryItem] = None) -> EntryItem: EntryItem the constructed `EntryItem` with parent-child linkages """ + # Note the base case here is when ``entry`` is a UUID, in which an EntryItem + # is made and recursion stops. These children need to be present to let the + # view know that there are children in the item (that will later be filled) item = EntryItem(entry, tree_parent=parent) if isinstance(entry, Root):