コード例 #1
0
    def test_recursiveCheck(self):
        self.populateTree()
        rootnode = self.session.query(GenericSystemTreeNode).filter_by(
            parent_id=None).one()
        model = GenericTreeModel(rootnode, treenode=GenericSystemTreeNode)
        self.logger.info('setting parent index')
        parent_index = model.index(0, 0, QtCore.QModelIndex())
        self.logger.info('setting parent checked')
        model.setData(parent_index, QtCore.Qt.Checked,
                      QtCore.Qt.CheckStateRole)
        state = model.data(parent_index, QtCore.Qt.CheckStateRole)
        self.logger.info('Validating that state is checked')
        self.assertTrue(state)

        self.logger.info('Validating that all children are checked')
        for childnr in range(model.rowCount(parent_index)):
            subindex = model.index(childnr, 0, parent_index)
            state = model.data(subindex, QtCore.Qt.CheckStateRole)
            self.assertTrue(state)

        self.logger.info('testing unchecking')
        model.setData(parent_index, QtCore.Qt.Unchecked,
                      QtCore.Qt.CheckStateRole)
        state = model.data(parent_index, QtCore.Qt.CheckStateRole)
        self.logger.info('Validating that state is unchecked')
        self.assertFalse(state)

        self.logger.info('Validating that all children are unchecked')
        for childnr in range(model.rowCount(parent_index)):
            subindex = model.index(childnr, 0, parent_index)
            state = model.data(subindex, QtCore.Qt.CheckStateRole)
            self.assertFalse(state)
コード例 #2
0
    def test_filterAcceptsRow(self):
        populateChecksTree(self.session)
        rootnode = self.session.query(Check).filter_by(parent_id=None).first()
        model = GenericTreeModel(rootnode, treenode=Check)

        filter_model=PolyMorphicFilterProxyModel(filterClasses=self.filter)
        filter_model.setSourceModel(model)

        rootindex=QtCore.QModelIndex()
        self.assertEqual(model.rowCount(rootindex), 2)
        self.assertEqual(filter_model.rowCount(rootindex), 2)
        index=model.index(1, 0, rootindex)  #Folder "Basis"
        self.assertEqual(model.rowCount(index), 1)
        self.assertEqual(model.data(index, QtCore.Qt.DisplayRole), 'Basis')
        self.assertEqual(model.rowCount(index), 1)
        index=model.index(0, 0, index)
        self.assertEqual(model.data(index, QtCore.Qt.DisplayRole), 'Post Install')
        self.assertEqual(model.rowCount(index), 1)
        index=model.index(0, 0, index)
        self.assertEqual(model.data(index, QtCore.Qt.DisplayRole), 'Clients 001 and 066 removed')

        filter_index=filter_model.index(1, 0, rootindex)
        self.assertEqual(filter_model.data(filter_index, QtCore.Qt.DisplayRole), 'Basis')
        filter_index=filter_model.index(0, 0, filter_index)
        self.assertEqual(filter_model.data(filter_index, QtCore.Qt.DisplayRole), 'Post Install')
        self.assertEqual(filter_model.rowCount(filter_index), 0)
コード例 #3
0
    def test_getNode(self):
        self.populateTree()
        rootnode = self.session.query(Check).filter_by(parent_id=None).first()
        model = GenericTreeModel(rootnode, treenode=Check)

        index = model.index(0, 0, QtCore.QModelIndex())
        node = model.getNode(index)

        self.assertEqual(node.name, 'Authorization')

        index = model.index(99, 2, QtCore.QModelIndex())
        node = model.getNode(index)

        self.assertEqual(node.name, 'RootNode')
コード例 #4
0
    def test_getNode(self):
        self.populateTree()
        rootnode = self.session.query(GenericSystemTreeNode).filter_by(
            parent_id=None).one()
        model = GenericTreeModel(rootnode, treenode=GenericSystemTreeNode)

        index = model.index(0, 0, QtCore.QModelIndex())
        node = model.getNode(index)

        self.assertEqual(node.name, 'DEV')

        index = model.index(99, 2, QtCore.QModelIndex())
        node = model.getNode(index)

        self.assertEqual(node.name, 'RootNode')
コード例 #5
0
    def test_insertRow(self):
        rootnode = self.session.query(GenericSystemTreeNode).filter_by(
            parent_id=None).one()
        model = GenericTreeModel(rootnode)
        index = model.createIndex(0, 0, rootnode)
        child_count_root = model.rowCount(index)
        self.assertEqual(child_count_root, 0)
        system_node = SystemAbap(name='New SID', sid='NEW')
        model.insertRow(0, index, nodeObject=system_node)
        child_count_root = model.rowCount(index)
        self.assertEqual(child_count_root,
                         1)  #Successfully added one new system
        self.assertTrue(model.hasChildren(index))  #Another test

        #Testing Inserting a new client
        system_index = model.index(0, 0, index)
        child_count_system = model.rowCount(system_index)
        self.assertEqual(child_count_system, 0)  #No new client exists
        self.assertFalse(model.hasChildren(system_index))  #Another test

        client_node = SystemAbapClient(client='000')
        model.insertRow(position=0,
                        parent=system_index,
                        nodeObject=client_node)
        child_count_system = model.rowCount(system_index)
        self.assertEqual(child_count_system,
                         1)  #Successfully added one new system
        self.assertTrue(model.hasChildren(system_index))  #Another test
コード例 #6
0
    def test_parent(self):
        self.populateTree()
        rootnode = self.session.query(GenericSystemTreeNode).filter_by(
            parent_id=None).one()
        model = GenericTreeModel(rootnode, treenode=GenericSystemTreeNode)

        node1index = model.index(0, 0, QtCore.QModelIndex())
        node2index = model.index(0, 0, node1index)

        self.assertEqual(model.data(node1index, QtCore.Qt.DisplayRole), 'DEV')
        self.assertEqual(model.data(node2index, QtCore.Qt.DisplayRole), 'E1D')

        data_node1 = model.data(node1index, QtCore.Qt.DisplayRole)

        node1_node = node1index.internalPointer()
        self.assertEqual(node1_node.name, 'DEV')
        node2_node = node2index.internalPointer()
        self.assertEqual(node2_node.name, 'E1D')
        node2_parent_index = model.parent(node2index)
        node2_parent_node = node2_parent_index.internalPointer()
        self.assertEqual(node2_parent_node.name, 'DEV')
コード例 #7
0
    def test_parent(self):
        self.populateTree()
        rootnode = self.session.query(Check).filter_by(parent_id=None).first()
        model = GenericTreeModel(rootnode, treenode=Check)

        node1index = model.index(1, 0, QtCore.QModelIndex())
        node2index = model.index(0, 0, node1index)

        self.assertEqual(model.data(node1index, QtCore.Qt.DisplayRole),
                         'Basis')
        self.assertEqual(model.data(node2index, QtCore.Qt.DisplayRole),
                         'Post Install')

        data_node1 = model.data(node1index, QtCore.Qt.DisplayRole)

        node1_node = node1index.internalPointer()
        self.assertEqual(node1_node.name, 'Basis')
        node2_node = node2index.internalPointer()
        self.assertEqual(node2_node.name, 'Post Install')
        node2_parent_index = model.parent(node2index)
        node2_parent_node = node2_parent_index.internalPointer()
        self.assertEqual(node2_parent_node.name, 'Basis')
コード例 #8
0
class TestSettingsModel(TestCase):
    def setUp(self):
        self.PATH = r'TestSettingsModel.sqlite'
        self.logger = logging.getLogger('{}.{}'.format(
            __name__, self.__class__.__name__))

        self.dbconfig = {
            'sqlalchemy.echo': False,
            'sqlalchemy.url': 'sqlite:///' + self.PATH
        }

        if os.path.exists(self.PATH):
            os.remove(self.PATH)

        self.engine = engine_from_config(self.dbconfig)
        systemcheck.models.meta.base.Base.metadata.create_all(self.engine)
        self.session_factory = sessionmaker(bind=self.engine)
        self.session = scoped_session(self.session_factory)

        if self.session.query(GenericSystemTreeNode).filter(
                GenericSystemTreeNode.parent_id == None).count() == 0:
            self.session.add(GenericSystemTreeNode(name='RootNode'))
            self.session.commit()

        self.populate_tree()
        rootnode = self.session.query(GenericSystemTreeNode).filter(
            GenericSystemTreeNode.parent_id == None).one()
        self.model = GenericTreeModel(rootnode=rootnode,
                                      treenode=GenericSystemTreeNode)

    def tearDown(self):

        self.session.close()
        if os.path.exists(self.PATH):
            os.remove(self.PATH)

    def populate_tree(self):
        systemcheck_tools.populateSystemsABAPTree(self.session)

    def test_columnCount(self):
        dev_index = self.model.index(0, 0, QtCore.QModelIndex())
        system_index = self.model.index(0, 0, dev_index)
        system_tree_node = system_index.internalPointer()
        self.assertEqual(system_tree_node.sid, 'E1D')

        settings_model = SettingsModel(system_tree_node)
        column_count = settings_model.columnCount()
        self.assertEqual(column_count, 16)
        self.assertEqual(column_count, system_tree_node._qt_column_count())

    def test_data(self):
        dev_index = self.model.index(0, 0, QtCore.QModelIndex())
        system_index = self.model.index(0, 0, dev_index)
        system_tree_node = system_index.internalPointer()
        self.assertEqual(system_tree_node.sid, 'E1D')

        settings_model = SettingsModel(system_tree_node)
        for colnr, column in enumerate(system_tree_node.__qtmap__):
            index = settings_model.index(0, colnr, QtCore.QModelIndex())
            self.assertEqual(settings_model.data(index, QtCore.Qt.DisplayRole),
                             getattr(system_tree_node, column.name))