Merge lp:~jderose/microfiber/usercouch into lp:microfiber

Proposed by Jason Gerard DeRose
Status: Merged
Merged at revision: 85
Proposed branch: lp:~jderose/microfiber/usercouch
Merge into: lp:microfiber
Diff against target: 139 lines (+30/-49)
3 files modified
debian/control (+3/-1)
setup.py (+10/-28)
test_microfiber.py (+17/-20)
To merge this branch: bzr merge lp:~jderose/microfiber/usercouch
Reviewer Review Type Date Requested Status
Jason Gerard DeRose Approve
Review via email: mp+77988@code.launchpad.net

Description of the change

This merge:

 * Changes the LiveTestCase base class so it automatically runs the live tests when `usercouch` is available

 * Each live test is now run with a throw-away CouchDB started with `usercouch.misc.TempCouch`

 * Revamps the setup.py test options: --no-live will skip the lives tests even when `usercouch` is available, and --oauth will setup the TempCouch instances with oauth so the internal oauth 1a support gets tested

To post a comment you must log in.
Revision history for this message
Jason Gerard DeRose (jderose) wrote :

I'm going to push this through so I can further verify that we can run live CouchDB tests okay on the build servers.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2011-09-30 06:27:17 +0000
3+++ debian/control 2011-10-03 18:29:23 +0000
4@@ -2,7 +2,9 @@
5 Section: python
6 Priority: optional
7 Maintainer: Jason Gerard DeRose <jderose@novacut.com>
8-Build-Depends: debhelper (>= 8.9), python3 (>= 3.2), python-sphinx
9+Build-Depends: debhelper (>= 8.9), python3 (>= 3.2),
10+ python3-usercouch,
11+ python-sphinx,
12 Standards-Version: 3.9.2
13 X-Python-Version: 3.2
14 X-Python3-Version: 3.2
15
16=== modified file 'setup.py'
17--- setup.py 2011-10-03 01:51:09 +0000
18+++ setup.py 2011-10-03 18:29:23 +0000
19@@ -39,46 +39,28 @@
20 import microfiber
21
22
23-TEST_DB = 'test_microfiber'
24-
25-
26 class Test(Command):
27 description = 'run unit tests and doc tests'
28
29 user_options = [
30- ('live', None, 'also run live tests against running CouchDB'),
31- ('dc3', None, 'test with dc3 using `dc3-control GetEnv`'),
32- ('basic', None, 'force dc3 couch tests to use basic auth'),
33- ('url=', None,
34- 'live test server URL; default is {!r}'.format(microfiber.SERVER)
35- ),
36- ('db=', None,
37- 'live test database name; default is {!r}'.format(TEST_DB)
38- ),
39+ ('no-live', None, 'skip live tests against tmp CouchDB instances'),
40+ ('oauth', None, 'run live tests using oauth instead of basic auth'),
41 ]
42
43 def initialize_options(self):
44- self.live = 0
45- self.dc3 = 0
46- self.basic = 0
47- self.url = microfiber.SERVER
48- self.db = TEST_DB
49+ self.no_live = 0
50+ self.oauth = 0
51
52 def finalize_options(self):
53- t = urlparse(self.url)
54- if t.scheme not in ('http', 'https') or t.netloc == '':
55- raise SystemExit('ERROR: invalid url: {!r}'.format(self.url))
56+ pass
57
58 def run(self):
59 # Possibly set environ variables for live test:
60- if self.live or self.dc3:
61- os.environ['MICROFIBER_TEST_DB'] = self.db
62- if self.live:
63- os.environ['MICROFIBER_TEST_URL'] = self.url
64- if self.dc3:
65- os.environ['MICROFIBER_TEST_DC3'] = 'true'
66- if self.basic:
67- os.environ['MICROFIBER_TEST_BASIC_AUTH'] = 'true'
68+ if self.no_live:
69+ os.environ['MICROFIBER_TEST_NO_LIVE'] = 'true'
70+
71+ if self.oauth:
72+ os.environ['MICROFIBER_TEST_OAUTH'] = 'true'
73
74 pynames = ['microfiber', 'test_microfiber']
75
76
77=== modified file 'test_microfiber.py'
78--- test_microfiber.py 2011-10-03 01:51:09 +0000
79+++ test_microfiber.py 2011-10-03 18:29:23 +0000
80@@ -30,7 +30,6 @@
81 from base64 import b64encode, b64decode, b32encode, b32decode
82 from copy import deepcopy
83 import json
84-import subprocess
85 import time
86 import io
87 import tempfile
88@@ -39,6 +38,11 @@
89 from urllib.parse import urlparse, urlencode
90 from http.client import HTTPConnection, HTTPSConnection
91
92+try:
93+ import usercouch.misc
94+except ImportError:
95+ usercouch = None
96+
97 import microfiber
98 from microfiber import NotFound, MethodNotAllowed, Conflict, PreconditionFailed
99
100@@ -481,27 +485,20 @@
101
102
103 class LiveTestCase(TestCase):
104-
105- def getvar(self, key):
106- try:
107- return os.environ[key]
108- except KeyError:
109- self.skipTest('{} not set'.format(key))
110+ db = 'test_microfiber'
111
112 def setUp(self):
113- self.db = self.getvar('MICROFIBER_TEST_DB')
114- if os.environ.get('MICROFIBER_TEST_DC3') == 'true':
115- self.env = microfiber.dc3_env()
116- if os.environ.get('MICROFIBER_TEST_BASIC_AUTH') == 'true':
117- # Force use of basic auth even if env['oauth'] exists
118- self.env['oauth'] = None
119- else:
120- self.env = {'url': self.getvar('MICROFIBER_TEST_URL')}
121- cb = microfiber.CouchBase(self.env)
122- try:
123- cb.delete(self.db)
124- except microfiber.NotFound:
125- pass
126+ if os.environ.get('MICROFIBER_TEST_NO_LIVE') == 'true':
127+ self.skipTest('called with --no-live')
128+ if usercouch is None:
129+ self.skipTest('`usercouch` not installed')
130+ self.oauth = (os.environ.get('MICROFIBER_TEST_OAUTH') == 'true')
131+ self.tmpcouch = usercouch.misc.TempCouch()
132+ self.env = self.tmpcouch.bootstrap(self.oauth)
133+
134+ def tearDown(self):
135+ self.tmpcouch = None
136+ self.env = None
137
138
139 class TestCouchBaseLive(LiveTestCase):

Subscribers

People subscribed via source and target branches