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

0001 /***************************************************************************
0002     Copyright (C) 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 #include "darkhorsefetchertest.h"
0026 
0027 #include "../fetch/execexternalfetcher.h"
0028 #include "../entry.h"
0029 #include "../collections/comicbookcollection.h"
0030 #include "../collectionfactory.h"
0031 #include "../images/imagefactory.h"
0032 #include "../images/image.h"
0033 #include "../fieldformat.h"
0034 
0035 #include <KSharedConfig>
0036 #include <KConfigGroup>
0037 
0038 #include <QTest>
0039 #include <QStandardPaths>
0040 
0041 QTEST_GUILESS_MAIN( DarkHorseFetcherTest )
0042 
0043 #define QSL(x) QStringLiteral(x)
0044 
0045 DarkHorseFetcherTest::DarkHorseFetcherTest() : AbstractFetcherTest() {
0046 }
0047 
0048 void DarkHorseFetcherTest::initTestCase() {
0049   const QString python = QStandardPaths::findExecutable(QSL("python"));
0050   if(python.isEmpty()) {
0051     QSKIP("This test requires python", SkipAll);
0052   }
0053 
0054   Tellico::ImageFactory::init();
0055   Tellico::RegisterCollection<Tellico::Data::ComicBookCollection> registerComic(Tellico::Data::Collection::ComicBook, "comicbook");
0056 }
0057 
0058 void DarkHorseFetcherTest::testComic() {
0059   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::Title,
0060                                        QSL("axe cop: bad guy earth #1"));
0061   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ExecExternalFetcher(this));
0062 
0063   KSharedConfig::Ptr config = KSharedConfig::openConfig(QFINDTESTDATA("../fetch/scripts/dark_horse_comics.py.spec"),
0064                                                         KConfig::SimpleConfig);
0065   KConfigGroup cg = config->group(QSL("<default>"));
0066   cg.writeEntry("ExecPath", QFINDTESTDATA("../fetch/scripts/dark_horse_comics.py"));
0067   fetcher->readConfig(cg);
0068   // don't sync() and save the new path
0069   cg.deleteEntry("ExecPath");
0070 
0071   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0072 
0073   QCOMPARE(results.size(), 2);
0074   Tellico::Data::EntryPtr entry = results.at(1);
0075 
0076   QCOMPARE(entry->field(QSL("title")), QSL("Axe Cop: Bad Guy Earth #1"));
0077   QCOMPARE(entry->field(QSL("pub_year")), QSL("2011"));
0078   QCOMPARE(entry->field(QSL("genre")), QSL("Humor; Kids"));
0079   QCOMPARE(entry->field(QSL("pages")), QSL("32"));
0080   QCOMPARE(entry->field(QSL("publisher")), QSL("Dark Horse Comics"));
0081   QCOMPARE(entry->field(QSL("writer")), QSL("Malachai Nicolle"));
0082   QCOMPARE(entry->field(QSL("artist")), QSL("Ethan Nicolle"));
0083   QVERIFY(!entry->field(QSL("comments")).isEmpty());
0084   QVERIFY(!entry->field(QSL("cover")).isEmpty());
0085   QVERIFY(!entry->field(QSL("cover")).contains(QLatin1Char('/')));
0086   QVERIFY(!Tellico::ImageFactory::imageById(entry->field(QSL("cover"))).isNull());
0087 }
0088 
0089 void DarkHorseFetcherTest::testMasterverse() {
0090   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::Title,
0091                                        QSL("Masters of the Universe: Masterverse #1"));
0092   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ExecExternalFetcher(this));
0093 
0094   KSharedConfig::Ptr config = KSharedConfig::openConfig(QFINDTESTDATA("../fetch/scripts/dark_horse_comics.py.spec"),
0095                                                         KConfig::SimpleConfig);
0096   KConfigGroup cg = config->group(QSL("<default>"));
0097   cg.writeEntry("ExecPath", QFINDTESTDATA("../fetch/scripts/dark_horse_comics.py"));
0098   fetcher->readConfig(cg);
0099   // don't sync() and save the new path
0100   cg.deleteEntry("ExecPath");
0101 
0102   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0103   QVERIFY(results.size() > 0);
0104   Tellico::Data::EntryPtr entry;  //  results can be randomly ordered, loop until we find the one we want
0105   foreach(Tellico::Data::EntryPtr testEntry, results) {
0106     if(!testEntry->title().contains(QLatin1Char('('))) {
0107       entry = testEntry;
0108       break;
0109     }
0110   }
0111   QVERIFY(entry);
0112 
0113   QCOMPARE(entry->field(QSL("title")), QSL("Masters of the Universe: Masterverse #1"));
0114   QCOMPARE(entry->field(QSL("pub_year")), QSL("2023"));
0115   QCOMPARE(entry->field(QSL("genre")), QSL("Superhero; Action/Adventure"));
0116   QCOMPARE(entry->field(QSL("pages")), QSL("32"));
0117   QCOMPARE(entry->field(QSL("publisher")), QSL("Dark Horse Comics"));
0118   QCOMPARE(entry->field(QSL("writer")), QSL("Tim Seeley"));
0119   QCOMPARE(entry->field(QSL("artist")), QSL("Eddie Nunez; Sergio Aragonés; Kelley Jones"));
0120 }