1
0
mirror of https://github.com/altlinux/admc.git synced 2025-03-12 12:58:20 +03:00

add attribute tests

for loading and filtering
fix filter dialog not getting deleted
fix read only checkbox not disabling subfilters on dialog open
This commit is contained in:
Dmitry Degtyarev 2021-06-11 16:09:08 +04:00
parent 7048f9da03
commit dfaf42f85e
5 changed files with 228 additions and 7 deletions

View File

@ -79,6 +79,7 @@ cd BUILD
%_bindir/admc_test_select_base_widget
%_bindir/admc_test_filter_widget
%_bindir/admc_test_security_tab
%_bindir/admc_test_attributes_tab
%changelog
* Wed May 12 2021 Dmitry Degtyarev <kevl@altlinux.org> 0.5.2-alt1

View File

@ -36,6 +36,7 @@
#include <QFrame>
#include <QLabel>
#include <QHeaderView>
#include <QDebug>
enum AttributesColumn {
AttributesColumn_Name,
@ -69,6 +70,7 @@ AttributesTab::AttributesTab() {
auto edit_button = new QPushButton(tr("Edit"));
auto filter_button = new QPushButton(tr("Filter"));
filter_button->setObjectName("filter_button");
auto buttons = new QHBoxLayout();
buttons->addWidget(edit_button);
buttons->addStretch(1);
@ -138,6 +140,7 @@ void AttributesTab::edit_attribute() {
void AttributesTab::open_filter_dialog() {
auto dialog = new QDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
auto layout = new QVBoxLayout();
dialog->setLayout(layout);
@ -159,6 +162,7 @@ void AttributesTab::open_filter_dialog() {
auto check = new QCheckBox(text);
const bool is_checked = proxy->filters[filter];
check->setChecked(is_checked);
check->setObjectName(QString::number(filter));
checks.insert(filter, check);
};
@ -172,15 +176,17 @@ void AttributesTab::open_filter_dialog() {
add_check(tr("Backlink"), AttributeFilter_Backlink);
// Enable readonly subtype checks when readonly is enabled
connect(
checks[AttributeFilter_ReadOnly], &QCheckBox::stateChanged,
[checks]() {
auto on_read_only_check = [checks]() {
const bool read_only_enabled = checks[AttributeFilter_ReadOnly]->isChecked();
checks[AttributeFilter_SystemOnly]->setEnabled(read_only_enabled);
checks[AttributeFilter_Constructed]->setEnabled(read_only_enabled);
checks[AttributeFilter_Backlink]->setEnabled(read_only_enabled);
});
};
connect(
checks[AttributeFilter_ReadOnly], &QCheckBox::stateChanged,
on_read_only_check);
on_read_only_check();
auto first_frame = make_frame();
first_frame->layout()->addWidget(checks[AttributeFilter_Unset]);

View File

@ -42,6 +42,7 @@ set(TEST_TARGETS
admc_test_select_base_widget
admc_test_filter_widget
admc_test_security_tab
admc_test_attributes_tab
)
foreach(target ${TEST_TARGETS})

View File

@ -0,0 +1,162 @@
/*
* ADMC - AD Management Center
*
* Copyright (C) 2020-2021 BaseALT Ltd.
* Copyright (C) 2020-2021 Dmitry Degtyarev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "admc_test_attributes_tab.h"
#include <QVBoxLayout>
#include <QString>
#include <QStandardItemModel>
#include <QPushButton>
#include <QDialog>
#include <QCheckBox>
// NOTE: can't be set because order is important. Read only
// has to be set first to enable other filters.
const QList<AttributeFilter> all_filters = []() {
QList<AttributeFilter> out;
for (int i = 0; i < AttributeFilter_COUNT; i++) {
out.append((AttributeFilter) i);
}
return out;
}();
void ADMCTestAttributesTab::init() {
ADMCTest::init();
attributes_tab = new AttributesTab();
parent_widget->show();
QVERIFY(QTest::qWaitForWindowExposed(parent_widget, 1000));
auto layout = new QVBoxLayout();
parent_widget->setLayout(layout);
layout->addWidget(attributes_tab);
model = attributes_tab->findChild<QStandardItemModel *>();
QVERIFY(model != nullptr);
proxy = attributes_tab->findChild<QSortFilterProxyModel *>();
QVERIFY(proxy != nullptr);
filter_button = attributes_tab->findChild<QPushButton *>("filter_button");
QVERIFY(filter_button != nullptr);
// Create test user
const QString name = TEST_USER;
dn = test_object_dn(name, CLASS_USER);
const bool create_success = ad.object_add(dn, CLASS_USER);
QVERIFY(create_success);
// Load it into the tab
const AdObject object = ad.search_object(dn);
attributes_tab->load(ad, object);
}
void ADMCTestAttributesTab::load() {
// Check that some attributes loaded correctly
auto check_value = [&](const QString &name, const QString &value) {
const QList<QStandardItem *> item_list = model->findItems(name);
if (item_list.size() != 1) {
return false;
}
QStandardItem *name_item = item_list[0];
QStandardItem *value_item = model->item(name_item->row(), 1);
const QString &this_value = value_item->text();
const bool value_is_correct = (this_value == value);
return value_is_correct;
};
check_value("name", TEST_USER);
check_value("distinguishedName", dn);
}
// Test filters by checking that affected attributes are
// visible/hidden when their filters are checked/unchecked
void ADMCTestAttributesTab::filter() {
auto test_filter = [&](const AttributeFilter filter, const QString &attribute) {
auto check_filtering = [&](const bool should_be_visible) {
const QList<QStandardItem *> item_list = model->findItems(attribute);
QVERIFY2((item_list.size() == 1), qPrintable(QString("Failed to find attribute %1)").arg(attribute)));
QStandardItem *item = item_list[0];
const QModelIndex index = item->index();
const QModelIndex proxy_index = proxy->mapFromSource(index);
const bool is_visible = proxy_index.isValid();
const bool correct_filtering = (is_visible == should_be_visible);
QVERIFY2(correct_filtering, qPrintable(QString("filter = %1, attribute = %2, is_visible = %3, should_be_visible = %4").arg(filter).arg(attribute).arg(is_visible).arg(should_be_visible)));
};
set_filter({filter}, Qt::Checked);
check_filtering(true);
set_filter({filter}, Qt::Unchecked);
check_filtering(false);
set_filter({filter}, Qt::Checked);
};
set_filter(all_filters, Qt::Checked);
test_filter(AttributeFilter_Unset, ATTRIBUTE_HOME_PHONE);
test_filter(AttributeFilter_ReadOnly, ATTRIBUTE_OBJECT_GUID);
test_filter(AttributeFilter_SystemOnly, ATTRIBUTE_WHEN_CREATED);
test_filter(AttributeFilter_Constructed, "allowedAttributes");
test_filter(AttributeFilter_Backlink, ATTRIBUTE_MEMBER_OF);
test_filter(AttributeFilter_Mandatory, "instanceType");
test_filter(AttributeFilter_Optional, ATTRIBUTE_COUNTRY_CODE);
// NOTE: read only also needs to affect these read only
// attributes
test_filter(AttributeFilter_ReadOnly, "allowedAttributes");
test_filter(AttributeFilter_ReadOnly, ATTRIBUTE_WHEN_CREATED);
test_filter(AttributeFilter_ReadOnly, ATTRIBUTE_MEMBER_OF);
set_filter(all_filters, Qt::Checked);
}
void ADMCTestAttributesTab::set_filter(const QList<AttributeFilter> &filter_list, const Qt::CheckState state) {
filter_button->click();
auto filter_dialog = attributes_tab->findChild<QDialog *>();
QVERIFY(filter_dialog != nullptr);
QVERIFY(QTest::qWaitForWindowExposed(filter_dialog, 1000));
for (const AttributeFilter &filter : filter_list) {
QCheckBox *checkbox = filter_dialog->findChild<QCheckBox *>(QString::number(filter));
QVERIFY(checkbox != nullptr);
checkbox->setCheckState(state);
}
filter_dialog->accept();
// NOTE: manually delete because normally it's deleted
// lazily which is a problem when we need to open this
// dialog multiple times
delete filter_dialog;
QVERIFY(QTest::qWaitForWindowExposed(attributes_tab, 1000));
}
QTEST_MAIN(ADMCTestAttributesTab)

View File

@ -0,0 +1,51 @@
/*
* ADMC - AD Management Center
*
* Copyright (C) 2020-2021 BaseALT Ltd.
* Copyright (C) 2020-2021 Dmitry Degtyarev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ADMC_TEST_ATTRIBUTES_TAB_H
#define ADMC_TEST_ATTRIBUTES_TAB_H
#include "admc_test.h"
#include "tabs/attributes_tab.h"
class QStandardItemModel;
class QSortFilterProxyModel;
class QPushButton;
class ADMCTestAttributesTab : public ADMCTest {
Q_OBJECT
private slots:
void init() override;
void load();
void filter();
private:
AttributesTab *attributes_tab;
QStandardItemModel *model;
QSortFilterProxyModel *proxy;
QPushButton *filter_button;
QString dn;
void set_filter(const QList<AttributeFilter> &filter_list, const Qt::CheckState state);
};
#endif /* ADMC_TEST_ATTRIBUTES_TAB_H */