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