File indexing completed on 2024-05-12 05:09:57
0001 /*************************************************************************** 0002 Copyright (C) 2023 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 <config.h> 0026 #include "discogstest.h" 0027 0028 #include "../translators/discogsimporter.h" 0029 #include "../collections/musiccollection.h" 0030 #include "../collectionfactory.h" 0031 #include "../images/imagefactory.h" 0032 0033 #include <KConfig> 0034 #include <KSharedConfig> 0035 #include <KConfigGroup> 0036 #include <KLocalizedString> 0037 0038 #include <QTest> 0039 #include <QNetworkInterface> 0040 #include <QStandardPaths> 0041 0042 QTEST_GUILESS_MAIN( DiscogsTest ) 0043 0044 static bool hasNetwork() { 0045 #ifdef ENABLE_NETWORK_TESTS 0046 foreach(const QNetworkInterface& net, QNetworkInterface::allInterfaces()) { 0047 if(net.flags().testFlag(QNetworkInterface::IsUp) && !net.flags().testFlag(QNetworkInterface::IsLoopBack)) { 0048 return true; 0049 } 0050 } 0051 #endif 0052 return false; 0053 } 0054 0055 void DiscogsTest::initTestCase() { 0056 QStandardPaths::setTestModeEnabled(true); 0057 KLocalizedString::setApplicationDomain("tellico"); 0058 Tellico::RegisterCollection<Tellico::Data::MusicCollection> registerMusic(Tellico::Data::Collection::Album, "album"); 0059 Tellico::ImageFactory::init(); 0060 } 0061 0062 void DiscogsTest::testImport() { 0063 if(!hasNetwork()) QSKIP("This test requires network access", SkipSingle); 0064 0065 Tellico::Import::DiscogsImporter imp; 0066 QVERIFY(!imp.canImport(Tellico::Data::Collection::Book)); 0067 QVERIFY(imp.canImport(Tellico::Data::Collection::Album)); 0068 0069 KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); 0070 KConfigGroup cg(config, QStringLiteral("ImportOptions - Discogs")); 0071 cg.writeEntry("User ID", QStringLiteral("tellico-robby")); 0072 // need to add token to get images 0073 config->sync(); 0074 imp.setConfig(config); 0075 0076 Tellico::Data::CollPtr coll(imp.collection()); 0077 QVERIFY(coll); 0078 QCOMPARE(coll->type(), Tellico::Data::Collection::Album); 0079 0080 Tellico::Data::EntryList entries = coll->entries(); 0081 QVERIFY(!entries.isEmpty()); 0082 Tellico::Data::EntryPtr entry = entries.at(0); 0083 QVERIFY(entry); 0084 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Les Misérables")); 0085 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1985")); 0086 QCOMPARE(entry->field(QStringLiteral("medium")), QStringLiteral("Compact Disc")); 0087 QCOMPARE(entry->field(QStringLiteral("label")), QStringLiteral("First Night Records")); 0088 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Musical")); 0089 QCOMPARE(entry->field(QStringLiteral("artist")), QStringLiteral("Alain Boublil; Claude-Michel Schönberg")); 0090 QCOMPARE(entry->field(QStringLiteral("rating")), QStringLiteral("4")); 0091 0092 // QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0093 // QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0094 // QVERIFY(!entry->field(QStringLiteral("comments")).isEmpty()); 0095 }