1 /***************************************************************************
2 Copyright (C) 2011 Robby Stephenson <robby@periapsis.org>
3 ***************************************************************************/
4
5 /***************************************************************************
6 * *
7 * This program is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU General Public License as *
9 * published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) version 3 or any later version *
11 * accepted by the membership of KDE e.V. (or its successor approved *
12 * by the membership of KDE e.V.), which shall act as a proxy *
13 * defined in Section 14 of version 3 of the license. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
22 * *
23 ***************************************************************************/
24
25 #include "darkhorsefetchertest.h"
26
27 #include "../fetch/execexternalfetcher.h"
28 #include "../entry.h"
29 #include "../collections/comicbookcollection.h"
30 #include "../collectionfactory.h"
31 #include "../images/imagefactory.h"
32 #include "../images/image.h"
33 #include "../fieldformat.h"
34
35 #include <KSharedConfig>
36 #include <KConfigGroup>
37
38 #include <QTest>
39 #include <QStandardPaths>
40
QTEST_GUILESS_MAIN(DarkHorseFetcherTest)41 QTEST_GUILESS_MAIN( DarkHorseFetcherTest )
42
43 #define QSL(x) QStringLiteral(x)
44
45 DarkHorseFetcherTest::DarkHorseFetcherTest() : AbstractFetcherTest() {
46 }
47
initTestCase()48 void DarkHorseFetcherTest::initTestCase() {
49 const QString python = QStandardPaths::findExecutable(QSL("python"));
50 if(python.isEmpty()) {
51 QSKIP("This test requires python", SkipAll);
52 }
53
54 Tellico::ImageFactory::init();
55 Tellico::RegisterCollection<Tellico::Data::ComicBookCollection> registerComic(Tellico::Data::Collection::ComicBook, "comicbook");
56 }
57
testComic()58 void DarkHorseFetcherTest::testComic() {
59 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::Title,
60 QSL("axe cop: bad guy earth #1"));
61 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ExecExternalFetcher(this));
62
63 KSharedConfig::Ptr config = KSharedConfig::openConfig(QFINDTESTDATA("../fetch/scripts/dark_horse_comics.py.spec"),
64 KConfig::SimpleConfig);
65 KConfigGroup cg = config->group(QSL("<default>"));
66 cg.writeEntry("ExecPath", QFINDTESTDATA("../fetch/scripts/dark_horse_comics.py"));
67 fetcher->readConfig(cg);
68 // don't sync() and save the new path
69 cg.deleteEntry("ExecPath");
70
71 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
72
73 QCOMPARE(results.size(), 1);
74 // the first entry had better be the right one
75 Tellico::Data::EntryPtr entry = results.at(0);
76
77 QCOMPARE(entry->field(QSL("title")), QSL("Axe Cop: Bad Guy Earth #1"));
78 QCOMPARE(entry->field(QSL("pub_year")), QSL("2011"));
79 QCOMPARE(entry->field(QSL("genre")), QSL("Humor; Kids"));
80 QCOMPARE(entry->field(QSL("pages")), QSL("32"));
81 QCOMPARE(entry->field(QSL("publisher")), QSL("Dark Horse Comics"));
82 QCOMPARE(entry->field(QSL("writer")), QSL("Malachai Nicolle"));
83 QCOMPARE(entry->field(QSL("artist")), QSL("Ethan Nicolle"));
84 QVERIFY(!entry->field(QSL("comments")).isEmpty());
85 QVERIFY(!entry->field(QSL("cover")).isEmpty());
86 QVERIFY(!entry->field(QSL("cover")).contains(QLatin1Char('/')));
87 QVERIFY(!Tellico::ImageFactory::imageById(entry->field(QSL("cover"))).isNull());
88 }
89