Merge lp://qastaging/~thisfred/desktopcouch/fix-missing-import into lp://qastaging/desktopcouch

Proposed by Eric Casteleijn
Status: Merged
Approved by: Stuart Langridge
Approved revision: 80
Merged at revision: not available
Proposed branch: lp://qastaging/~thisfred/desktopcouch/fix-missing-import
Merge into: lp://qastaging/desktopcouch
Diff against target: 54 lines
2 files modified
desktopcouch/pair/couchdb_pairing/couchdb_io.py (+8/-5)
desktopcouch/pair/tests/test_couchdb_io.py (+7/-0)
To merge this branch: bzr merge lp://qastaging/~thisfred/desktopcouch/fix-missing-import
Reviewer Review Type Date Requested Status
Stuart Langridge (community) Approve
Mark G. Saye (community) Approve
Review via email: mp+12953@code.qastaging.launchpad.net

Commit message

Fixed broken mk_uri function and added a test for it.

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

This fixes two pretty bad errors: mk_uri uses urllib which was not imported, and had a parenthesis in the wrong place. Test added.

80. By Eric Casteleijn

test with path

Revision history for this message
Mark G. Saye (markgsaye) wrote :

Code looks good, new tests that test untested code are always good, especially when they pass!

review: Approve
Revision history for this message
Stuart Langridge (sil) wrote :

> This fixes two pretty bad errors: mk_uri uses urllib which was not imported,
> and had a parenthesis in the wrong place. Test added.

Good catch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/pair/couchdb_pairing/couchdb_io.py'
2--- desktopcouch/pair/couchdb_pairing/couchdb_io.py 2009-09-30 15:52:57 +0000
3+++ desktopcouch/pair/couchdb_pairing/couchdb_io.py 2009-10-07 13:29:11 +0000
4@@ -18,6 +18,7 @@
5 """Communicate with CouchDB."""
6
7 import logging
8+import urllib
9
10 from desktopcouch import find_port as desktopcouch_find_port
11 from desktopcouch.records import server
12@@ -33,10 +34,12 @@
13 def mkuri(hostname, port, has_ssl=False, path="", auth_pair=None):
14 """Create a URI from parts."""
15 protocol = "https" if has_ssl else "http"
16- auth = (":".join(map(urllib.quote, auth_pair) + "@")) if auth_pair else ""
17- port = int(port)
18- uri = "%(protocol)s://%(auth)s%(hostname)s:%(port)d/%(path)s" % locals()
19- return uri
20+ if auth_pair:
21+ auth = (":".join(map(urllib.quote, auth_pair)) + "@")
22+ else:
23+ auth = ""
24+ port = str(port)
25+ return "%s://%s%s:%s/%s" % (protocol, auth, hostname, port, path)
26
27 def _get_db(name, create=True, uri=None):
28 """Get (and create?) a database."""
29@@ -224,7 +227,7 @@
30 target_ssl, target_oauth)
31 logging.debug("db exists, and we're ready to replicate")
32 except:
33- logging.exception("can't create/verify %r %s:%d oauth=%s",
34+ logging.exception("can't create/verify %r %s:%d oauth=%s",
35 target_database, target_host, target_port, target_oauth)
36
37 try:
38
39=== modified file 'desktopcouch/pair/tests/test_couchdb_io.py'
40--- desktopcouch/pair/tests/test_couchdb_io.py 2009-09-24 13:46:17 +0000
41+++ desktopcouch/pair/tests/test_couchdb_io.py 2009-10-07 13:29:11 +0000
42@@ -113,6 +113,13 @@
43 self.assertEquals(len(got), 1)
44 self.assertEquals(got, again)
45
46+ def test_mkuri(self):
47+ uri = couchdb_io.mkuri(
48+ 'fnord.org', 55241, has_ssl=True, path='a/b/c',
49+ auth_pair=('f o o', 'b=a=r'))
50+ self.assertEquals(
51+ 'https://f%20o%20o:b%3Da%3Dr@fnord.org:55241/a/b/c', uri)
52+
53 def Xtest_replication_good(self):
54 pass
55

Subscribers

People subscribed via source and target branches