File indexing completed on 2024-05-05 05:04:13
0001 // SPDX-FileCopyrightText: 2023 Rishi Kumar <rsi.dev17@gmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 #include "account/accountmanager.h" 0005 #include "admin/iprulestoolmodel.h" 0006 #include "helperreply.h" 0007 #include "mockaccount.h" 0008 0009 #include <QtTest/QtTest> 0010 0011 class IpRulesToolTest : public QObject 0012 { 0013 Q_OBJECT 0014 0015 private Q_SLOTS: 0016 void initTestCase() 0017 { 0018 account = new MockAccount(); 0019 AccountManager::instance().addAccount(account, false); 0020 AccountManager::instance().selectAccount(account); 0021 } 0022 0023 void cleanupTestCase() 0024 { 0025 AccountManager::instance().removeAccount(account); 0026 } 0027 0028 void testModel() 0029 { 0030 QUrl url = account->apiUrl(QStringLiteral("/api/v1/admin/ip_blocks")); 0031 account->registerGet(url, new TestReply(QStringLiteral("ip-info.json"), account)); 0032 0033 IpRulesToolModel ipRulesToolModel; 0034 QCOMPARE(ipRulesToolModel.rowCount({}), 4); 0035 QCOMPARE(ipRulesToolModel.data(ipRulesToolModel.index(0, 0), IpRulesToolModel::IdRole).toInt(), 1); 0036 QCOMPARE(ipRulesToolModel.data(ipRulesToolModel.index(0, 0), IpRulesToolModel::IpRole).toString(), QStringLiteral("192.0.2.0/30")); 0037 Q_ASSERT(ipRulesToolModel.data(ipRulesToolModel.index(0, 0), IpRulesToolModel::SeverityRole).isValid()); 0038 QCOMPARE(ipRulesToolModel.data(ipRulesToolModel.index(0, 0), IpRulesToolModel::SeverityRole).toInt(), IpInfo::BlockAccess); 0039 QCOMPARE(ipRulesToolModel.data(ipRulesToolModel.index(0, 0), IpRulesToolModel::CommentRole).toString(), QStringLiteral("konqi is cute")); 0040 Q_ASSERT(ipRulesToolModel.data(ipRulesToolModel.index(0, 0), IpRulesToolModel::CreatedAtRole).isValid()); 0041 Q_ASSERT(ipRulesToolModel.data(ipRulesToolModel.index(0, 0), IpRulesToolModel::ExpiredAtRole).isValid()); 0042 } 0043 0044 private: 0045 MockAccount *account = nullptr; 0046 }; 0047 0048 QTEST_MAIN(IpRulesToolTest) 0049 #include "iprulestooltest.moc"