mirror of
https://github.com/altlinux/admc.git
synced 2025-01-08 01:18:25 +03:00
add country edit tests
This commit is contained in:
parent
04e828e0bf
commit
7a5a229ac9
@ -80,6 +80,7 @@ cd BUILD
|
||||
%_bindir/admc_test_unlock_edit
|
||||
%_bindir/admc_test_upn_edit
|
||||
%_bindir/admc_test_string_edit
|
||||
%_bindir/admc_test_country_edit
|
||||
%_bindir/admc_test_gplink
|
||||
%_bindir/admc_test_ad_interface
|
||||
|
||||
|
@ -23,12 +23,14 @@
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
#include "edits/country_edit.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QFormLayout>
|
||||
#include <QComboBox>
|
||||
#include <QHash>
|
||||
#include <QFile>
|
||||
#include <algorithm>
|
||||
#include <QDebug>
|
||||
|
||||
// TODO: translate country strings to Russian (qt doesn't have it)
|
||||
|
||||
@ -47,7 +49,7 @@ CountryEdit::CountryEdit(QList<AttributeEdit *> *edits_out, QObject *parent)
|
||||
// TODO: cache this
|
||||
QFile file(":/admc/countries.csv");
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
printf("ERROR: Failed to load countries file!\n");
|
||||
qDebug() << "ERROR: Failed to load countries file!\n";
|
||||
} else {
|
||||
// Load countries csv into maps
|
||||
// Map country code to country string and country abbreviation
|
||||
|
@ -106,6 +106,8 @@ set(TEST_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/src/admc/console_widget/results_description.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/admc/console_widget/results_view.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/admc/console_widget/console_drag_model.cpp
|
||||
|
||||
${PROJECT_SOURCE_DIR}/src/admc/admc.qrc
|
||||
)
|
||||
|
||||
# NOTE: ADD ALL TESTS TO THIS LIST
|
||||
@ -117,6 +119,7 @@ set(TEST_TARGETS
|
||||
admc_test_unlock_edit
|
||||
admc_test_upn_edit
|
||||
admc_test_string_edit
|
||||
admc_test_country_edit
|
||||
admc_test_gplink
|
||||
)
|
||||
|
||||
|
127
tests/admc_test_country_edit.cpp
Normal file
127
tests/admc_test_country_edit.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* ADMC - AD Management Center
|
||||
*
|
||||
* Copyright (C) 2020 BaseALT Ltd.
|
||||
*
|
||||
* 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_country_edit.h"
|
||||
|
||||
#include "adldap.h"
|
||||
#include "edits/country_edit.h"
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QComboBox>
|
||||
|
||||
#define TEST_ATTRIBUTE ATTRIBUTE_FIRST_NAME
|
||||
|
||||
void ADMCTestCountryEdit::init() {
|
||||
ADMCTest::init();
|
||||
|
||||
QList<AttributeEdit *> edits;
|
||||
edit = new CountryEdit(&edits, parent_widget);
|
||||
auto layout = new QFormLayout();
|
||||
parent_widget->setLayout(layout);
|
||||
edit->add_to_layout(layout);
|
||||
|
||||
parent_widget->show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(parent_widget, 1000));
|
||||
|
||||
tab();
|
||||
combo = qobject_cast<QComboBox *>(QApplication::focusWidget());
|
||||
QVERIFY(combo != 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);
|
||||
}
|
||||
|
||||
// Combo count should be some decently large number. If csv
|
||||
// failed to load, combo would have just the "None" item
|
||||
void ADMCTestCountryEdit::loaded_csv_file() {
|
||||
QVERIFY(combo->count() > 200);
|
||||
}
|
||||
|
||||
// edited() signal should be emitted when lineedit is edited
|
||||
void ADMCTestCountryEdit::emit_edited_signal() {
|
||||
bool edited_signal_emitted = false;
|
||||
connect(
|
||||
edit, &AttributeEdit::edited,
|
||||
[&edited_signal_emitted]() {
|
||||
edited_signal_emitted = true;
|
||||
});
|
||||
|
||||
combo->setCurrentIndex(combo->currentIndex() + 1);
|
||||
QVERIFY(edited_signal_emitted);
|
||||
}
|
||||
|
||||
// Edit should contain current attribute value after load()
|
||||
// call
|
||||
void ADMCTestCountryEdit::load() {
|
||||
// Set attribute value
|
||||
const int test_value = 4;
|
||||
ad.attribute_replace_int(dn, ATTRIBUTE_COUNTRY_CODE, test_value);
|
||||
|
||||
// Load user into edit
|
||||
const AdObject object = ad.search_object(dn);
|
||||
edit->load(ad, object);
|
||||
|
||||
|
||||
const int edit_value = combo->currentData().toInt();
|
||||
QVERIFY(edit_value == test_value);
|
||||
}
|
||||
|
||||
// Edit should do nothing if value wasn't modified
|
||||
void ADMCTestCountryEdit::apply_unmodified() {
|
||||
const AdObject object_before_apply = ad.search_object(dn);
|
||||
|
||||
const bool apply_success = edit->apply(ad, dn);
|
||||
QVERIFY(apply_success);
|
||||
|
||||
const AdObject object_after_apply = ad.search_object(dn);
|
||||
|
||||
QVERIFY(object_before_apply.get_attributes_data() == object_after_apply.get_attributes_data());
|
||||
}
|
||||
|
||||
// Edit should do change attribute to value.
|
||||
void ADMCTestCountryEdit::apply_modified() {
|
||||
const int new_value = 8;
|
||||
const int new_value_index = combo->findData(QVariant(new_value));
|
||||
combo->setCurrentIndex(new_value_index);
|
||||
|
||||
const AdObject object_before = ad.search_object(dn);
|
||||
const QString country_abbreviation_before = object_before.get_string(ATTRIBUTE_COUNTRY_ABBREVIATION);
|
||||
const QString country_before = object_before.get_string(ATTRIBUTE_COUNTRY);
|
||||
|
||||
const bool apply_success = edit->apply(ad, dn);
|
||||
QVERIFY(apply_success);
|
||||
|
||||
const AdObject object_after = ad.search_object(dn);
|
||||
const int current_value = object_after.get_int(ATTRIBUTE_COUNTRY_CODE);
|
||||
const QString country_abbreviation_after = object_after.get_string(ATTRIBUTE_COUNTRY_ABBREVIATION);
|
||||
const QString country_after = object_after.get_string(ATTRIBUTE_COUNTRY);
|
||||
QVERIFY(current_value == new_value);
|
||||
|
||||
// NOTE: figuring out what abbreviation and country
|
||||
// strings are actually supposed to be requires parsing
|
||||
// the countries csv file, so just check that these
|
||||
// strings changed.
|
||||
QVERIFY(country_abbreviation_after != country_abbreviation_before);
|
||||
QVERIFY(country_after != country_before);
|
||||
}
|
||||
|
||||
QTEST_MAIN(ADMCTestCountryEdit)
|
46
tests/admc_test_country_edit.h
Normal file
46
tests/admc_test_country_edit.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* ADMC - AD Management Center
|
||||
*
|
||||
* Copyright (C) 2020 BaseALT Ltd.
|
||||
*
|
||||
* 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_COUNTRY_EDIT_H
|
||||
#define ADMC_TEST_COUNTRY_EDIT_H
|
||||
|
||||
#include "admc_test.h"
|
||||
|
||||
class CountryEdit;
|
||||
class QComboBox;
|
||||
|
||||
class ADMCTestCountryEdit : public ADMCTest {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void init() override;
|
||||
|
||||
void loaded_csv_file();
|
||||
void emit_edited_signal();
|
||||
void load();
|
||||
void apply_unmodified();
|
||||
void apply_modified();
|
||||
|
||||
private:
|
||||
CountryEdit *edit;
|
||||
QComboBox *combo;
|
||||
QString dn;
|
||||
};
|
||||
|
||||
#endif /* ADMC_TEST_COUNTRY_EDIT_H */
|
Loading…
Reference in New Issue
Block a user