[office/tellico/4.2] src: Restore Entrez fetcher test
Robby Stephenson <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit aa1c5f502dd29b8be1ed4d381d081193cb3da2fa by Robby Stephenson.
Committed on 02/08/2026 at 18:29.
Pushed by rstephenson into branch '4.2'.
Restore Entrez fetcher test
M +16 -6 src/fetch/entrezfetcher.cpp
M +6 -0 src/tests/CMakeLists.txt
M +2 -1 src/tests/entrezfetchertest.cpp
https://invent.kde.org/office/tellico/-/commit/aa1c5f502dd29b8be1ed4d381d081193cb3da2fa
diff --git a/src/fetch/entrezfetcher.cpp b/src/fetch/entrezfetcher.cpp
index 88d17d02e..6577f1a28 100644
--- a/src/fetch/entrezfetcher.cpp
+++ b/src/fetch/entrezfetcher.cpp
@@ -148,7 +148,7 @@ void EntrezFetcher::search() {
u.setQuery(q);
m_step = Step::Search;
-// myLog() << "search url: " << u.url();
+ myLog() << "Reading" << u.toDisplayString();
m_job = KIO::storedGet(u, KIO::NoReload, KIO::HideProgressInfo);
KJobWidgets::setWindow(m_job, GUI::Proxy::widget());
connect(m_job.data(), &KJob::result,
@@ -182,7 +182,7 @@ void EntrezFetcher::slotComplete(KJob*) {
return;
}
- QByteArray data = m_job->data();
+ const QByteArray data = m_job->data();
if(data.isEmpty()) {
myDebug() << "no data";
stop();
@@ -241,13 +241,23 @@ void EntrezFetcher::searchResults(const QByteArray& data_) {
} else if(e.tagName() == QLatin1String("WebEnv")) {
m_webEnv = e.text();
++count;
+ } else if(e.tagName() == QLatin1String("ERROR")) {
+ const auto error = e.text();
+ message(error, MessageHandler::Error);
+ myLog() << "EntrezFetcher -" << error;
+ stop();
+ return;
}
if(count >= 3) {
break; // found them all
}
}
-
- doSummary();
+ if(m_total == 0) {
+ myLog() << "0 results found";
+ stop();
+ } else {
+ doSummary();
+ }
}
void EntrezFetcher::doSummary() {
@@ -380,7 +390,7 @@ Tellico::Data::EntryPtr EntrezFetcher::fetchEntryHook(uint uid_) {
}
f1.close();
#endif
- QString str = m_xsltHandler->applyStylesheet(xmlOutput);
+ const QString str = m_xsltHandler->applyStylesheet(xmlOutput);
if(str.isEmpty()) {
// might be an API error, and message is in JSON
QJsonDocument doc = QJsonDocument::fromJson(xmlOutput.toUtf8());
@@ -431,7 +441,7 @@ Tellico::Data::EntryPtr EntrezFetcher::fetchEntryHook(uint uid_) {
.namedItem(QStringLiteral("ObjUrl"))
.namedItem(QStringLiteral("Url"));
if(!linkNode.isNull()) {
- QString u = linkNode.toElement().text();
+ const QString u = linkNode.toElement().text();
// myDebug() << u;
if(!u.isEmpty()) {
if(!coll->hasField(QStringLiteral("url"))) {
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index a5d0e23f2..6c7a82db0 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -677,6 +677,12 @@ ecm_add_test(dvdfrfetchertest.cpp
LINK_LIBRARIES fetcherstest ${TELLICO_TEST_LIBS}
)
+ecm_add_test(entrezfetchertest.cpp
+ ../fetch/entrezfetcher.cpp
+ TEST_NAME entrezfetchertest
+ LINK_LIBRARIES fetcherstest ${TELLICO_TEST_LIBS}
+)
+
ecm_add_test(externalfetchertest.cpp
../fetch/execexternalfetcher.cpp
../translators/bibteximporter.cpp
diff --git a/src/tests/entrezfetchertest.cpp b/src/tests/entrezfetchertest.cpp
index 12d5c7f39..393d77d60 100644
--- a/src/tests/entrezfetchertest.cpp
+++ b/src/tests/entrezfetchertest.cpp
@@ -80,8 +80,9 @@ void EntrezFetcherTest::testTitle() {
}
void EntrezFetcherTest::testAuthor() {
+ // searching "Rachel R Stine" strictly as author doesn't provide results
Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Person,
- QStringLiteral("Rachel R Stine"));
+ QStringLiteral("Stine RR"));
Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::EntrezFetcher(this));
Tellico::Data::EntryList results = DO_FETCH(fetcher, request);