1
0
mirror of https://github.com/altlinux/admc.git synced 2025-01-09 17:18:15 +03:00
admc/tests/admc_test_members_tab.cpp

124 lines
3.8 KiB
C++
Raw Normal View History

2021-06-25 14:32:23 +03:00
/*
* ADMC - AD Management Center
*
2022-04-06 14:59:32 +03:00
* Copyright (C) 2020-2022 BaseALT Ltd.
* Copyright (C) 2020-2022 Dmitry Degtyarev
2021-06-25 14:32:23 +03:00
*
* 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_members_tab.h"
#include "select_dialogs/select_object_dialog.h"
2021-06-25 14:32:23 +03:00
#include "tabs/membership_tab.h"
#include "tabs/ui_membership_tab.h"
2021-06-25 14:32:23 +03:00
#include <QPushButton>
2021-06-30 13:24:51 +03:00
#include <QStandardItemModel>
2021-06-25 14:32:23 +03:00
#include <QTreeView>
2021-06-30 13:24:51 +03:00
#include <QVBoxLayout>
2021-06-25 14:32:23 +03:00
void ADMCTestMembersTab::init() {
ADMCTest::init();
2021-12-22 15:26:03 +03:00
view = new QTreeView(parent_widget);
auto primary_button = new QPushButton(parent_widget);
add_button = new QPushButton(parent_widget);
remove_button = new QPushButton(parent_widget);
auto properties_button = new QPushButton(parent_widget);
auto primary_group_label = new QLabel(parent_widget);
2021-06-25 14:32:23 +03:00
2021-12-22 15:26:03 +03:00
edit = new MembershipTabEdit(view, primary_button, add_button, remove_button, properties_button, primary_group_label, MembershipTabType_Members, parent_widget);
model = edit->findChild<QStandardItemModel *>();
QVERIFY(model);
2021-06-25 14:32:23 +03:00
// Create test user
const QString user_name = TEST_USER;
user_dn = test_object_dn(user_name, CLASS_USER);
const bool create_user_success = ad.object_add(user_dn, CLASS_USER);
QVERIFY(create_user_success);
// Create test group
const QString group_name = TEST_GROUP;
group_dn = test_object_dn(group_name, CLASS_GROUP);
const bool create_group_success = ad.object_add(group_dn, CLASS_GROUP);
QVERIFY(create_group_success);
// Load it into the tab
const AdObject object = ad.search_object(group_dn);
2021-12-22 15:26:03 +03:00
edit->load(ad, object);
2021-06-25 14:32:23 +03:00
}
// Loading a group without members should result in empty
// model
void ADMCTestMembersTab::load_empty() {
QCOMPARE(model->rowCount(), 0);
2021-06-25 14:32:23 +03:00
}
// Loading a group with members should put members in the
// model
void ADMCTestMembersTab::load() {
const bool add_success = ad.group_add_member(group_dn, user_dn);
QVERIFY(add_success);
const AdObject object = ad.search_object(group_dn);
2021-12-22 15:26:03 +03:00
edit->load(ad, object);
2021-06-25 14:32:23 +03:00
QCOMPARE(model->rowCount(), 1);
2021-06-25 14:32:23 +03:00
auto item = model->item(0, 0);
QCOMPARE(item->text(), dn_get_name(user_dn));
2021-06-25 14:32:23 +03:00
}
// Removing members should remove members from model and group
void ADMCTestMembersTab::remove() {
load();
const QModelIndex index = model->index(0, 0);
view->setCurrentIndex(index);
remove_button->click();
2021-12-22 15:26:03 +03:00
edit->apply(ad, group_dn);
2021-06-25 14:32:23 +03:00
const AdObject updated_object = ad.search_object(group_dn);
const QList<QString> member_list = updated_object.get_strings(ATTRIBUTE_MEMBER);
QCOMPARE(model->rowCount(), 0);
2021-06-25 14:32:23 +03:00
QVERIFY(member_list.isEmpty());
}
void ADMCTestMembersTab::add() {
add_button->click();
2021-06-30 12:58:28 +03:00
select_object_dialog_select(user_dn);
2021-06-25 14:32:23 +03:00
// Check ui state before applying
QCOMPARE(model->rowCount(), 1);
QCOMPARE(model->item(0, 0)->text(), dn_get_name(user_dn));
2021-06-25 14:32:23 +03:00
// Apply and check object state
2021-12-22 15:26:03 +03:00
edit->apply(ad, group_dn);
2021-06-25 14:32:23 +03:00
const AdObject object = ad.search_object(group_dn);
const QList<QString> member_list = object.get_strings(ATTRIBUTE_MEMBER);
QCOMPARE(member_list, QList<QString>({user_dn}));
2021-06-25 14:32:23 +03:00
// Check ui state after applying (just in case)
QCOMPARE(model->rowCount(), 1);
QCOMPARE(model->item(0, 0)->text(), dn_get_name(user_dn));
2021-06-25 14:32:23 +03:00
}
QTEST_MAIN(ADMCTestMembersTab)