File indexing completed on 2024-05-12 16:46:23
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 0063 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0064 0065 QCOMPARE(results.size(), 1); 0066 0067 Tellico::Data::EntryPtr entry = results.at(0); 0068 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Superman Returns")); 0069 QCOMPARE(entry->field(QStringLiteral("certification")), QStringLiteral("PG-13 (USA)")); 0070 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2006")); 0071 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Action; Sci-Fi")); 0072 QCOMPARE(entry->field(QStringLiteral("director")), QStringLiteral("Bryan Singer")); 0073 QCOMPARE(set(entry, "writer"), 0074 set("Bryan Singer; Dan Harris; Michael Dougherty")); 0075 // QCOMPARE(entry->field(QStringLiteral("producer")), QStringLiteral("Bryan Singer; Jon Peters; Gilbert Adler")); 0076 QCOMPARE(entry->field(QStringLiteral("running-time")), QStringLiteral("154")); 0077 QCOMPARE(entry->field(QStringLiteral("nationality")), QStringLiteral("United States; Australia")); 0078 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0079 QVERIFY(!castList.isEmpty()); 0080 QCOMPARE(castList.at(0), QStringLiteral("Brandon Routh")); 0081 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0082 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0083 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0084 QCOMPARE(entry->field(QStringLiteral("imdb")), QStringLiteral("http://www.imdb.com/title/tt0348150/")); 0085 } 0086 0087 // see https://bugs.kde.org/show_bug.cgi?id=336765 0088 void OMDBFetcherTest::testBabel() { 0089 if(!m_config.isValid()) { 0090 QSKIP("This test requires a config file.", SkipAll); 0091 } 0092 0093 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, 0094 QStringLiteral("babel")); 0095 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::OMDBFetcher(this)); 0096 fetcher->readConfig(m_config); 0097 0098 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0099 0100 QCOMPARE(results.size(), 1); 0101 0102 Tellico::Data::EntryPtr entry = results.at(0); 0103 QCOMPARE(entry->field("title"), QStringLiteral("Babel")); 0104 QCOMPARE(entry->field("year"), QStringLiteral("2006")); 0105 QCOMPARE(entry->field("director"), QString::fromUtf8("Alejandro G. Iñárritu")); 0106 } 0107 0108 void OMDBFetcherTest::testUpdate() { 0109 Tellico::Data::CollPtr coll(new Tellico::Data::VideoCollection(true)); 0110 Tellico::Data::FieldPtr field(new Tellico::Data::Field(QStringLiteral("imdb"), 0111 QStringLiteral("IMDB"), 0112 Tellico::Data::Field::URL)); 0113 QCOMPARE(coll->addField(field), true); 0114 Tellico::Data::EntryPtr entry(new Tellico::Data::Entry(coll)); 0115 coll->addEntries(entry); 0116 entry->setField(QStringLiteral("title"), QStringLiteral("The Man From Snowy River")); 0117 entry->setField(QStringLiteral("year"), QStringLiteral("1982")); 0118 0119 Tellico::Fetch::OMDBFetcher fetcher(this); 0120 auto request = fetcher.updateRequest(entry); 0121 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0122 QVERIFY(request.value().contains(QStringLiteral("y=1982"))); 0123 0124 entry->setField(QStringLiteral("imdb"), QStringLiteral("https://www.imdb.com/title/tt0084296/?ref_=nv_sr_srsg_0")); 0125 request = fetcher.updateRequest(entry); 0126 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0127 QVERIFY(request.value().contains(QStringLiteral("i=tt0084296"))); 0128 }