File indexing completed on 2024-05-12 05:10:06
0001 /*************************************************************************** 0002 Copyright (C) 2010-2011 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 "themoviedbfetchertest.h" 0028 0029 #include "../fetch/themoviedbfetcher.h" 0030 #include "../collections/videocollection.h" 0031 #include "../entry.h" 0032 #include "../images/imagefactory.h" 0033 0034 #include <KSharedConfig> 0035 #include <KConfigGroup> 0036 0037 #include <QTest> 0038 0039 QTEST_GUILESS_MAIN( TheMovieDBFetcherTest ) 0040 0041 TheMovieDBFetcherTest::TheMovieDBFetcherTest() : AbstractFetcherTest() { 0042 } 0043 0044 void TheMovieDBFetcherTest::initTestCase() { 0045 Tellico::ImageFactory::init(); 0046 0047 m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("Superman Returns")); 0048 m_fieldValues.insert(QStringLiteral("studio"), QStringLiteral("Warner Bros. Pictures; Bad Hat Harry Productions; " 0049 "Peters Entertainment; DC Comics; Legendary Pictures")); 0050 m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("2006")); 0051 m_fieldValues.insert(QStringLiteral("genre"), QStringLiteral("action; adventure; science fiction")); 0052 m_fieldValues.insert(QStringLiteral("director"), QStringLiteral("Bryan Singer")); 0053 m_fieldValues.insert(QStringLiteral("producer"), QStringLiteral("Bryan Singer; Jon Peters; Gilbert Adler")); 0054 m_fieldValues.insert(QStringLiteral("running-time"), QStringLiteral("154")); 0055 m_fieldValues.insert(QStringLiteral("nationality"), QStringLiteral("USA")); 0056 } 0057 0058 void TheMovieDBFetcherTest::testTitle() { 0059 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, 0060 QStringLiteral("superman returns")); 0061 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::TheMovieDBFetcher(this)); 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 QHashIterator<QString, QString> i(m_fieldValues); 0069 while(i.hasNext()) { 0070 i.next(); 0071 QString result = entry->field(i.key()).toLower(); 0072 QCOMPARE(set(result), set(i.value().toLower())); 0073 } 0074 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0075 QVERIFY(!castList.isEmpty()); 0076 QCOMPARE(castList.at(0), QStringLiteral("Brandon Routh::Clark Kent / Superman")); 0077 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0078 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0079 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0080 } 0081 0082 void TheMovieDBFetcherTest::testTitleFr() { 0083 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("TMDB FR")); 0084 cg.writeEntry("Locale", QStringLiteral("fr")); 0085 0086 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, 0087 QStringLiteral("superman returns")); 0088 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::TheMovieDBFetcher(this)); 0089 fetcher->readConfig(cg); 0090 0091 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0092 0093 QCOMPARE(results.size(), 1); 0094 0095 Tellico::Data::EntryPtr entry = results.at(0); 0096 QStringList fields = QStringList() << QStringLiteral("title") 0097 << QStringLiteral("studio") 0098 << QStringLiteral("year") 0099 << QStringLiteral("title"); 0100 foreach(const QString& field, fields) { 0101 QString result = entry->field(field).toLower(); 0102 QCOMPARE(set(result), set(m_fieldValues.value(field).toLower())); 0103 } 0104 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0105 QVERIFY(!castList.isEmpty()); 0106 QCOMPARE(castList.at(0), QStringLiteral("Brandon Routh::Clark Kent / Superman")); 0107 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0108 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0109 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0110 } 0111 0112 // see https://bugs.kde.org/show_bug.cgi?id=336765 0113 void TheMovieDBFetcherTest::testBabel() { 0114 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, 0115 QStringLiteral("babel")); 0116 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::TheMovieDBFetcher(this)); 0117 0118 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0119 0120 QCOMPARE(results.size(), 1); 0121 0122 Tellico::Data::EntryPtr entry = results.at(0); 0123 QCOMPARE(entry->field("title"), QStringLiteral("Babel")); 0124 QCOMPARE(entry->field("year"), QStringLiteral("2006")); 0125 QCOMPARE(set(entry, "director"), set(QString::fromUtf8("Alejandro González Iñárritu"))); 0126 QCOMPARE(set(entry, "producer"), set(QString::fromUtf8("Alejandro González Iñárritu; Steve Golin; Jon Kilik; Ann Ruark; Corinne Golden Weber"))); 0127 } 0128 0129 void TheMovieDBFetcherTest::testAllMankind() { 0130 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("TMDB")); 0131 cg.writeEntry("Custom Fields", QStringLiteral("origtitle,alttitle,network,episode,tmdb,imdb")); 0132 0133 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, 0134 QStringLiteral("for all mankind")); 0135 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::TheMovieDBFetcher(this)); 0136 fetcher->readConfig(cg); 0137 0138 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0139 0140 QCOMPARE(results.size(), 1); 0141 0142 Tellico::Data::EntryPtr entry = results.at(0); 0143 QCOMPARE(entry->field("title"), QStringLiteral("For All Mankind")); 0144 QCOMPARE(entry->field("origtitle"), QStringLiteral("For All Mankind")); 0145 QStringList titleList = Tellico::FieldFormat::splitValue(entry->field(QStringLiteral("alttitle"))); 0146 QVERIFY(!titleList.isEmpty()); 0147 QVERIFY(titleList.contains(QStringLiteral("为全人类"))); 0148 QCOMPARE(entry->field("year"), QStringLiteral("2019")); 0149 QCOMPARE(entry->field("network"), QStringLiteral("Apple TV+")); 0150 QCOMPARE(entry->field("language"), QStringLiteral("English")); 0151 QCOMPARE(entry->field("nationality"), QStringLiteral("USA")); 0152 QCOMPARE(set(entry, "producer"), set(QStringLiteral("Huey M. Park"))); 0153 QVERIFY(entry->field("cast").startsWith(QStringLiteral("Joel Kinnaman::Ed Baldwin"))); 0154 QStringList episodeList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("episode"))); 0155 QVERIFY(!episodeList.isEmpty()); 0156 QCOMPARE(episodeList.at(0), QStringLiteral("Red Moon::1::1")); 0157 // imdb should be empty 0158 QVERIFY(entry->field(QStringLiteral("imdb")).isEmpty()); 0159 QCOMPARE(entry->field(QStringLiteral("tmdb")), QStringLiteral("https://www.themoviedb.org/tv/87917")); 0160 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0161 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0162 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0163 } 0164 0165 void TheMovieDBFetcherTest::testUpdate() { 0166 Tellico::Data::CollPtr coll(new Tellico::Data::VideoCollection(true)); 0167 Tellico::Data::FieldPtr field(new Tellico::Data::Field(QStringLiteral("imdb"), 0168 QStringLiteral("IMDB"), 0169 Tellico::Data::Field::URL)); 0170 QCOMPARE(coll->addField(field), true); 0171 Tellico::Data::EntryPtr entry(new Tellico::Data::Entry(coll)); 0172 coll->addEntries(entry); 0173 entry->setField(QStringLiteral("title"), QStringLiteral("The Man From Snowy River")); 0174 entry->setField(QStringLiteral("year"), QStringLiteral("1982")); 0175 0176 Tellico::Fetch::TheMovieDBFetcher fetcher(this); 0177 auto request = fetcher.updateRequest(entry); 0178 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0179 QVERIFY(request.value().contains(QStringLiteral("year=1982"))); 0180 0181 entry->setField(QStringLiteral("imdb"), QStringLiteral("https://www.imdb.com/title/tt0084296/?ref_=nv_sr_srsg_0")); 0182 request = fetcher.updateRequest(entry); 0183 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0184 QCOMPARE(request.value(), QStringLiteral("external_source=imdb_id")); 0185 QCOMPARE(request.data(), QStringLiteral("/find/tt0084296")); 0186 }