Permalink
Browse files

[Tests] Add first scraper online tests

 - add tests for scraper searches
 - fix ADE scraper
  • Loading branch information...
bugwelle committed Aug 30, 2018
1 parent 30148a7 commit c2a9dbcddbf738deeccd3f1b8110236615cc4bdc
View
@@ -61,8 +61,8 @@ ICON = MediaElch.icns
RC_FILE = MediaElch.rc
QMAKE_INFO_PLIST = MediaElch.plist
SOURCES += main.cpp\
main/MainWindow.cpp \
SOURCES += main.cpp \
main/MainWindow.cpp \
data/Movie.cpp \
data/MovieFileSearcher.cpp \
mediaCenterPlugins/XbmcXml.cpp \
@@ -474,3 +474,25 @@ TRANSLATIONS += \
i18n/MediaElch_ru.ts \
i18n/MediaElch_ja.ts \
i18n/MediaElch_da.ts
test {
message(Test build)
QT += testlib
TARGET = mediaelch-test
HEADERS += test/qtCatchHelper.h
SOURCES -= main.cpp
SOURCES += test/main.cpp \
test/scrapers/testAdultDvdEmpire.cpp \
test/scrapers/testAEBN.cpp \
test/scrapers/testHotMovies.cpp \
test/scrapers/testIMDb.cpp \
test/scrapers/testKinoDe.cpp \
test/scrapers/testTMDb.cpp \
test/scrapers/testVideoBuster.cpp
} else {
message(Normal build)
}
@@ -83,7 +83,7 @@ QList<ScraperSearchResult> AdultDvdEmpire::parseSearch(QString html)
QTextDocument doc;
QList<ScraperSearchResult> results;
int offset = 0;
QRegExp rx(R"re(<a href="([^"]*)"\n *title="([^"]*)" Category="List Page" Label="Title">)re");
QRegExp rx(R"re(<a href="([^"]*)"[\n\t\s]*title="([^"]*)" Category="List Page" Label="Title">)re");
rx.setMinimal(true);
while ((offset = rx.indexIn(html, offset)) != -1) {
doc.setHtml(rx.cap(2).trimmed());
View
@@ -91,14 +91,18 @@ void IMDB::search(QString searchStr)
QRegExp rx("^tt\\d+$");
if (rx.exactMatch(searchStr)) {
QUrl url = QUrl(QStringLiteral("https://www.imdb.com/title/%1/").arg(searchStr).toUtf8());
QNetworkReply *reply = m_qnam.get(QNetworkRequest(url));
QNetworkRequest request(url);
request.setRawHeader("Accept-Language", "en"); // todo: add language dropdown in settings
QNetworkReply *reply = m_qnam.get(request);
new NetworkReplyWatcher(this, reply);
connect(reply, &QNetworkReply::finished, this, &IMDB::onSearchIdFinished);
} else {
QUrl url = QUrl::fromEncoded(
QStringLiteral("https://www.imdb.com/find?s=tt&ttype=ft&ref_=fn_ft&q=%1").arg(encodedSearch).toUtf8());
QNetworkReply *reply = m_qnam.get(QNetworkRequest(url));
QNetworkRequest request(url);
request.setRawHeader("Accept-Language", "en"); // todo: add language dropdown in settings
QNetworkReply *reply = m_qnam.get(request);
new NetworkReplyWatcher(this, reply);
connect(reply, &QNetworkReply::finished, this, &IMDB::onSearchFinished);
}
View
@@ -0,0 +1,11 @@
#define CATCH_CONFIG_RUNNER
#include "thirdParty/catch2/catch.hpp"
#include <QApplication>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
const int res = Catch::Session().run(argc, argv);
return res;
}
View
@@ -0,0 +1,42 @@
#include "globals/Globals.h"
#include <QEventLoop>
#include <QList>
#include <QString>
#include <ostream>
// Some operators for better warnings with Catch2
inline std::ostream &operator<<(std::ostream &os, const QByteArray &value)
{
return os << '"' << (value.isEmpty() ? "" : value.constData()) << '"';
}
inline std::ostream &operator<<(std::ostream &os, const QLatin1String &value)
{
return os << '"' << value.latin1() << '"';
}
inline std::ostream &operator<<(std::ostream &os, const QString &value)
{
return os << value.toLocal8Bit();
}
/**
* @brief Searches for searchStr and returns the results synchronously using the given Scraper.
*/
template<class ScraperInterfaceT>
QList<ScraperSearchResult> searchScraperSync(ScraperInterfaceT &scraper, QString search)
{
QList<ScraperSearchResult> results;
QEventLoop loop;
loop.connect(&scraper, &ScraperInterfaceT::searchDone, [&](QList<ScraperSearchResult> res) {
results = res;
loop.quit();
});
scraper.search(search);
loop.exec();
return results;
}
View
@@ -0,0 +1,12 @@
#include <QtTest>
#include "testIMDb.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
TestIMDb testIMDb;
return QTest::qExec(&testIMDb, argc, argv);
}
View
@@ -0,0 +1,16 @@
#include "test/qtCatchHelper.h"
#include "thirdParty/catch2/catch.hpp"
#include "scrapers/AEBN.h"
TEST_CASE("AEBN returns valid search results", "[scraper][AEBN][search][requiresInternet]")
{
AEBN AEBN;
SECTION("Search by movie name returns correct results")
{
const auto scraperResults = searchScraperSync(AEBN, "Magic Mike XXXL");
REQUIRE(scraperResults.length() >= 1);
REQUIRE(scraperResults[0].name == "Magic Mike XXXL: A Hardcore Parody");
}
}
@@ -0,0 +1,16 @@
#include "test/qtCatchHelper.h"
#include "thirdParty/catch2/catch.hpp"
#include "scrapers/AdultDvdEmpire.h"
TEST_CASE("AdultDvdEmpire returns valid search results", "[scraper][AdultDvdEmpire][search][requiresInternet]")
{
AdultDvdEmpire adultDvdEmpire;
SECTION("Search by movie name returns correct results")
{
const auto scraperResults = searchScraperSync(adultDvdEmpire, "Magic Mike XXXL");
REQUIRE(scraperResults.length() >= 1);
REQUIRE(scraperResults[0].name == "Magic Mike XXXL");
}
}
@@ -0,0 +1,16 @@
#include "test/qtCatchHelper.h"
#include "thirdParty/catch2/catch.hpp"
#include "scrapers/HotMovies.h"
TEST_CASE("HotMovies returns valid search results", "[scraper][HotMovies][search][requiresInternet]")
{
HotMovies HotMovies;
SECTION("Search by movie name returns correct results")
{
const auto scraperResults = searchScraperSync(HotMovies, "Magic Mike XXXL");
REQUIRE(scraperResults.length() >= 1);
REQUIRE(scraperResults[0].name == "Magic Mike XXXL: A Hardcore Parody");
}
}
View
@@ -0,0 +1,17 @@
#include "test/qtCatchHelper.h"
#include "thirdParty/catch2/catch.hpp"
#include "scrapers/IMDB.h"
TEST_CASE("IMDb returns valid search results", "[scraper][IMDb][search][requiresInternet]")
{
IMDB imdb;
SECTION("Search by movie name returns correct results")
{
const auto scraperResults = searchScraperSync(imdb, "Finding Dory");
REQUIRE(scraperResults.length() >= 2);
REQUIRE(scraperResults[0].name == "Finding Dory");
REQUIRE(scraperResults[1].name == "Finding Glory");
}
}
@@ -0,0 +1,16 @@
#include "test/qtCatchHelper.h"
#include "thirdParty/catch2/catch.hpp"
#include "scrapers/KinoDe.h"
TEST_CASE("KinoDe returns valid search results", "[scraper][KinoDe][search][requiresInternet]")
{
KinoDe KinoDe;
SECTION("Search by movie name returns correct results")
{
const auto scraperResults = searchScraperSync(KinoDe, "Findet Dorie");
REQUIRE(scraperResults.length() >= 1);
REQUIRE(scraperResults[0].name == "Findet Dorie");
}
}
View
@@ -0,0 +1,17 @@
#include "test/qtCatchHelper.h"
#include "thirdParty/catch2/catch.hpp"
#include "scrapers/TMDb.h"
TEST_CASE("TMDb returns valid search results", "[scraper][TMDb][search][requiresInternet]")
{
TMDb TMDb;
SECTION("Search by movie name returns correct results")
{
const auto scraperResults = searchScraperSync(TMDb, "Finding Dory");
REQUIRE(scraperResults.length() >= 2);
REQUIRE(scraperResults[0].name == "Finding Dory");
REQUIRE(scraperResults[1].name == "Marine Life Interviews");
}
}
@@ -0,0 +1,16 @@
#include "test/qtCatchHelper.h"
#include "thirdParty/catch2/catch.hpp"
#include "scrapers/VideoBuster.h"
TEST_CASE("VideoBuster returns valid search results", "[scraper][VideoBuster][search][requiresInternet]")
{
VideoBuster VideoBuster;
SECTION("Search by movie name returns correct results")
{
const auto scraperResults = searchScraperSync(VideoBuster, "Findet Dorie");
REQUIRE(scraperResults.length() >= 1);
REQUIRE(scraperResults[0].name == "Findet Dorie");
}
}
Oops, something went wrong.

0 comments on commit c2a9dbc

Please sign in to comment.