mirror of
https://github.com/altlinux/admc.git
synced 2024-10-27 01:55:37 +03:00
add tests for policy results widget
add alternate update() f-n for test
This commit is contained in:
parent
213cf77295
commit
7b9d9d12ab
@ -128,6 +128,12 @@ void PolicyResultsWidget::update(const QModelIndex &index) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString new_gpo = index.data(PolicyRole_DN).toString();
|
||||
|
||||
update(new_gpo);
|
||||
}
|
||||
|
||||
void PolicyResultsWidget::update(const QString &new_gpo) {
|
||||
AdInterface ad;
|
||||
if (ad_failed(ad)) {
|
||||
return;
|
||||
@ -135,7 +141,7 @@ void PolicyResultsWidget::update(const QModelIndex &index) {
|
||||
|
||||
model->removeRows(0, model->rowCount());
|
||||
|
||||
gpo = index.data(PolicyRole_DN).toString();
|
||||
gpo = new_gpo;
|
||||
|
||||
const QString base = g_adconfig->domain_head();
|
||||
const SearchScope scope = SearchScope_All;
|
||||
|
@ -42,6 +42,8 @@ public:
|
||||
// Loads links for this policy. Nothing is done if given
|
||||
// index is not a policy.
|
||||
void update(const QModelIndex &index);
|
||||
|
||||
void update(const QString &gpo);
|
||||
|
||||
ResultsView *get_view() const;
|
||||
|
||||
|
@ -65,6 +65,7 @@ set(TEST_TARGETS
|
||||
admc_test_string_editor
|
||||
admc_test_multi_editor
|
||||
admc_test_edit_query_item_widget
|
||||
admc_test_policy_results_widget
|
||||
)
|
||||
|
||||
foreach(target ${TEST_TARGETS})
|
||||
|
@ -54,11 +54,11 @@ public slots:
|
||||
// Called before first test
|
||||
virtual void initTestCase();
|
||||
// Called after last test
|
||||
void cleanupTestCase();
|
||||
virtual void cleanupTestCase();
|
||||
|
||||
// Called before and after each test
|
||||
virtual void init();
|
||||
void cleanup();
|
||||
virtual void cleanup();
|
||||
|
||||
protected:
|
||||
AdInterface ad;
|
||||
|
112
tests/admc_test_policy_results_widget.cpp
Normal file
112
tests/admc_test_policy_results_widget.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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_policy_results_widget.h"
|
||||
|
||||
#include "policy_results_widget.h"
|
||||
#include "console_widget/results_view.h"
|
||||
#include "ad_filter.h"
|
||||
#include "gplink.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <QTreeView>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
// NOTE: unlike other tests, here we have to create the test
|
||||
// thing (gpo) once and reuse between tests because creating
|
||||
// and deleting gpo's takes too much time. If we did that
|
||||
// for every test they would take forever.
|
||||
|
||||
// TODO: test modify operations
|
||||
|
||||
const QString gpo_name = "test_policy_for_admc_test_results_widget";
|
||||
|
||||
void ADMCTestPolicyResultsWidget::initTestCase() {
|
||||
ADMCTest::initTestCase();
|
||||
|
||||
const bool create_gpo_success = ad.create_gpo(gpo_name, gpo);
|
||||
QVERIFY(create_gpo_success);
|
||||
}
|
||||
|
||||
void ADMCTestPolicyResultsWidget::cleanupTestCase() {
|
||||
ADMCTest::cleanupTestCase();
|
||||
|
||||
// Delete old test-policy, if needed
|
||||
const QString base = ad.adconfig()->domain_head();
|
||||
const QString filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_DISPLAY_NAME, gpo_name);
|
||||
const QList<QString> attributes = QList<QString>();
|
||||
const QHash<QString, AdObject> search_results = ad.search(base, SearchScope_All, filter, attributes);
|
||||
|
||||
for (const QString &dn : search_results.keys()) {
|
||||
ad.delete_gpo(dn);
|
||||
}
|
||||
}
|
||||
|
||||
void ADMCTestPolicyResultsWidget::init() {
|
||||
ADMCTest::init();
|
||||
|
||||
widget = new PolicyResultsWidget();
|
||||
add_widget(widget);
|
||||
|
||||
ResultsView *results_view = widget->get_view();
|
||||
view = results_view->detail_view();
|
||||
|
||||
model = widget->findChild<QStandardItemModel *>();
|
||||
QVERIFY(model != nullptr);
|
||||
}
|
||||
|
||||
void ADMCTestPolicyResultsWidget::load_empty() {
|
||||
widget->update(gpo);
|
||||
|
||||
QCOMPARE(view->model()->rowCount(), 0);
|
||||
}
|
||||
|
||||
void ADMCTestPolicyResultsWidget::load() {
|
||||
// Link gpo to ou
|
||||
const QString ou_dn = test_object_dn(TEST_OU, CLASS_OU);
|
||||
const bool create_ou_success = ad.object_add(ou_dn, CLASS_OU);
|
||||
QVERIFY(create_ou_success);
|
||||
const AdObject ou_object = ad.search_object(ou_dn);
|
||||
const QString gplink_string = ou_object.get_string(ATTRIBUTE_GPLINK);
|
||||
Gplink gplink = Gplink(gplink_string);
|
||||
gplink.add(gpo);
|
||||
gplink.set_option(gpo, GplinkOption_Enforced, true);
|
||||
ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, gplink.to_string());
|
||||
|
||||
widget->update(gpo);
|
||||
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
QCOMPARE(model->columnCount(), 4);
|
||||
|
||||
QList<QStandardItem *> item_list;
|
||||
for (int col = 0; col < 4; col++) {
|
||||
QStandardItem *item = model->item(0, col);
|
||||
QVERIFY(item != nullptr);
|
||||
item_list.append(item);
|
||||
}
|
||||
|
||||
QCOMPARE(item_list[0]->text(), TEST_OU);
|
||||
QCOMPARE(item_list[1]->checkState(), Qt::Checked);
|
||||
QCOMPARE(item_list[2]->checkState(), Qt::Unchecked);
|
||||
QCOMPARE(item_list[3]->text(), dn_get_parent_canonical(ou_dn));
|
||||
|
||||
}
|
||||
|
||||
QTEST_MAIN(ADMCTestPolicyResultsWidget)
|
49
tests/admc_test_policy_results_widget.h
Normal file
49
tests/admc_test_policy_results_widget.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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_POLICY_RESULTS_WIDGET_H
|
||||
#define ADMC_TEST_POLICY_RESULTS_WIDGET_H
|
||||
|
||||
#include "admc_test.h"
|
||||
|
||||
class PolicyResultsWidget;
|
||||
class QTreeView;
|
||||
class QStandardItemModel;
|
||||
|
||||
class ADMCTestPolicyResultsWidget : public ADMCTest {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase() override;
|
||||
void cleanupTestCase() override;
|
||||
|
||||
void init() override;
|
||||
|
||||
void load_empty();
|
||||
void load();
|
||||
|
||||
private:
|
||||
PolicyResultsWidget *widget;
|
||||
QTreeView *view;
|
||||
QStandardItemModel *model;
|
||||
QString gpo;
|
||||
};
|
||||
|
||||
#endif /* ADMC_TEST_POLICY_RESULTS_WIDGET_H */
|
Loading…
Reference in New Issue
Block a user