From bea8add2cbb4ad0c96ae356b4e4f25b1f527cdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Thu, 31 Jul 2014 11:49:33 +0200 Subject: Do not create custom backend for tst_files It should be faster and more stable, at cost of more complex backend configuration, Change-Id: I3b2e202c9e69ac7ffec37b5626e343cfcc818024 Reviewed-by: Andras Becsi --- tests/auto/files/tst_files.cpp | 94 ++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 54 deletions(-) diff --git a/tests/auto/files/tst_files.cpp b/tests/auto/files/tst_files.cpp index cf26117..f66cb2a 100644 --- a/tests/auto/files/tst_files.cpp +++ b/tests/auto/files/tst_files.cpp @@ -57,10 +57,8 @@ class tst_Files: public QObject { Q_OBJECT - QString _backendName; - EnginioTests::EnginioBackendManager _backendManager; - QByteArray _backendId; - + QString _id; + EnginioClient _client; public slots: void error(EnginioReply *reply) { qDebug() << "\n\n### ERROR"; @@ -70,32 +68,29 @@ public slots: } private slots: - void initTestCase(); - void cleanupTestCase(); + void initTestCase() + { + QObject::connect(&_client, SIGNAL(error(EnginioReply *)), this, SLOT(error(EnginioReply *))); + _client.setBackendId("5376019e698b3c6ad500095a"); + } + + void cleanup() + { + if (!_id.isEmpty()) { + QJsonObject obj; + obj["objectType"] = QString::fromUtf8("objects.FilesFileUploadDownload"); + obj["id"] = _id; + EnginioReply *reply = _client.remove(obj); + QTRY_VERIFY(reply->isFinished()); + CHECK_NO_ERROR(reply); + } + _id.clear(); + } + void fileUploadDownload_data(); void fileUploadDownload(); }; -void tst_Files::initTestCase() -{ - if (EnginioTests::TESTAPP_URL.isEmpty()) - QFAIL("Needed environment variable ENGINIO_API_URL is not set!"); - - _backendName = QStringLiteral("Files") + QString::number(QDateTime::currentMSecsSinceEpoch()); - QVERIFY(_backendManager.createBackend(_backendName)); - - QJsonObject apiKeys = _backendManager.backendApiKeys(_backendName, EnginioTests::TESTAPP_ENV); - _backendId = apiKeys["backendId"].toString().toUtf8(); - - QVERIFY(!_backendId.isEmpty()); - - EnginioTests::prepareTestObjectType(_backendName); -} - -void tst_Files::cleanupTestCase() -{ - QVERIFY(_backendManager.removeBackend(_backendName)); -} void tst_Files::fileUploadDownload_data() { @@ -127,36 +122,28 @@ void tst_Files::fileUploadDownload() { QFETCH(int, chunkSize); - EnginioClient client; - QObject::connect(&client, SIGNAL(error(EnginioReply *)), this, SLOT(error(EnginioReply *))); - client.setBackendId(_backendId); - client.setServiceUrl(EnginioTests::TESTAPP_URL); - if (chunkSize > 0) { - EnginioClientConnectionPrivate *clientPrivate = EnginioClientConnectionPrivate::get(&client); + EnginioClientConnectionPrivate *clientPrivate = EnginioClientConnectionPrivate::get(&_client); clientPrivate->_uploadChunkSize = chunkSize; } - QSignalSpy spyError(&client, SIGNAL(error(EnginioReply*))); + QSignalSpy spyError(&_client, SIGNAL(error(EnginioReply*))); //![upload-create-object] QJsonObject obj; - obj["objectType"] = QString::fromUtf8("objects.%1").arg(EnginioTests::CUSTOM_OBJECT1); - obj["title"] = QString::fromUtf8("Object With File"); - const EnginioReply* createReply = client.create(obj); + obj["objectType"] = QString::fromUtf8("objects.FilesFileUploadDownload"); + const EnginioReply* createReply = _client.create(obj); //![upload-create-object] QVERIFY(createReply); QTRY_VERIFY(createReply->isFinished()); CHECK_NO_ERROR(createReply); QCOMPARE(spyError.count(), 0); - QCOMPARE(createReply->networkError(), QNetworkReply::NoError); QJsonObject data = createReply->data(); QVERIFY(!data.isEmpty()); - QCOMPARE(data["title"], obj["title"]); QCOMPARE(data["objectType"], obj["objectType"]); - QString id = data["id"].toString(); - QVERIFY(!id.isEmpty()); + _id = data["id"].toString(); + QVERIFY(!_id.isEmpty()); QString fileName = QStringLiteral("test.png"); QString filePath = QStringLiteral(TEST_FILE_PATH); @@ -168,8 +155,8 @@ void tst_Files::fileUploadDownload() { //![upload] QJsonObject object; - object["id"] = id; - object["objectType"] = QString::fromUtf8("objects.%1").arg(EnginioTests::CUSTOM_OBJECT1); + object["id"] = _id; + object["objectType"] = QString::fromUtf8("objects.FilesFileUploadDownload"); object["propertyName"] = QStringLiteral("fileAttachment"); QJsonObject fileObject; @@ -178,7 +165,7 @@ void tst_Files::fileUploadDownload() QJsonObject uploadJson; uploadJson[QStringLiteral("targetFileProperty")] = object; uploadJson[QStringLiteral("file")] = fileObject; - const EnginioReply *responseUpload = client.uploadFile(uploadJson, QUrl(filePath)); + const EnginioReply *responseUpload = _client.uploadFile(uploadJson, QUrl(filePath)); //![upload] QVERIFY(responseUpload); @@ -197,11 +184,10 @@ void tst_Files::fileUploadDownload() QJsonObject obj2; obj2 = QJsonDocument::fromJson( "{\"include\": {\"fileAttachment\": {}}," - "\"objectType\": \"objects." + EnginioTests::CUSTOM_OBJECT1.toUtf8() + "\"," - "\"query\": {\"id\": \"" + id.toUtf8() + "\"}}").object(); + "\"objectType\": \"objects.FilesFileUploadDownload\"," + "\"query\": {\"id\": \"" + _id.toUtf8() + "\"}}").object(); - const EnginioReply *reply = client.query(obj2); - QVERIFY(reply); + const EnginioReply *reply = _client.query(obj2); QTRY_VERIFY(reply->isFinished()); CHECK_NO_ERROR(reply); QCOMPARE(spyError.count(), 0); @@ -216,7 +202,7 @@ void tst_Files::fileUploadDownload() while (!resultObject["fileAttachment"].isObject() && --ok) { qDebug() << resultObject; QTest::qWait(1000); // We failed the test, but still we need to gather some debug data. - const EnginioReply *reply = client.query(obj2); + const EnginioReply *reply = _client.query(obj2); QTRY_VERIFY(reply->isFinished()); CHECK_NO_ERROR(reply); QCOMPARE(spyError.count(), 0); @@ -244,7 +230,7 @@ void tst_Files::fileUploadDownload() QJsonObject object; object["id"] = fileId; // ID of an existing object with attached file - const EnginioReply *replyDownload = client.downloadUrl(object); + const EnginioReply *replyDownload = _client.downloadUrl(object); //![download] QVERIFY(replyDownload); @@ -257,7 +243,7 @@ void tst_Files::fileUploadDownload() QVERIFY(!downloadData["expiresAt"].toString().isEmpty()); QNetworkRequest req; req.setUrl(QUrl(downloadData["expiringUrl"].toString())); - QNetworkReply *reply = client.networkManager()->get(req); + QNetworkReply *reply = _client.networkManager()->get(req); QTRY_VERIFY(reply->isFinished()); if (reply->error() != QNetworkReply::NoError) { // the test has failed already, let's printout some debugging information @@ -277,7 +263,7 @@ void tst_Files::fileUploadDownload() { QJsonObject fileObject; fileObject.insert("id", fileId); - EnginioReply *fileInfo = client.query(fileObject, Enginio::FileOperation); + EnginioReply *fileInfo = _client.query(fileObject, Enginio::FileOperation); QVERIFY(fileInfo); QTRY_VERIFY(fileInfo->isFinished()); CHECK_NO_ERROR(fileInfo); @@ -293,7 +279,7 @@ void tst_Files::fileUploadDownload() int count = 0; while (thumbnailStatus == "processing" && ++count < 20) { QTest::qWait(1000); - fileInfo = client.query(fileObject, Enginio::FileOperation); + fileInfo = _client.query(fileObject, Enginio::FileOperation); QVERIFY(fileInfo); QTRY_VERIFY(fileInfo->isFinished()); CHECK_NO_ERROR(fileInfo); @@ -317,7 +303,7 @@ void tst_Files::fileUploadDownload() object["id"] = fileId; // ID of an existing object with attached file object[EnginioString::variant] = QStringLiteral("thumbnail"); - const EnginioReply* replyDownload = client.downloadUrl(object); + const EnginioReply *replyDownload = _client.downloadUrl(object); QVERIFY(replyDownload); QTRY_VERIFY(replyDownload->isFinished()); @@ -330,7 +316,7 @@ void tst_Files::fileUploadDownload() QNetworkRequest req; req.setUrl(QUrl(downloadData["expiringUrl"].toString())); - QNetworkReply *reply = client.networkManager()->get(req); + QNetworkReply *reply = _client.networkManager()->get(req); QTRY_VERIFY(reply->isFinished()); if (reply->error() != QNetworkReply::NoError) { // the test has failed already, let's printout some debugging information -- cgit v1.2.1