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
=== modified file 'desktopcouch/records/server_base.py'
--- desktopcouch/records/server_base.py 2010-09-29 14:34:31 +0000
+++ desktopcouch/records/server_base.py 2010-09-30 15:43:36 +0000
@@ -466,6 +466,9 @@
466 return self.view_with_reconnects(wrapper.obj.__len__,466 return self.view_with_reconnects(wrapper.obj.__len__,
467 wrapper.obj)467 wrapper.obj)
468468
469 def __getattr__(wrapper, key):
470 return self.with_reconnects(getattr, wrapper.obj, key)
471
469 def __getitem__(wrapper, key):472 def __getitem__(wrapper, key):
470 return ReconnectingViewWrapper(wrapper.obj.__getitem__, key)473 return ReconnectingViewWrapper(wrapper.obj.__getitem__, key)
471474
472475
=== modified file 'desktopcouch/records/tests/test_server.py'
--- desktopcouch/records/tests/test_server.py 2010-09-29 14:48:41 +0000
+++ desktopcouch/records/tests/test_server.py 2010-09-30 15:43:36 +0000
@@ -286,6 +286,9 @@
286286
287 results = self.database.get_records(create_view=True)287 results = self.database.get_records(create_view=True)
288288
289 self.assertTrue(8 <= len(results.rows)) # our 8, plus callers' data
290 self.assertIn("record_type", results.rows[0].value)
291
289 for row in results[good_record_type]: # index notation292 for row in results[good_record_type]: # index notation
290 self.assertTrue(row.id in record_ids_we_care_about)293 self.assertTrue(row.id in record_ids_we_care_about)
291 record_ids_we_care_about.remove(row.id)294 record_ids_we_care_about.remove(row.id)
@@ -389,6 +392,19 @@
389 # Ensure position different.392 # Ensure position different.
390 self.assertEqual(saved_position + 1, self.database._changes_since)393 self.assertEqual(saved_position + 1, self.database._changes_since)
391394
395 def test_view_wrapper_has_all_attributes(self):
396 design_doc = "test_view_wrapper_has_all_attributes"
397 view1_name = "unit_tests_are_great_yeah"
398
399 map_js = """function(doc) { emit(doc._id, null) }"""
400
401 self.database.add_view(view1_name, map_js, None, design_doc)
402 view = self.database.execute_view(view1_name, design_doc)
403
404 for attr_name in dir(view.obj):
405 # This works because hasattr actually calls getattr.
406 self.assertTrue(hasattr(view, attr_name))
407
392 def test_report_changes_all_ops_give_known_keys(self):408 def test_report_changes_all_ops_give_known_keys(self):
393 def rep(**kwargs):409 def rep(**kwargs):
394 self.failUnless("changes" in kwargs)410 self.failUnless("changes" in kwargs)

Subscribers

People subscribed via source and target branches