Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test: Add a configuration with admin enabled

Session API works only when not in Admin party, so a dedicated
configuration for it is required.
  • Loading branch information...
commit 510ea0c260f55a05f21d1735e49b9d316b39fde4 1 parent 6745a57
Daniel Truemper truemped authored nailor committed
Showing with 63 additions and 10 deletions.
  1. +8 −0 test/conf/local_session.ini
  2. +55 −10 test/couch_util.py
8 test/conf/local_session.ini
View
@@ -0,0 +1,8 @@
+[couch_httpd_auth]
+secret = bd42ab447cdaecb52f2b2dc3bda6ec10
+
+[httpd]
+port = 8922
+
+[admins]
+admin = -hashed-609ab15a7189304d14390b48876180f498a38008,35cee0c36d7a4bd5f1ba460eda70454f
65 test/couch_util.py
View
@@ -39,11 +39,14 @@
from urllib2 import URLError
import nose.tools
-from tornado.httpclient import HTTPClient
+from tornado.httpclient import HTTPClient, HTTPError
baseurl = ''
-def setup():
+_proc = None
+
+
+def setup_with_admin():
global _proc, baseurl
try:
shutil.rmtree('tmp')
@@ -56,16 +59,58 @@ def setup():
os.mkdir('tmp')
os.mkdir('tmp/couch')
- dbdir = 'tmp/couch'
- ini = 'tmp/local.ini'
- log = 'tmp/couch.log'
+ port = 8922
+ baseurl = 'http://localhost:%d/' % (port)
+
+ dir = os.path.dirname(__file__)
+
+ cmdline = 'couchdb -n -a %s -a %s' % (
+ os.path.join(dir, 'conf/local.ini'),
+ os.path.join(dir, 'conf/local_session.ini'),
+ )
+
+ null = open('/dev/null', 'w')
+ _proc = subprocess.Popen(
+ cmdline, shell=True, stdout=null, stderr=null
+ )
+
+ # Wait for couchdb to start
+ time.sleep(1)
+ # Wait for couchdb to start
+
+ while True:
+ try:
+ f = request.urlopen('http://localhost:%s' % port)
+ except URLError:
+ continue
+ try:
+ json.loads(f.read().decode('utf-8'))
+ except ValueError:
+ continue
+ # Got a sensible response
+ break
+
+
+def setup():
+ global _proc, baseurl
+ try:
+ shutil.rmtree('tmp')
+ except OSError:
+ # Python 3
+ err = sys.exc_info()[1]
+ if err.errno != errno.ENOENT:
+ raise
+
+ os.mkdir('tmp')
+ os.mkdir('tmp/couch')
port = 8921
- baseurl = 'http://localhost:%d/' % port
+ baseurl = 'http://localhost:%d/' % (port)
- cmdline = 'couchdb -n -a test/conf/local.ini'
+ dir = os.path.dirname(__file__)
+ cmdline = 'couchdb -n -a %s' % os.path.join(dir, 'conf/local.ini')
null = open('/dev/null', 'w')
- _proc = subprocess.Popen(cmdline, shell=True)#, stdout=null, stderr=null)
+ _proc = subprocess.Popen(cmdline, shell=True, stdout=null, stderr=null)
# Wait for couchdb to start
time.sleep(1)
@@ -73,7 +118,7 @@ def setup():
while True:
try:
- f = request.urlopen(baseurl)
+ f = request.urlopen('http://localhost:%s' % port)
except URLError:
continue
try:
@@ -191,7 +236,7 @@ def inner(*args, **kwargs):
dbs = json.loads(response.body.decode('utf-8'))
except ValueError:
print >> sys.stderr, \
- "CouchDB's response was invalid JSON: %s" % db_string
+ "CouchDB's response was invalid JSON: %s" % response.body
sys.exit(2)
for database in dbs:
Please sign in to comment.
Something went wrong with that request. Please try again.