File indexing completed on 2024-05-12 05:09:53

0001 /***************************************************************************
0002     Copyright (C) 2010-2012 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 "allocinefetchertest.h"
0028 
0029 #include "../fetch/execexternalfetcher.h"
0030 #include "../fetch/allocinefetcher.h"
0031 #include "../collections/videocollection.h"
0032 #include "../collectionfactory.h"
0033 #include "../entry.h"
0034 #include "../images/imagefactory.h"
0035 
0036 #include <KSharedConfig>
0037 
0038 #include <QTest>
0039 
0040 QTEST_GUILESS_MAIN( AllocineFetcherTest )
0041 
0042 AllocineFetcherTest::AllocineFetcherTest() : AbstractFetcherTest() {
0043 }
0044 
0045 void AllocineFetcherTest::initTestCase() {
0046   Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video");
0047   Tellico::ImageFactory::init();
0048 
0049   m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("allocine"));
0050   m_config.writeEntry("Max Cast", QStringLiteral("5"));
0051   m_config.writeEntry("Custom Fields", QStringLiteral("origtitle,allocine"));
0052 }
0053 
0054 void AllocineFetcherTest::cleanupTestCase() {
0055   Tellico::ImageFactory::clean(true);
0056 }
0057 
0058 void AllocineFetcherTest::testTitle() {
0059   // Allocine script is currently failing
0060   return;
0061   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title,
0062                                        QStringLiteral("Superman Returns"));
0063   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ExecExternalFetcher(this));
0064 
0065   KConfig config(QFINDTESTDATA("../fetch/scripts/fr.allocine.py.spec"), KConfig::SimpleConfig);
0066   KConfigGroup cg = config.group(QStringLiteral("<default>"));
0067   cg.writeEntry("ExecPath", QFINDTESTDATA("../fetch/scripts/fr.allocine.py"));
0068   fetcher->readConfig(cg);
0069   // don't sync() and save the new path
0070   cg.deleteEntry("ExecPath");
0071 
0072   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0073 
0074   QCOMPARE(results.size(), 1);
0075 
0076   Tellico::Data::EntryPtr entry = results.at(0);
0077   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Superman Returns"));
0078   QCOMPARE(entry->field(QStringLiteral("director")), QStringLiteral("Bryan Singer"));
0079   QCOMPARE(entry->field(QStringLiteral("producer")), QStringLiteral("Jon Peters; Gilbert Adler; Bryan Singer; Lorne Orleans"));
0080   QCOMPARE(entry->field(QStringLiteral("studio")), QStringLiteral("Warner Bros. France"));
0081   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2006"));
0082   QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Fantastique; Action"));
0083   QCOMPARE(entry->field(QStringLiteral("nationality")), QString::fromUtf8("Américain; Australien"));
0084   QCOMPARE(entry->field(QStringLiteral("running-time")), QStringLiteral("154"));
0085   QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast")));
0086   QVERIFY(!castList.isEmpty());
0087   QCOMPARE(castList.at(0), QStringLiteral("Brandon Routh::Clark Kent / Superman"));
0088   QCOMPARE(castList.size(), 8);
0089   QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
0090   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0091   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0092 }
0093 
0094 void AllocineFetcherTest::testTitleAccented() {
0095   // Allocine script is currently failing
0096   return;
0097   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title,
0098                                        QStringLiteral("Opération Tonnerre"));
0099   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ExecExternalFetcher(this));
0100 
0101   KConfig config(QFINDTESTDATA("../fetch/scripts/fr.allocine.py.spec"), KConfig::SimpleConfig);
0102   KConfigGroup cg = config.group(QStringLiteral("<default>"));
0103   cg.writeEntry("ExecPath", QFINDTESTDATA("../fetch/scripts/fr.allocine.py"));
0104   fetcher->readConfig(cg);
0105   // don't sync() and save the new path
0106   cg.deleteEntry("ExecPath");
0107 
0108   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0109 
0110   QCOMPARE(results.size(), 1);
0111 
0112   Tellico::Data::EntryPtr entry = results.at(0);
0113   QCOMPARE(entry->field(QStringLiteral("title")), QString::fromUtf8("Opération Tonnerre"));
0114   QCOMPARE(entry->field(QStringLiteral("titre-original")), QStringLiteral("Thunderball"));
0115   QCOMPARE(entry->field(QStringLiteral("studio")), QString());
0116 }
0117 
0118 void AllocineFetcherTest::testTitleAccentRemoved() {
0119   // Allocine script is currently failing
0120   return;
0121   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title,
0122                                        QStringLiteral("Operation Tonnerre"));
0123   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ExecExternalFetcher(this));
0124 
0125   KConfig config(QFINDTESTDATA("../fetch/scripts/fr.allocine.py.spec"), KConfig::SimpleConfig);
0126   KConfigGroup cg = config.group(QStringLiteral("<default>"));
0127   cg.writeEntry("ExecPath", QFINDTESTDATA("../fetch/scripts/fr.allocine.py"));
0128   fetcher->readConfig(cg);
0129   // don't sync() and save the new path
0130   cg.deleteEntry("ExecPath");
0131 
0132   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0133 
0134   QCOMPARE(results.size(), 1);
0135 
0136   Tellico::Data::EntryPtr entry = results.at(0);
0137   QCOMPARE(entry->field(QStringLiteral("title")), QString::fromUtf8("Opération Tonnerre"));
0138 }
0139 
0140 void AllocineFetcherTest::testPlotQuote() {
0141   // Allocine script is currently failing
0142   return;
0143   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title,
0144                                        QStringLiteral("Goldfinger"));
0145   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ExecExternalFetcher(this));
0146 
0147   KConfig config(QFINDTESTDATA("../fetch/scripts/fr.allocine.py.spec"), KConfig::SimpleConfig);
0148   KConfigGroup cg = config.group(QStringLiteral("<default>"));
0149   cg.writeEntry("ExecPath", QFINDTESTDATA("../fetch/scripts/fr.allocine.py"));
0150   fetcher->readConfig(cg);
0151   // don't sync() and save the new path
0152   cg.deleteEntry("ExecPath");
0153 
0154   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0155 
0156   QCOMPARE(results.size(), 1);
0157 
0158   Tellico::Data::EntryPtr entry = results.at(0);
0159   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Goldfinger"));
0160   QVERIFY(!entry->field(QStringLiteral("plot")).contains(QStringLiteral("&quot;")));
0161 }
0162 
0163 void AllocineFetcherTest::testTitleAPI() {
0164   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword,
0165                                        QStringLiteral("Superman Returns"));
0166   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::AllocineFetcher(this));
0167   fetcher->readConfig(m_config);
0168   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0169 
0170   QCOMPARE(results.size(), 1);
0171 
0172   Tellico::Data::EntryPtr entry = results.at(0);
0173   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Superman Returns"));
0174   QCOMPARE(entry->field(QStringLiteral("director")), QStringLiteral("Bryan Singer"));
0175   QCOMPARE(entry->field(QStringLiteral("producer")), QStringLiteral("Jon Peters; Gilbert Adler; Bryan Singer; Lorne Orleans"));
0176   QCOMPARE(entry->field(QStringLiteral("studio")), QStringLiteral("Warner Bros. France"));
0177   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2006"));
0178   QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Fantastique; Action"));
0179   QCOMPARE(entry->field(QStringLiteral("nationality")), QStringLiteral("U.S.A.; Australie"));
0180   QCOMPARE(entry->field(QStringLiteral("running-time")), QStringLiteral("154"));
0181   QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast")));
0182   QVERIFY(!castList.isEmpty());
0183   QCOMPARE(castList.at(0), QStringLiteral("Brandon Routh::Clark Kent / Superman"));
0184   QCOMPARE(castList.size(), 5);
0185   QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
0186   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0187   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0188 }
0189 
0190 void AllocineFetcherTest::testTitleAPIAccented() {
0191   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword,
0192                                        QStringLiteral("Opération Tonnerre"));
0193   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::AllocineFetcher(this));
0194   fetcher->readConfig(m_config);
0195   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0196 
0197   QCOMPARE(results.size(), 1);
0198 
0199   Tellico::Data::EntryPtr entry = results.at(0);
0200   QCOMPARE(entry->field(QStringLiteral("title")), QString::fromUtf8("Opération Tonnerre"));
0201   QCOMPARE(entry->field(QStringLiteral("origtitle")), QStringLiteral("Thunderball"));
0202   QCOMPARE(entry->field(QStringLiteral("studio")), QStringLiteral("United International Pictures (UIP)"));
0203   QCOMPARE(entry->field(QStringLiteral("director")), QStringLiteral("Terence Young"));
0204   QCOMPARE(entry->field(QStringLiteral("color")), QStringLiteral("Color"));
0205   QVERIFY(!entry->field(QStringLiteral("allocine")).isEmpty());
0206 }
0207 
0208 // mentioned in https://bugs.kde.org/show_bug.cgi?id=337432
0209 void AllocineFetcherTest::testGhostDog() {
0210   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword,
0211                                        QStringLiteral("Ghost Dog: la voie du samourai"));
0212   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::AllocineFetcher(this));
0213   fetcher->readConfig(m_config);
0214   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0215 
0216   QCOMPARE(results.size(), 1);
0217 
0218   Tellico::Data::EntryPtr entry = results.at(0);
0219   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Ghost Dog: la voie du samourai"));
0220 }