Merge lp:~leonardr/lazr.restfulclient/delete-entry into lp:lazr.restfulclient

Proposed by Leonard Richardson
Status: Merged
Approved by: Aaron Bentley
Approved revision: 101
Merged at revision: not available
Proposed branch: lp:~leonardr/lazr.restfulclient/delete-entry
Merge into: lp:lazr.restfulclient
Diff against target: 81 lines (+34/-1)
4 files modified
src/lazr/restfulclient/NEWS.txt (+4/-1)
src/lazr/restfulclient/_browser.py (+1/-0)
src/lazr/restfulclient/docs/entries.txt (+25/-0)
src/lazr/restfulclient/resource.py (+4/-0)
To merge this branch: bzr merge lp:~leonardr/lazr.restfulclient/delete-entry
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+24421@code.launchpad.net

Description of the change

This branch rectifies a major oversight: there was no non-hacky way to DELETE a lazr.restful entry resource from lazr.restfulclient.

To get the tests to work I had to create
https://code.edge.launchpad.net/~leonardr/lazr.restful/fix-remove-recipe.

To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

Oh: I originally wanted to implement __del__ instead of lp_delete, but upon reading the documentation I saw that __del__ deletes the _variable_ assignment, not necessarily the underlying object. So it's not an appropriate overload.

Revision history for this message
Leonard Richardson (leonardr) wrote :

The fix-remove-recipe branch seems not to be necessary--there was an intermittent problem with my setup that's now gone away.

Revision history for this message
Leonard Richardson (leonardr) wrote :
Revision history for this message
Aaron Bentley (abentley) :
review: Approve
102. By Leonard Richardson

Updated release date.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restfulclient/NEWS.txt'
2--- src/lazr/restfulclient/NEWS.txt 2010-04-27 19:18:57 +0000
3+++ src/lazr/restfulclient/NEWS.txt 2010-05-03 16:45:39 +0000
4@@ -2,13 +2,16 @@
5 NEWS for lazr.restfulclient
6 ===========================
7
8-0.9.16 (2010-04-27)
9+0.9.16 (2010-05-03)
10 ===================
11
12 - If a server returns a 502 or 503 error code, lazr.restfulclient
13 will retry its request a configurable number of times in hopes that
14 the error is transient.
15
16+ - It's now possible to invoke lazr.restful destructor methods, with
17+ the lp_delete() method.
18+
19 0.9.15 (2010-04-27)
20 ====================
21
22
23=== modified file 'src/lazr/restfulclient/_browser.py'
24--- src/lazr/restfulclient/_browser.py 2010-04-29 13:17:40 +0000
25+++ src/lazr/restfulclient/_browser.py 2010-05-03 16:45:39 +0000
26@@ -355,6 +355,7 @@
27 def delete(self, url):
28 """DELETE the resource at the given URL."""
29 self._request(url, method='DELETE')
30+ return None
31
32 def patch(self, url, representation, headers=None):
33 """PATCH the object at url with the updated representation."""
34
35=== modified file 'src/lazr/restfulclient/docs/entries.txt'
36--- src/lazr/restfulclient/docs/entries.txt 2010-04-14 19:02:48 +0000
37+++ src/lazr/restfulclient/docs/entries.txt 2010-05-03 16:45:39 +0000
38@@ -469,3 +469,28 @@
39 ...
40 ValueError: You tried to access a resource that you don't have the
41 server-side permission to see.
42+
43+Deleting an entry
44+=================
45+
46+Some entries can be deleted with the lp_delete method.
47+
48+ >>> recipe = service.recipes[6]
49+ >>> print recipe.lp_delete()
50+ None
51+
52+A deleted entry no longer exists.
53+
54+ >>> recipe.lp_refresh()
55+ Traceback (most recent call last):
56+ ...
57+ HTTPError: HTTP Error 404: Not Found
58+ ...
59+
60+Some entries can't be deleted.
61+
62+ >>> cookbook.lp_delete()
63+ Traceback (most recent call last):
64+ ...
65+ HTTPError: HTTP Error 405: Method Not Allowed
66+ ...
67
68=== modified file 'src/lazr/restfulclient/resource.py'
69--- src/lazr/restfulclient/resource.py 2010-04-27 19:16:14 +0000
70+++ src/lazr/restfulclient/resource.py 2010-05-03 16:45:39 +0000
71@@ -609,6 +609,10 @@
72 return '<%s at %s>' % (
73 URI(self.resource_type_link).fragment, self.self_link)
74
75+ def lp_delete(self):
76+ """Delete the resource."""
77+ return self._root._browser.delete(URI(self.self_link))
78+
79 def __str__(self):
80 """Return the URL to the resource."""
81 return self.self_link

Subscribers

People subscribed via source and target branches