|
13 | 13 | """Unit tests for DB editor's custom ``QTreeView`` classes.""" |
14 | 14 |
|
15 | 15 | from unittest import mock |
16 | | -from PySide6.QtCore import QItemSelection, QItemSelectionModel, Qt |
| 16 | +from PySide6.QtCore import QItemSelection, QItemSelectionModel, QModelIndex, Qt |
17 | 17 | from PySide6.QtWidgets import QApplication |
18 | 18 | import pytest |
19 | 19 | from spinedb_api import ( |
@@ -734,6 +734,44 @@ def test_removing_element_removes_corresponding_entity(self, entity_tree_model, |
734 | 734 | assert len(data) == 4 |
735 | 735 | assert {i.name for i in data} == {"object_11", "object_12", "object_22", "object_11__object_22"} |
736 | 736 |
|
| 737 | + def test_duplicate_element(self, entity_tree_model, db_mngr, db_map, db_editor): |
| 738 | + o11_id = db_map.entity(entity_class_name="object_class_1", name="object_11")["id"] |
| 739 | + r1_id = db_map.entity(entity_class_name="relationship_class", entity_byname=("object_11", "object_21"))["id"] |
| 740 | + assert db_mngr.relationship_graph.is_any_id_reachable(db_map, r1_id, {o11_id}) |
| 741 | + view = db_editor.ui.treeView_entity |
| 742 | + model = entity_tree_model |
| 743 | + root_index = model.index(0, 0) |
| 744 | + model.fetchMore(root_index) |
| 745 | + while model.rowCount(root_index) != 3: |
| 746 | + QApplication.processEvents() |
| 747 | + class_index = model.index(0, 0, root_index) |
| 748 | + assert class_index.data() == "object_class_1" |
| 749 | + model.fetchMore(class_index) |
| 750 | + while model.rowCount(class_index) != 2: |
| 751 | + QApplication.processEvents() |
| 752 | + object_index = model.index(0, 0, class_index) |
| 753 | + assert object_index.data() == "object_11" |
| 754 | + view.selectionModel().setCurrentIndex(object_index, QItemSelectionModel.SelectionFlag.ClearAndSelect) |
| 755 | + view._context_item = model.item_from_index(object_index) |
| 756 | + view.duplicate_entity() |
| 757 | + QApplication.processEvents() |
| 758 | + root_index = model.index(0, 0) |
| 759 | + model.fetchMore(root_index) |
| 760 | + while model.rowCount(root_index) != 3: |
| 761 | + QApplication.processEvents() |
| 762 | + class_index = model.index(0, 0, root_index) |
| 763 | + assert class_index.data() == "object_class_1" |
| 764 | + model.fetchMore(class_index) |
| 765 | + while model.rowCount(class_index) != 3: |
| 766 | + QApplication.processEvents() |
| 767 | + object_index = model.index(1, 0, class_index) |
| 768 | + assert object_index.data() == "object_11 (1)" |
| 769 | + model.fetchMore(object_index) |
| 770 | + while model.rowCount(object_index) != 2: |
| 771 | + QApplication.processEvents() |
| 772 | + assert model.index(0, 0, object_index).data() == "٭ ǀ object_21" |
| 773 | + assert model.index(1, 0, object_index).data() == "٭ ǀ object_22" |
| 774 | + |
737 | 775 | @staticmethod |
738 | 776 | def _rename_class(class_name, db_editor): |
739 | 777 | view = db_editor.ui.treeView_entity |
|
0 commit comments