def test_flags(good_node_states, good_device_states, good_truth_tables):
    table_model = DeviceStateTableModel()

    for i, good_states in enumerate(good_node_states):
        table_model.setNodeStates(good_states)
        table_model.setDeviceStates(good_device_states[i])

        #No editing of the truth table section
        flags = (QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
        for i, row in enumerate(good_truth_tables[i]):
            for j, val in enumerate(row):
                assert table_model.flags(
                    table_model.index(i, j, QtCore.QModelIndex())) == flags

        #Always allow editing of status, icon_layer, is_warning, is_alarm, triggers_action, log_entrance
        flags = (QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
                 | QtCore.Qt.ItemIsEditable)
        assert table_model.flags(
            table_model.index(0, table_model.statusColumn(),
                              QtCore.QModelIndex())) == flags
        assert table_model.flags(
            table_model.index(0, table_model.iconLayerColumn(),
                              QtCore.QModelIndex())) == flags
        assert table_model.flags(
            table_model.index(0, table_model.isWarningColumn(),
                              QtCore.QModelIndex())) == flags
        assert table_model.flags(
            table_model.index(0, table_model.isAlarmColumn(),
                              QtCore.QModelIndex())) == flags
        assert table_model.flags(
            table_model.index(0, table_model.triggersActionColumn(),
                              QtCore.QModelIndex())) == flags
        assert table_model.flags(
            table_model.index(0, table_model.logEntranceColumn(),
                              QtCore.QModelIndex())) == flags
def test_headerData(good_node_states, good_device_states):
    table_model = DeviceStateTableModel()

    for i, good_states in enumerate(good_node_states):
        table_model.setNodeStates(good_states)
        table_model.setDeviceStates(good_device_states[i])

        #check vertical header
        for row in range(table_model.rowCount()):
            assert str(row) == table_model.headerData(row, QtCore.Qt.Vertical,
                                                      QtCore.Qt.DisplayRole)

        #Check horizontal headers
        headers = [row[0] for row in good_states]
        headers = headers[::-1]

        for i, val in enumerate(headers):
            assert val == table_model.headerData(i, QtCore.Qt.Horizontal,
                                                 QtCore.Qt.DisplayRole)

        assert 'Status' == table_model.headerData(table_model.statusColumn(),
                                                  QtCore.Qt.Horizontal,
                                                  QtCore.Qt.DisplayRole)
        assert 'Icon Layer\nName' == table_model.headerData(
            table_model.iconLayerColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)
        assert 'Is Warning' == table_model.headerData(
            table_model.isWarningColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)
        assert 'Warning\nTimeout (sec)' == table_model.headerData(
            table_model.warningTimeoutColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)
        assert 'Warning Message' == table_model.headerData(
            table_model.warningMessageColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)
        assert 'Is Alarm' == table_model.headerData(
            table_model.isAlarmColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)
        assert 'Alarm\nTimeout (sec)' == table_model.headerData(
            table_model.alarmTimeoutColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)
        assert 'Alarm Message' == table_model.headerData(
            table_model.alarmMessageColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)
        assert 'Triggers\nAction' == table_model.headerData(
            table_model.triggersActionColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)
        assert 'Action\nTimeout (sec)' == table_model.headerData(
            table_model.actionTimeoutColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)
        assert 'Action' == table_model.headerData(table_model.actionColumn(),
                                                  QtCore.Qt.Horizontal,
                                                  QtCore.Qt.DisplayRole)
        assert 'Log Entrance' == table_model.headerData(
            table_model.logEntranceColumn(), QtCore.Qt.Horizontal,
            QtCore.Qt.DisplayRole)