Merge lp:~cmiller/desktopcouch/abstract-wrappers into lp:desktopcouch

Proposed by Chad Miller
Status: Merged
Approved by: Chad Miller
Approved revision: 180
Merged at revision: 179
Proposed branch: lp:~cmiller/desktopcouch/abstract-wrappers
Merge into: lp:desktopcouch
Diff against target: 47 lines (+19/-0)
2 files modified
desktopcouch/records/server_base.py (+3/-0)
desktopcouch/records/tests/test_server.py (+16/-0)
To merge this branch: bzr merge lp:~cmiller/desktopcouch/abstract-wrappers
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Vincenzo Di Somma (community) Approve
Review via email: mp+37142@code.launchpad.net

Commit message

The view wrapper that assists with reconnecting did not implement attributes that some clients (like Lernid) use. Now, catch any attribute access on the wrapper and pass it through to the proxied object. This should make the proxy object functionally identical to the destination object. (LP: #652095)

To post a comment you must log in.
180. By Chad Miller

Use wrapper instead of exact proxying.

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

Code looks good, tests pass.

review: Approve

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-29 14:34:31 +0000
3+++ desktopcouch/records/server_base.py 2010-09-30 15:43:36 +0000
4@@ -466,6 +466,9 @@
5 return self.view_with_reconnects(wrapper.obj.__len__,
6 wrapper.obj)
7
8+ def __getattr__(wrapper, key):
9+ return self.with_reconnects(getattr, wrapper.obj, key)
10+
11 def __getitem__(wrapper, key):
12 return ReconnectingViewWrapper(wrapper.obj.__getitem__, key)
13
14
15=== modified file 'desktopcouch/records/tests/test_server.py'
16--- desktopcouch/records/tests/test_server.py 2010-09-29 14:48:41 +0000
17+++ desktopcouch/records/tests/test_server.py 2010-09-30 15:43:36 +0000
18@@ -286,6 +286,9 @@
19
20 results = self.database.get_records(create_view=True)
21
22+ self.assertTrue(8 <= len(results.rows)) # our 8, plus callers' data
23+ self.assertIn("record_type", results.rows[0].value)
24+
25 for row in results[good_record_type]: # index notation
26 self.assertTrue(row.id in record_ids_we_care_about)
27 record_ids_we_care_about.remove(row.id)
28@@ -389,6 +392,19 @@
29 # Ensure position different.
30 self.assertEqual(saved_position + 1, self.database._changes_since)
31
32+ def test_view_wrapper_has_all_attributes(self):
33+ design_doc = "test_view_wrapper_has_all_attributes"
34+ view1_name = "unit_tests_are_great_yeah"
35+
36+ map_js = """function(doc) { emit(doc._id, null) }"""
37+
38+ self.database.add_view(view1_name, map_js, None, design_doc)
39+ view = self.database.execute_view(view1_name, design_doc)
40+
41+ for attr_name in dir(view.obj):
42+ # This works because hasattr actually calls getattr.
43+ self.assertTrue(hasattr(view, attr_name))
44+
45 def test_report_changes_all_ops_give_known_keys(self):
46 def rep(**kwargs):
47 self.failUnless("changes" in kwargs)

Subscribers

People subscribed via source and target branches