Merge lp:~jamesh/storage-provider-webdav/delete-item into lp:storage-provider-webdav/devel

Proposed by James Henstridge
Status: Merged
Approved by: James Henstridge
Approved revision: 19
Merged at revision: 16
Proposed branch: lp:~jamesh/storage-provider-webdav/delete-item
Merge into: lp:storage-provider-webdav/devel
Prerequisite: lp:~jamesh/storage-provider-webdav/create-folder
Diff against target: 229 lines (+180/-0)
5 files modified
src/CMakeLists.txt (+1/-0)
src/DavProvider.cpp (+3/-0)
src/DeleteHandler.cpp (+45/-0)
src/DeleteHandler.h (+31/-0)
tests/davprovider/davprovider_test.cpp (+100/-0)
To merge this branch: bzr merge lp:~jamesh/storage-provider-webdav/delete-item
Reviewer Review Type Date Requested Status
unity-api-1-bot continuous-integration Approve
Michi Henning (community) Approve
Review via email: mp+310610@code.launchpad.net

Commit message

Implemente the delete_item D-Bus operation.

Description of the change

Implemente the delete_item D-Bus operation.

To post a comment you must log in.
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:18
https://jenkins.canonical.com/unity-api-1/job/lp-storage-provider-webdav-ci/24/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1052
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1059
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/848
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/848/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/848
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/848/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/848
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/848/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/848
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/848/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/848
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/848/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/848
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/848/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/848
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/848/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/848
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/848/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/848
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/848/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-provider-webdav-ci/24/rebuild

review: Approve (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

Looks good! (One minor comment inline.) Can you top-approve after removing the trace please?

review: Approve
19. By James Henstridge

Remove trace.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:19
https://jenkins.canonical.com/unity-api-1/job/lp-storage-provider-webdav-ci/25/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1055
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1062
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/851
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/851/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/851
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/851/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/851
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/851/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/851
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/851/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/851
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/851/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/851
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/851/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/851
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/851/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/851
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/851/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/851
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/851/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-provider-webdav-ci/25/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2016-11-11 07:06:37 +0000
3+++ src/CMakeLists.txt 2016-11-11 07:06:37 +0000
4@@ -6,6 +6,7 @@
5 MultiStatusParser.cpp
6 item_id.cpp
7 CreateFolderHandler.cpp
8+ DeleteHandler.cpp
9 PropFindHandler.cpp
10 ListHandler.cpp
11 LookupHandler.cpp
12
13=== modified file 'src/DavProvider.cpp'
14--- src/DavProvider.cpp 2016-11-11 07:06:37 +0000
15+++ src/DavProvider.cpp 2016-11-11 07:06:37 +0000
16@@ -7,6 +7,7 @@
17 #include "DavDownloadJob.h"
18 #include "DavUploadJob.h"
19 #include "CreateFolderHandler.h"
20+#include "DeleteHandler.h"
21 #include "item_id.h"
22
23 #include <QDateTime>
24@@ -100,6 +101,8 @@
25 boost::future<void> DavProvider::delete_item(
26 string const& item_id, Context const& ctx)
27 {
28+ auto handler = new DeleteHandler(*this, item_id, ctx);
29+ return handler->get_future();
30 }
31
32 boost::future<Item> DavProvider::move(
33
34=== added file 'src/DeleteHandler.cpp'
35--- src/DeleteHandler.cpp 1970-01-01 00:00:00 +0000
36+++ src/DeleteHandler.cpp 2016-11-11 07:06:37 +0000
37@@ -0,0 +1,45 @@
38+#include "DeleteHandler.h"
39+
40+#include <unity/storage/provider/Exceptions.h>
41+
42+#include "DavProvider.h"
43+#include "item_id.h"
44+
45+using namespace std;
46+using namespace unity::storage::provider;
47+
48+DeleteHandler::DeleteHandler(DavProvider const& provider,
49+ string const& item_id,
50+ Context const& ctx)
51+ : provider_(provider), item_id_(item_id)
52+{
53+ QUrl const base_url = provider.base_url(ctx);
54+ QNetworkRequest request(id_to_url(item_id_, base_url));
55+ reply_.reset(provider.send_request(request, QByteArrayLiteral("DELETE"),
56+ nullptr, ctx));
57+ connect(reply_.get(), &QNetworkReply::finished,
58+ this, &DeleteHandler::onFinished);
59+}
60+
61+DeleteHandler::~DeleteHandler() = default;
62+
63+boost::future<void> DeleteHandler::get_future()
64+{
65+ return promise_.get_future();
66+}
67+
68+void DeleteHandler::onFinished()
69+{
70+ auto status = reply_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
71+
72+ if (status / 100 == 2)
73+ {
74+ promise_.set_value();
75+ }
76+ else
77+ {
78+ promise_.set_exception(RemoteCommsException("Error from DELETE: " + to_string(status)));
79+ }
80+
81+ deleteLater();
82+}
83
84=== added file 'src/DeleteHandler.h'
85--- src/DeleteHandler.h 1970-01-01 00:00:00 +0000
86+++ src/DeleteHandler.h 2016-11-11 07:06:37 +0000
87@@ -0,0 +1,31 @@
88+#pragma once
89+
90+#include <QBuffer>
91+#include <QObject>
92+#include <QNetworkReply>
93+#include <unity/storage/provider/ProviderBase.h>
94+
95+#include <memory>
96+
97+class DavProvider;
98+
99+class DeleteHandler : public QObject {
100+ Q_OBJECT
101+public:
102+ DeleteHandler(DavProvider const& provider, std::string const& item_id,
103+ unity::storage::provider::Context const& ctx);
104+ ~DeleteHandler();
105+
106+ boost::future<void> get_future();
107+
108+private Q_SLOTS:
109+ void onFinished();
110+
111+private:
112+ boost::promise<void> promise_;
113+
114+ DavProvider const& provider_;
115+ std::string const item_id_;
116+
117+ std::unique_ptr<QNetworkReply> reply_;
118+};
119
120=== modified file 'tests/davprovider/davprovider_test.cpp'
121--- tests/davprovider/davprovider_test.cpp 2016-11-11 07:06:37 +0000
122+++ tests/davprovider/davprovider_test.cpp 2016-11-11 07:06:37 +0000
123@@ -1024,6 +1024,106 @@
124 }
125 }
126
127+TEST_F(DavProviderTests, delete_item)
128+{
129+ auto account = get_client();
130+ make_file("foo.txt");
131+
132+ shared_ptr<Root> root;
133+ {
134+ QFutureWatcher<QVector<shared_ptr<Root>>> watcher;
135+ QSignalSpy spy(&watcher, &decltype(watcher)::finished);
136+ watcher.setFuture(account->roots());
137+ if (spy.count() == 0)
138+ {
139+ ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
140+ }
141+ auto roots = watcher.result();
142+ ASSERT_EQ(1, roots.size());
143+ root = roots[0];
144+ }
145+
146+ shared_ptr<Item> item;
147+ {
148+ QFutureWatcher<shared_ptr<Item>> watcher;
149+ QSignalSpy spy(&watcher, &decltype(watcher)::finished);
150+ watcher.setFuture(root->get("foo.txt"));
151+ if (spy.count() == 0)
152+ {
153+ ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
154+ }
155+ item = watcher.result();
156+ }
157+
158+ {
159+ QFutureWatcher<void> watcher;
160+ QSignalSpy spy(&watcher, &decltype(watcher)::finished);
161+ watcher.setFuture(item->delete_item());
162+ if (spy.count() == 0)
163+ {
164+ ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
165+ }
166+ watcher.waitForFinished(); // to catch any errors
167+ }
168+
169+ struct stat buf;
170+ EXPECT_EQ(-1, stat(local_file("foo.txt").c_str(), &buf));
171+ EXPECT_EQ(ENOENT, errno);
172+}
173+
174+TEST_F(DavProviderTests, delete_item_not_found)
175+{
176+ auto account = get_client();
177+ make_file("foo.txt");
178+
179+ shared_ptr<Root> root;
180+ {
181+ QFutureWatcher<QVector<shared_ptr<Root>>> watcher;
182+ QSignalSpy spy(&watcher, &decltype(watcher)::finished);
183+ watcher.setFuture(account->roots());
184+ if (spy.count() == 0)
185+ {
186+ ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
187+ }
188+ auto roots = watcher.result();
189+ ASSERT_EQ(1, roots.size());
190+ root = roots[0];
191+ }
192+
193+ shared_ptr<Item> item;
194+ {
195+ QFutureWatcher<shared_ptr<Item>> watcher;
196+ QSignalSpy spy(&watcher, &decltype(watcher)::finished);
197+ watcher.setFuture(root->get("foo.txt"));
198+ if (spy.count() == 0)
199+ {
200+ ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
201+ }
202+ item = watcher.result();
203+ }
204+
205+ ASSERT_EQ(0, unlink(local_file("foo.txt").c_str()));
206+
207+ {
208+ QFutureWatcher<void> watcher;
209+ QSignalSpy spy(&watcher, &decltype(watcher)::finished);
210+ watcher.setFuture(item->delete_item());
211+ if (spy.count() == 0)
212+ {
213+ ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
214+ }
215+ try
216+ {
217+ watcher.waitForFinished(); // to catch any errors
218+ FAIL();
219+ }
220+ catch (RemoteCommsException const& e)
221+ {
222+ EXPECT_EQ("Error from DELETE: 404", e.error_message());
223+ }
224+ }
225+}
226+
227 int main(int argc, char**argv)
228 {
229 QCoreApplication app(argc, argv);

Subscribers

People subscribed via source and target branches