Merge lp:~vds/desktopcouch/fix_delete_record_reconnection into lp:desktopcouch

Proposed by Vincenzo Di Somma
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 179
Merged at revision: 178
Proposed branch: lp:~vds/desktopcouch/fix_delete_record_reconnection
Merge into: lp:desktopcouch
Diff against target: 90 lines (+35/-14)
2 files modified
desktopcouch/records/server_base.py (+13/-10)
desktopcouch/records/tests/test_server.py (+22/-4)
To merge this branch: bzr merge lp:~vds/desktopcouch/fix_delete_record_reconnection
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Vincenzo Di Somma (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+37006@code.launchpad.net

Commit message

Fixes a problem with delete files and reconnection.

Description of the change

Fixes a problem with delete files and reconnection.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good, tests pass

review: Approve
Revision history for this message
Vincenzo Di Somma (vds) wrote :

Three unrelated errors in tests. Looks very good!

===============================================================================
[ERROR]: canonical.tests.test_share_sync.TestShareClientMove.test_syncs_get_changed_file_hash

Traceback (most recent call last):
Failure: ubuntuone.u1sync.main.TreesDiffer:
===============================================================================
[ERROR]: canonical.tests.test_sync.TestClientMove.test_syncs_get_changed_file_hash

Traceback (most recent call last):
Failure: ubuntuone.u1sync.main.TreesDiffer:
===============================================================================
[ERROR]: canonical.tests.test_udf_sync.TestUDFClientMove.test_syncs_get_changed_file_hash

Traceback (most recent call last):
Failure: ubuntuone.u1sync.main.TreesDiffer:

review: Approve
Revision history for this message
Manuel de la Peña (mandel) wrote :

+1 Ran all the tests, no issues. Code looks good to me.

review: Approve
Revision history for this message
Vincenzo Di Somma (vds) wrote :

Sorry, wrong browser window! :(

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/server_base.py'
2--- desktopcouch/records/server_base.py 2010-09-21 08:44:05 +0000
3+++ desktopcouch/records/server_base.py 2010-09-29 15:27:41 +0000
4@@ -202,17 +202,8 @@
5 return self.with_reconnects(self.db.query, map_fun, reduce_fun, language,
6 wrapper, **options)
7
8- def get_record(self, record_id):
9+ def get_record(self, record_id, hide_deleted=True):
10 """Get a record from back end storage."""
11- try:
12- couch_record = self.with_reconnects(self.db.__getitem__, record_id)
13- except ResourceNotFound:
14- return None
15- data = {}
16- if row_is_deleted(couch_record):
17- return None
18- data.update(couch_record)
19- record = self.record_factory(data=data)
20
21 def make_getter(source_db, document_id, attachment_name, content_type):
22 """Closure storing the database for lower levels to use when needed.
23@@ -221,11 +212,23 @@
24 return source_db.get_attachment(document_id, attachment_name), \
25 content_type
26 return getter
27+
28+ try:
29+ couch_record = self.with_reconnects(self.db.__getitem__, record_id)
30+ except ResourceNotFound:
31+ return None
32+ data = {}
33+
34+ if row_is_deleted(couch_record) and hide_deleted:
35+ return None
36+ data.update(couch_record)
37+ record = self.record_factory(data=data)
38 if "_attachments" in data:
39 for att_name, att_attributes in data["_attachments"].iteritems():
40 record.attach_by_reference(att_name,
41 make_getter(self.db, record_id, att_name,
42 att_attributes["content_type"]))
43+
44 return record
45
46 def put_record(self, record):
47
48=== modified file 'desktopcouch/records/tests/test_server.py'
49--- desktopcouch/records/tests/test_server.py 2010-09-22 13:02:08 +0000
50+++ desktopcouch/records/tests/test_server.py 2010-09-29 15:27:41 +0000
51@@ -114,6 +114,24 @@
52 retrieved_record = self.database.get_record(record_id)
53 self.assertEqual(0, retrieved_record['record_number'])
54
55+ def test_get_deleted_record(self):
56+ """Test getting a record."""
57+ record = Record({'record_number': 0}, record_type="http://example.com/")
58+ record_id = self.database.put_record(record)
59+ self.database.delete_record(record_id)
60+ retrieved_record = self.database.get_record(record_id)
61+ #FIXME the record has to be None
62+ self.assertEqual(retrieved_record, None)
63+
64+ def test_get_deleted_record_not_hidden(self):
65+ """Test getting a record."""
66+ record = Record({'record_number': 0}, record_type="http://example.com/")
67+ record_id = self.database.put_record(record)
68+ self.database.delete_record(record_id)
69+ retrieved_record = self.database.get_record(record_id=record_id,
70+ hide_deleted=False)
71+ self.assertEqual(0, retrieved_record['record_number'])
72+
73 def test_put_record(self):
74 """Test putting a record."""
75 record = Record({'record_number': 0}, record_type="http://example.com/")
76@@ -149,10 +167,10 @@
77 record = Record({'record_number': 0}, record_type="http://example.com/")
78 record_id = self.database.put_record(record)
79 self.database.delete_record(record_id)
80- ###self.maybe_die() # should be able to survive couchdb death
81- deleted_record = self.database._server[self.dbname][record_id]
82- #deleted_record = self.database.get_record(record_id)
83- self.assert_(deleted_record['application_annotations']['Ubuntu One'][
84+ self.maybe_die() # should be able to survive couchdb death
85+ deleted_record = self.database.get_record(record_id=record_id,
86+ hide_deleted=False)
87+ self.assert_(deleted_record.application_annotations['Ubuntu One'][
88 'private_application_annotations']['deleted'])
89
90 def test_delete_and_recreate_record(self):

Subscribers

People subscribed via source and target branches