From 6b80d971b16f81a71fdb583ef796feafa782c20c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 23 Aug 2017 21:39:06 -0600 Subject: Fully tested the account settings * Fixed account and davresource loading. * Use resource type instead of capabilities for loading of the resource. --- framework/src/domain/settings/accountsettings.cpp | 31 +++++++------- framework/src/domain/settings/accountsettings.h | 4 ++ .../src/domain/settings/tests/settingstest.cpp | 50 ++++++++++++++++++++-- 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/framework/src/domain/settings/accountsettings.cpp b/framework/src/domain/settings/accountsettings.cpp index 9f2bcd12..232f7aba 100644 --- a/framework/src/domain/settings/accountsettings.cpp +++ b/framework/src/domain/settings/accountsettings.cpp @@ -61,10 +61,12 @@ void AccountSettings::setAccountIdentifier(const QByteArray &id) mCardDavServer = QString(); mCardDavUsername = QString(); mCardDavPassword = QString(); + mPath = QString(); emit changed(); emit imapResourceChanged(); emit smtpResourceChanged(); emit cardDavResourceChanged(); + emit pathChanged(); load(); @@ -158,7 +160,7 @@ void AccountSettings::saveAccount() }) .exec().waitForFinished(); } else { - qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier; + qDebug() << "Saving account " << mAccountIdentifier; Q_ASSERT(!mAccountIdentifier.isEmpty()); SinkAccount account(mAccountIdentifier); account.setAccountType(mAccountType); @@ -182,12 +184,14 @@ void AccountSettings::loadAccount() mIcon = account.getIcon(); mName = account.getName(); emit changed(); + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to load the account: " << error.errorMessage; }).exec().waitForFinished(); } void AccountSettings::loadImapResource() { - Store::fetchOne(Query().filter(mAccountIdentifier).containsFilter(ResourceCapabilities::Mail::storage)) + Store::fetchOne(Query().filter(mAccountIdentifier).filter("sink.imap")) .then([this](const SinkResource &resource) { mImapIdentifier = resource.identifier(); mImapServer = resource.getProperty("server").toString(); @@ -195,28 +199,25 @@ void AccountSettings::loadImapResource() mImapPassword = resource.getProperty("password").toString(); emit imapResourceChanged(); }).onError([](const KAsync::Error &error) { - qWarning() << "Failed to find the imap resource: " << error.errorMessage; + qWarning() << "Failed to load the imap resource: " << error.errorMessage; }).exec().waitForFinished(); } void AccountSettings::loadMaildirResource() { - Store::fetchOne(Query().filter(mAccountIdentifier).containsFilter(ResourceCapabilities::Mail::storage)) + Store::fetchOne(Query().filter(mAccountIdentifier).filter("sink.maildir")) .then([this](const SinkResource &resource) { mMaildirIdentifier = resource.identifier(); - auto path = resource.getProperty("path").toString(); - if (mPath != path) { - mPath = path; - emit pathChanged(); - } + mPath = resource.getProperty("path").toString(); + emit pathChanged(); }).onError([](const KAsync::Error &error) { - SinkWarning() << "Failed to find the maildir resource: " << error.errorMessage; + SinkWarning() << "Failed to load the maildir resource: " << error.errorMessage; }).exec().waitForFinished(); } void AccountSettings::loadMailtransportResource() { - Store::fetchOne(Query().filter(mAccountIdentifier).containsFilter(ResourceCapabilities::Mail::transport)) + Store::fetchOne(Query().filter(mAccountIdentifier).filter("sink.mailtransport")) .then([this](const SinkResource &resource) { mMailtransportIdentifier = resource.identifier(); mSmtpServer = resource.getProperty("server").toString(); @@ -224,7 +225,7 @@ void AccountSettings::loadMailtransportResource() mSmtpPassword = resource.getProperty("password").toString(); emit smtpResourceChanged(); }).onError([](const KAsync::Error &error) { - SinkWarning() << "Failed to find the smtp resource: " << error.errorMessage; + SinkWarning() << "Failed to load the smtp resource: " << error.errorMessage; }).exec().waitForFinished(); } @@ -238,13 +239,13 @@ void AccountSettings::loadIdentity() mEmailAddress = identity.getAddress(); emit identityChanged(); }).onError([](const KAsync::Error &error) { - SinkWarning() << "Failed to find the identity resource: " << error.errorMessage; + SinkWarning() << "Failed to load the identity: " << error.errorMessage; }).exec().waitForFinished(); } void AccountSettings::loadCardDavResource() { - Store::fetchOne(Query().filter(mAccountIdentifier).containsFilter(ResourceCapabilities::Contact::storage)) + Store::fetchOne(Query().filter(mAccountIdentifier).filter("sink.dav")) .then([this](const SinkResource &resource) { mCardDavIdentifier = resource.identifier(); mCardDavServer = resource.getProperty("server").toString(); @@ -252,7 +253,7 @@ void AccountSettings::loadCardDavResource() mCardDavPassword = resource.getProperty("password").toString(); emit cardDavResourceChanged(); }).onError([](const KAsync::Error &error) { - qWarning() << "Failed to find the CardDAV resource: " << error.errorMessage; + qWarning() << "Failed to load the CardDAV resource: " << error.errorMessage; }).exec().waitForFinished(); } diff --git a/framework/src/domain/settings/accountsettings.h b/framework/src/domain/settings/accountsettings.h index 077b7784..79fc5f72 100644 --- a/framework/src/domain/settings/accountsettings.h +++ b/framework/src/domain/settings/accountsettings.h @@ -42,6 +42,10 @@ class AccountSettings : public QObject Q_PROPERTY(QString smtpUsername MEMBER mSmtpUsername NOTIFY smtpResourceChanged) Q_PROPERTY(QString smtpPassword MEMBER mSmtpPassword NOTIFY smtpResourceChanged) + Q_PROPERTY(QString carddavServer MEMBER mCardDavServer NOTIFY cardDavResourceChanged) + Q_PROPERTY(QString carddavUsername MEMBER mCardDavUsername NOTIFY cardDavResourceChanged) + Q_PROPERTY(QString carddavPassword MEMBER mCardDavPassword NOTIFY cardDavResourceChanged) + Q_PROPERTY(QUrl path READ path WRITE setPath NOTIFY pathChanged) Q_PROPERTY(QValidator* pathValidator READ pathValidator CONSTANT) diff --git a/framework/src/domain/settings/tests/settingstest.cpp b/framework/src/domain/settings/tests/settingstest.cpp index 2d997468..3b8ae69b 100644 --- a/framework/src/domain/settings/tests/settingstest.cpp +++ b/framework/src/domain/settings/tests/settingstest.cpp @@ -24,6 +24,8 @@ public: loadAccount(); loadImapResource(); loadMailtransportResource(); + loadMaildirResource(); + loadCardDavResource(); loadIdentity(); } @@ -32,6 +34,8 @@ public: saveAccount(); saveImapResource(); saveMailtransportResource(); + saveMaildirResource(); + saveCardDavResource(); saveIdentity(); } @@ -39,6 +43,8 @@ public: { removeResource(mMailtransportIdentifier); removeResource(mImapIdentifier); + removeResource(mMaildirIdentifier); + removeResource(mCardDavIdentifier); removeIdentity(); removeAccount(); } @@ -56,7 +62,6 @@ private slots: void testLoad() { - auto accountId = "accountid"; auto imapServer = QString("imapserver"); auto imapUsername = QString("imapName"); auto imapPassword = QString("imapPw"); @@ -65,21 +70,33 @@ private slots: auto smtpPassword = QString("smtpPw"); auto username = QString("username"); auto emailAddress = QString("emailAddress"); + auto path = QString("path"); + auto accountName = QString("accountName"); + auto carddavServer = QString("carddavServer"); + auto carddavUsername = QString("carddavUsername"); + auto carddavPassword = QString("carddavPassword"); TestSettings settings; - settings.setAccountIdentifier(accountId); + settings.setProperty("accountType", "test"); + settings.setProperty("accountName", accountName); settings.setProperty("imapServer", imapServer); settings.setProperty("imapUsername", imapUsername); settings.setProperty("imapPassword", imapPassword); settings.setProperty("smtpServer", smtpServer); settings.setProperty("smtpUsername", smtpUsername); settings.setProperty("smtpPassword", smtpPassword); + settings.setProperty("carddavServer", carddavServer); + settings.setProperty("carddavUsername", carddavUsername); + settings.setProperty("carddavPassword", carddavPassword); + settings.setProperty("path", path); settings.setProperty("userName", username); settings.setProperty("emailAddress", emailAddress); settings.save(); + auto accountId = settings.accountIdentifier(); + Sink::Store::fetchAll(Sink::Query()).then([](const QList &resources) { - QCOMPARE(resources.size(), 2); + QCOMPARE(resources.size(), 4); }) .exec().waitForFinished(); @@ -88,29 +105,45 @@ private slots: TestSettings readSettings; QSignalSpy spy(&readSettings, &TestSettings::imapResourceChanged); QSignalSpy spy1(&readSettings, &TestSettings::smtpResourceChanged); + QSignalSpy spy2(&readSettings, &TestSettings::cardDavResourceChanged); + QSignalSpy spy3(&readSettings, &TestSettings::changed); + QSignalSpy spy4(&readSettings, &TestSettings::pathChanged); readSettings.setAccountIdentifier(accountId); //Once for clear and once for the new setting QTRY_COMPARE(spy.count(), 2); QTRY_COMPARE(spy1.count(), 2); + QTRY_COMPARE(spy2.count(), 2); + QTRY_COMPARE(spy3.count(), 2); + QTRY_COMPARE(spy4.count(), 2); QVERIFY(!readSettings.accountIdentifier().isEmpty()); + QCOMPARE(readSettings.property("accountName").toString(), accountName); QCOMPARE(readSettings.property("imapServer").toString(), imapServer); QCOMPARE(readSettings.property("imapUsername").toString(), imapUsername); QCOMPARE(readSettings.property("imapPassword").toString(), imapPassword); QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer); QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername); QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword); + QCOMPARE(readSettings.property("carddavServer").toString(), carddavServer); + QCOMPARE(readSettings.property("carddavUsername").toString(), carddavUsername); + QCOMPARE(readSettings.property("carddavPassword").toString(), carddavPassword); + QCOMPARE(readSettings.property("path").toString(), path); QCOMPARE(readSettings.property("userName").toString(), username); QCOMPARE(readSettings.property("emailAddress").toString(), emailAddress); } //Modify all settings { + settings.setProperty("accountName", accountName + "mod"); settings.setProperty("imapServer", imapServer + "mod"); settings.setProperty("imapUsername", imapUsername + "mod"); settings.setProperty("imapPassword", imapPassword + "mod"); settings.setProperty("smtpServer", smtpServer + "mod"); settings.setProperty("smtpUsername", smtpUsername + "mod"); settings.setProperty("smtpPassword", smtpPassword + "mod"); + settings.setProperty("carddavServer", carddavServer + "mod"); + settings.setProperty("carddavUsername", carddavUsername + "mod"); + settings.setProperty("carddavPassword", carddavPassword + "mod"); + settings.setProperty("path", path + "mod"); settings.setProperty("userName", username + "mod"); settings.setProperty("emailAddress", emailAddress + "mod"); settings.save(); @@ -121,17 +154,28 @@ private slots: TestSettings readSettings; QSignalSpy spy(&readSettings, &TestSettings::imapResourceChanged); QSignalSpy spy1(&readSettings, &TestSettings::smtpResourceChanged); + QSignalSpy spy2(&readSettings, &TestSettings::cardDavResourceChanged); + QSignalSpy spy3(&readSettings, &TestSettings::changed); + QSignalSpy spy4(&readSettings, &TestSettings::pathChanged); readSettings.setAccountIdentifier(accountId); //Once for clear and once for the new setting QTRY_COMPARE(spy.count(), 2); QTRY_COMPARE(spy1.count(), 2); + QTRY_COMPARE(spy2.count(), 2); + QTRY_COMPARE(spy3.count(), 2); + QTRY_COMPARE(spy4.count(), 2); QVERIFY(!readSettings.accountIdentifier().isEmpty()); + QCOMPARE(readSettings.property("accountName").toString(), accountName + "mod"); QCOMPARE(readSettings.property("imapServer").toString(), imapServer + "mod"); QCOMPARE(readSettings.property("imapUsername").toString(), imapUsername + "mod"); QCOMPARE(readSettings.property("imapPassword").toString(), imapPassword + "mod"); QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer + "mod"); QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername + "mod"); QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword + "mod"); + QCOMPARE(readSettings.property("carddavServer").toString(), carddavServer + "mod"); + QCOMPARE(readSettings.property("carddavUsername").toString(), carddavUsername + "mod"); + QCOMPARE(readSettings.property("carddavPassword").toString(), carddavPassword + "mod"); + QCOMPARE(readSettings.property("path").toString(), path + "mod"); QCOMPARE(readSettings.property("userName").toString(), username + "mod"); QCOMPARE(readSettings.property("emailAddress").toString(), emailAddress + "mod"); } -- cgit v1.2.3