File indexing completed on 2024-05-12 05:10:04
0001 /*************************************************************************** 0002 Copyright (C) 2020 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #undef QT_NO_CAST_FROM_ASCII 0026 0027 #include "numistafetchertest.h" 0028 0029 #include "../fetch/numistafetcher.h" 0030 #include "../collections/coincollection.h" 0031 #include "../entry.h" 0032 #include "../images/imagefactory.h" 0033 0034 #include <KSharedConfig> 0035 0036 #include <QTest> 0037 0038 QTEST_GUILESS_MAIN( NumistaFetcherTest ) 0039 0040 NumistaFetcherTest::NumistaFetcherTest() : AbstractFetcherTest() { 0041 } 0042 0043 void NumistaFetcherTest::initTestCase() { 0044 Tellico::ImageFactory::init(); 0045 0046 m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("numista")); 0047 m_config.writeEntry("Custom Fields", QStringLiteral("numista,description,obverse,reverse,km")); 0048 } 0049 0050 void NumistaFetcherTest::testSacagawea() { 0051 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Coin, 0052 Tellico::Fetch::Keyword, 0053 QStringLiteral("2019 Sacagawea")); 0054 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::NumistaFetcher(this)); 0055 fetcher->readConfig(m_config); 0056 0057 static_cast<Tellico::Fetch::NumistaFetcher*>(fetcher.data())->setLimit(1); 0058 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0059 0060 QCOMPARE(results.size(), 1); 0061 Tellico::Data::EntryPtr entry = results.at(0); 0062 0063 QCOMPARE(entry->field(QStringLiteral("type")), QStringLiteral("Native American Dollar")); 0064 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2019")); 0065 QCOMPARE(entry->field(QStringLiteral("country")), QStringLiteral("United States")); 0066 QCOMPARE(entry->field(QStringLiteral("denomination")), QStringLiteral("1 Dollar")); 0067 QCOMPARE(entry->field(QStringLiteral("currency")), QStringLiteral("Dollar")); 0068 QCOMPARE(entry->field(QStringLiteral("numista")), QStringLiteral("https://en.numista.com/catalogue/pieces155679.html")); 0069 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0070 QVERIFY(!entry->field(QStringLiteral("obverse")).isEmpty()); 0071 QVERIFY(!entry->field(QStringLiteral("obverse")).contains(QLatin1Char('/'))); 0072 QVERIFY(!entry->field(QStringLiteral("reverse")).isEmpty()); 0073 QVERIFY(!entry->field(QStringLiteral("reverse")).contains(QLatin1Char('/'))); 0074 } 0075 0076 void NumistaFetcherTest::testJefferson() { 0077 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Coin, 0078 Tellico::Fetch::Keyword, 0079 QStringLiteral("1974 jefferson nickel")); 0080 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::NumistaFetcher(this)); 0081 0082 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0083 0084 QVERIFY(!results.isEmpty()); 0085 Tellico::Data::EntryPtr entry = results.at(0); 0086 QVERIFY(entry); 0087 0088 QCOMPARE(entry->field(QStringLiteral("type")), QStringLiteral("Jefferson Nickel")); 0089 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1974")); 0090 QCOMPARE(entry->field(QStringLiteral("country")), QStringLiteral("United States")); 0091 QCOMPARE(entry->field(QStringLiteral("denomination")), QStringLiteral("5 Cents")); 0092 QCOMPARE(entry->field(QStringLiteral("currency")), QStringLiteral("Dollar")); 0093 } 0094 0095 void NumistaFetcherTest::testPagination() { 0096 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Coin, 0097 Tellico::Fetch::Keyword, 0098 QStringLiteral("jefferson")); 0099 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::NumistaFetcher(this)); 0100 0101 // fetch as many as 30 :) 0102 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 30); 0103 0104 QVERIFY(results.count() > 20); 0105 }