Exemplo n.º 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)
Exemplo n.º 2
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
    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)
Exemplo n.º 4
0
    def test_removeRow(self):
        rootnode = self.session.query(Check).filter_by(parent_id=None).first()
        model = GenericTreeModel(rootnode, treenode=Check)
        index = model.createIndex(0, 0, rootnode)
        check = CheckAbapCountTableEntries(
            name='Clients 001 and 066 removed',
            description=
            'If client 001 is not actively used, it can be deleted. Client 066 is no longer required in any case',
        )

        param001 = CheckAbapCountTableEntries__params(
            table_name='T000',
            table_fields='MANDT',
            expected_count=0,
            operator='NE',
            where_clause="MANDT EQ '001'")
        param066 = CheckAbapCountTableEntries__params(
            table_name='T000',
            table_fields='MANDT',
            expected_count=0,
            operator='NE',
            where_clause="MANDT EQ '066'")
        check.params.append(param001)

        model.insertRow(0, index, nodeObject=check)
        self.assertEqual(model.rowCount(index), 1)
        model.removeRow(0, index)
        self.assertEqual(model.rowCount(index), 0)
Exemplo n.º 5
0
 def test_removeRows(self):
     rootnode = self.session.query(Check).filter_by(parent_id=None).first()
     model = GenericTreeModel(rootnode, treenode=Check)
     index = model.createIndex(0, 0, rootnode)
     model.insertRows(0, 10, index)
     self.assertEqual(model.rowCount(index), 10)
     model.removeRows(1, 5, index)
     self.assertEqual(model.rowCount(index), 5)
Exemplo n.º 6
0
 def test_removeRow(self):
     rootnode = self.session.query(GenericSystemTreeNode).filter_by(
         parent_id=None).one()
     model = GenericTreeModel(rootnode, treenode=GenericSystemTreeNode)
     index = model.createIndex(0, 0, rootnode)
     model.insertRow(0, index)
     self.assertEqual(model.rowCount(index), 1)
     model.removeRow(0, index)
     self.assertEqual(model.rowCount(index), 0)
Exemplo n.º 7
0
    def test_rowCount(self):
        self.populateTree()
        rootnode = self.session.query(Check).filter_by(parent_id=None).first()
        model = GenericTreeModel(rootnode, treenode=Check)
        rootindex = model.createIndex(0, 0, rootnode)

        self.assertEqual(model.rowCount(rootindex), 2)
Exemplo n.º 8
0
    def test_rowCount(self):
        self.populateTree()
        rootnode = self.session.query(GenericSystemTreeNode).filter_by(
            parent_id=None).one()
        model = GenericTreeModel(rootnode)
        rootindex = model.createIndex(0, 0, rootnode)

        self.assertEqual(model.rowCount(rootindex), 4)
    def test_insertRow(self):
        rootnode = get_or_create(self.session, Check, parent_id=None, name='RootNode')
        model = GenericTreeModel(rootnode, treenode=Check)
        proxymodel = PolyMorphicFilterProxyModel()
        proxymodel.setSourceModel(model)

        index = QtCore.QModelIndex()

        check=CheckAbapCountTableEntries(name = 'Clients 001 and 066 removed',
                                         description = 'If client 001 is not actively used, it can be deleted. Client 066 is no longer required in any case',
                                         )


        param001 = CheckAbapCountTableEntries__params(
                                         table_name = 'T000',
                                         table_fields = 'MANDT',
                                         expected_count = 0,
                                         operator = 'NE',
                                         where_clause = "MANDT EQ '001'"
                                         )
        param066 = CheckAbapCountTableEntries__params(
                                         table_name = 'T000',
                                         table_fields = 'MANDT',
                                         expected_count = 0,
                                         operator = 'NE',
                                         where_clause = "MANDT EQ '066'"
                                         )
        check.params.append(param001)
        check.params.append(param066)

        print('\nroot node: ')
        print(rootnode._dump())
        print('\ncheck node: ')
        print(check._dump())

        proxymodel.insertRow(position=0, parent=QtCore.QModelIndex(), nodeObject=check)

        print('\nroot node after insertRow: ')
        print(rootnode._dump())

        #proxymodel=PolyMorphicFilterProxyModel()
        #proxymodel.setSourceModel(model)
        proxyRowcount=proxymodel.rowCount(QtCore.QModelIndex())

        sourceRowcount=model.rowCount(QtCore.QModelIndex())

        for count in range(proxyRowcount):
            index = proxymodel.index(count, 0, QtCore.QModelIndex())
            sourceIndex = proxymodel.mapToSource(index)
            node = model.getNode(sourceIndex)
            print('Node {}'.format(count))
            print(node._dump())


#        self.assertTrue(proxymodel.hasChildren(index))  #Another test
        self.assertEqual(proxyRowcount, sourceRowcount)