File indexing completed on 2024-05-19 16:19:08

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_FETCH1(fetcher, request, 1);
0072 
0073   QCOMPARE(results.size(), 1);
0074   // the first entry had better be the right one
0075   Tellico::Data::EntryPtr entry = results.at(0);
0076 
0077   QCOMPARE(entry->field(QSL("title")), QSL("Axe Cop: Bad Guy Earth #1"));
0078   QCOMPARE(entry->field(QSL("pub_year")), QSL("2011"));
0079   QCOMPARE(entry->field(QSL("genre")), QSL("Humor; Kids"));
0080   QCOMPARE(entry->field(QSL("pages")), QSL("32"));
0081   QCOMPARE(entry->field(QSL("publisher")), QSL("Dark Horse Comics"));
0082   QCOMPARE(entry->field(QSL("writer")), QSL("Malachai Nicolle"));
0083   QCOMPARE(entry->field(QSL("artist")), QSL("Ethan Nicolle"));
0084   QVERIFY(!entry->field(QSL("comments")).isEmpty());
0085   QVERIFY(!entry->field(QSL("cover")).isEmpty());
0086   QVERIFY(!entry->field(QSL("cover")).contains(QLatin1Char('/')));
0087   QVERIFY(!Tellico::ImageFactory::imageById(entry->field(QSL("cover"))).isNull());
0088 }