File indexing completed on 2024-05-19 16:19:07
0001 /*************************************************************************** 0002 Copyright (C) 2019-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 "colnectfetchertest.h" 0028 0029 #include "../fetch/colnectfetcher.h" 0030 #include "../entry.h" 0031 #include "../collections/coincollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../images/imagefactory.h" 0034 #include "../fieldformat.h" 0035 #include "../fetch/fetcherjob.h" 0036 0037 #include <KSharedConfig> 0038 0039 #include <QTest> 0040 0041 QTEST_GUILESS_MAIN( ColnectFetcherTest ) 0042 0043 ColnectFetcherTest::ColnectFetcherTest() : AbstractFetcherTest() { 0044 } 0045 0046 void ColnectFetcherTest::initTestCase() { 0047 Tellico::ImageFactory::init(); 0048 Tellico::RegisterCollection<Tellico::Data::CoinCollection> registerMe(Tellico::Data::Collection::Coin, "coin"); 0049 0050 m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("colnect")); 0051 m_config.writeEntry("Custom Fields", QStringLiteral("obverse,reverse,series,mintage,description")); 0052 } 0053 0054 void ColnectFetcherTest::testSlug() { 0055 // test the implementation of the Colnect slug derivation 0056 QFETCH(QString, input); 0057 QFETCH(QString, slug); 0058 0059 QCOMPARE(Tellico::Fetch::ColnectFetcher::URLize(input), slug); 0060 } 0061 0062 void ColnectFetcherTest::testSlug_data() { 0063 QTest::addColumn<QString>("input"); 0064 QTest::addColumn<QString>("slug"); 0065 0066 QTest::newRow("basic") << QStringLiteral("input") << QStringLiteral("input"); 0067 QTest::newRow("Aus1$") << QStringLiteral("1 Dollar (50 Years Moonlanding)") << QStringLiteral("1_Dollar_50_Years_Moonlanding"); 0068 } 0069 0070 void ColnectFetcherTest::testRaw() { 0071 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Coin, 0072 Tellico::Fetch::Raw, 0073 QStringLiteral("147558")); 0074 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this)); 0075 fetcher->readConfig(m_config); 0076 0077 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0078 0079 QCOMPARE(results.size(), 1); 0080 Tellico::Data::EntryPtr entry = results.at(0); 0081 0082 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2019")); 0083 QCOMPARE(entry->field(QStringLiteral("country")), QStringLiteral("Australia")); 0084 QCOMPARE(entry->field(QStringLiteral("denomination")), QStringLiteral("$1.00")); 0085 QCOMPARE(entry->field(QStringLiteral("currency")), QStringLiteral("$ - Australian dollar")); 0086 QCOMPARE(entry->field(QStringLiteral("series")), QStringLiteral("1970~Today - Numismatic Products")); 0087 QCOMPARE(entry->field(QStringLiteral("mintage")), QStringLiteral("25000")); 0088 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0089 QVERIFY(!entry->field(QStringLiteral("obverse")).isEmpty()); 0090 QVERIFY(!entry->field(QStringLiteral("obverse")).contains(QLatin1Char('/'))); 0091 QVERIFY(!entry->field(QStringLiteral("reverse")).isEmpty()); 0092 QVERIFY(!entry->field(QStringLiteral("reverse")).contains(QLatin1Char('/'))); 0093 } 0094 0095 void ColnectFetcherTest::testSacagawea() { 0096 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Coin, 0097 Tellico::Fetch::Keyword, 0098 QStringLiteral("2007 Sacagawea")); 0099 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this)); 0100 fetcher->readConfig(m_config); 0101 0102 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0103 0104 QCOMPARE(results.size(), 1); 0105 Tellico::Data::EntryPtr entry = results.at(0); 0106 0107 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2007")); 0108 QCOMPARE(entry->field(QStringLiteral("country")), QStringLiteral("United States of America")); 0109 QCOMPARE(entry->field(QStringLiteral("denomination")), QStringLiteral("$1.00")); 0110 QCOMPARE(entry->field(QStringLiteral("currency")), QStringLiteral("$ - United States dollar")); 0111 QCOMPARE(entry->field(QStringLiteral("series")), QStringLiteral("B06a - Eisenhower, Anthony & Sacagawea Dollar")); 0112 QCOMPARE(entry->field(QStringLiteral("mintage")), QStringLiteral("1497251077")); 0113 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0114 QVERIFY(!entry->field(QStringLiteral("obverse")).isEmpty()); 0115 QVERIFY(!entry->field(QStringLiteral("obverse")).contains(QLatin1Char('/'))); 0116 QVERIFY(!entry->field(QStringLiteral("reverse")).isEmpty()); 0117 QVERIFY(!entry->field(QStringLiteral("reverse")).contains(QLatin1Char('/'))); 0118 } 0119 0120 void ColnectFetcherTest::testSkylab() { 0121 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("colnect stamps")); 0122 cg.writeEntry("Custom Fields", QStringLiteral("image,series,description,stanley-gibbons,michel")); 0123 0124 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Stamp, 0125 Tellico::Fetch::Title, 0126 QStringLiteral("2013 Skylab")); 0127 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this)); 0128 fetcher->readConfig(cg); 0129 0130 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0131 0132 QCOMPARE(results.size(), 1); 0133 Tellico::Data::EntryPtr entry = results.at(0); 0134 0135 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2013")); 0136 QCOMPARE(entry->field(QStringLiteral("country")), QStringLiteral("Papua New Guinea")); 0137 QCOMPARE(entry->field(QStringLiteral("stanley-gibbons")), QStringLiteral("PG 1638")); 0138 QCOMPARE(entry->field(QStringLiteral("michel")), QStringLiteral("PG 1902")); 0139 QCOMPARE(entry->field(QStringLiteral("series")), QStringLiteral("15th Anniversary of Launch of International Space Station")); 0140 QCOMPARE(entry->field(QStringLiteral("gummed")), QStringLiteral("PVA (Polyvinyl Alcohol)")); 0141 QCOMPARE(entry->field(QStringLiteral("denomination")), QStringLiteral("K1.30")); 0142 QCOMPARE(entry->field(QStringLiteral("currency")), QStringLiteral("K - Papua New Guinean kina")); 0143 QCOMPARE(entry->field(QStringLiteral("color")), QStringLiteral("Multicolor")); 0144 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0145 QVERIFY(!entry->field(QStringLiteral("image")).isEmpty()); 0146 QVERIFY(!entry->field(QStringLiteral("image")).contains(QLatin1Char('/'))); 0147 }