File indexing completed on 2024-05-12 05:10:04
0001 /*************************************************************************** 0002 Copyright (C) 2017 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 "omdbfetchertest.h" 0028 0029 #include "../fetch/omdbfetcher.h" 0030 #include "../collections/videocollection.h" 0031 #include "../entry.h" 0032 #include "../images/imagefactory.h" 0033 0034 #include <KSharedConfig> 0035 0036 #include <QTest> 0037 0038 QTEST_GUILESS_MAIN( OMDBFetcherTest ) 0039 0040 OMDBFetcherTest::OMDBFetcherTest() : AbstractFetcherTest() { 0041 } 0042 0043 void OMDBFetcherTest::initTestCase() { 0044 Tellico::ImageFactory::init(); 0045 0046 QString configFile = QFINDTESTDATA("tellicotest_private.config"); 0047 if(!configFile.isEmpty()) { 0048 m_config = KSharedConfig::openConfig(configFile, KConfig::SimpleConfig)->group(QStringLiteral("OMDB")); 0049 } 0050 } 0051 0052 void OMDBFetcherTest::testTitle() { 0053 // all the private API test config is in tellicotest_private.config right now 0054 if(!m_config.isValid()) { 0055 QSKIP("This test requires a config file.", SkipAll); 0056 } 0057 0058 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, 0059 QStringLiteral("superman returns")); 0060 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::OMDBFetcher(this)); 0061 fetcher->readConfig(m_config); 0062 QVERIFY(fetcher->canSearch(request.key())); 0063 0064 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0065 0066 QCOMPARE(results.size(), 1); 0067 0068 Tellico::Data::EntryPtr entry = results.at(0); 0069 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Superman Returns")); 0070 QCOMPARE(entry->field(QStringLiteral("certification")), QStringLiteral("PG-13 (USA)")); 0071 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2006")); 0072 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Action; Adventure; Sci-Fi")); 0073 QCOMPARE(entry->field(QStringLiteral("director")), QStringLiteral("Bryan Singer")); 0074 QCOMPARE(set(entry, "writer"), 0075 set("Bryan Singer; Dan Harris; Michael Dougherty")); 0076 // QCOMPARE(entry->field(QStringLiteral("producer")), QStringLiteral("Bryan Singer; Jon Peters; Gilbert Adler")); 0077 QCOMPARE(entry->field(QStringLiteral("running-time")), QStringLiteral("154")); 0078 QCOMPARE(entry->field(QStringLiteral("nationality")), QStringLiteral("United States; Australia")); 0079 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0080 QVERIFY(!castList.isEmpty()); 0081 QCOMPARE(castList.at(0), QStringLiteral("Brandon Routh")); 0082 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0083 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0084 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0085 QCOMPARE(entry->field(QStringLiteral("imdb")), QStringLiteral("http://www.imdb.com/title/tt0348150/")); 0086 } 0087 0088 // see https://bugs.kde.org/show_bug.cgi?id=336765 0089 void OMDBFetcherTest::testBabel() { 0090 if(!m_config.isValid()) { 0091 QSKIP("This test requires a config file.", SkipAll); 0092 } 0093 0094 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, 0095 QStringLiteral("babel")); 0096 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::OMDBFetcher(this)); 0097 fetcher->readConfig(m_config); 0098 QVERIFY(fetcher->canSearch(request.key())); 0099 0100 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0101 0102 QCOMPARE(results.size(), 1); 0103 0104 Tellico::Data::EntryPtr entry = results.at(0); 0105 QCOMPARE(entry->field("title"), QStringLiteral("Babel")); 0106 QCOMPARE(entry->field("year"), QStringLiteral("2006")); 0107 QCOMPARE(entry->field("director"), QString::fromUtf8("Alejandro G. Iñárritu")); 0108 } 0109 0110 void OMDBFetcherTest::testUpdate() { 0111 Tellico::Data::CollPtr coll(new Tellico::Data::VideoCollection(true)); 0112 Tellico::Data::FieldPtr field(new Tellico::Data::Field(QStringLiteral("imdb"), 0113 QStringLiteral("IMDB"), 0114 Tellico::Data::Field::URL)); 0115 QCOMPARE(coll->addField(field), true); 0116 Tellico::Data::EntryPtr entry(new Tellico::Data::Entry(coll)); 0117 coll->addEntries(entry); 0118 entry->setField(QStringLiteral("title"), QStringLiteral("The Man From Snowy River")); 0119 entry->setField(QStringLiteral("year"), QStringLiteral("1982")); 0120 0121 Tellico::Fetch::OMDBFetcher fetcher(this); 0122 auto request = fetcher.updateRequest(entry); 0123 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0124 QVERIFY(request.value().contains(QStringLiteral("y=1982"))); 0125 0126 entry->setField(QStringLiteral("imdb"), QStringLiteral("https://www.imdb.com/title/tt0084296/?ref_=nv_sr_srsg_0")); 0127 request = fetcher.updateRequest(entry); 0128 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0129 QVERIFY(request.value().contains(QStringLiteral("i=tt0084296"))); 0130 }