You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wi...@apache.org on 2017/10/18 10:25:56 UTC

[couchdb] branch master updated: Configurable Mango test parameters (#899)

This is an automated email from the ASF dual-hosted git repository.

willholley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 69ebe61  Configurable Mango test parameters (#899)
69ebe61 is described below

commit 69ebe617d17747249a7bca01a45d33e27b5ac4b9
Author: Will Holley <wi...@gmail.com>
AuthorDate: Wed Oct 18 11:25:53 2017 +0100

    Configurable Mango test parameters (#899)
    
    The Mango test suite previously assumed that the target
    CouchDB for testing was at http://127.0.0.1:15984 with
    username "testuser" and password "testpass".
    
    It's helpful to be able to override these defaults
    so we can test against other environments, including those
    that do not support basic authentication. This commit
    adds support for overriding the defaults using environment
    variables.
    
    Now that we enable tests to be run against remote
    clusters, default to n=1 at database creation time
    to prevent assertion failures due to eventual
    consistency between replicas.
---
 src/mango/test/README.md | 14 +++++++++++++-
 src/mango/test/mango.py  | 34 ++++++++++++++++++++++++++--------
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/src/mango/test/README.md b/src/mango/test/README.md
index 3aace39..a7f6350 100644
--- a/src/mango/test/README.md
+++ b/src/mango/test/README.md
@@ -14,4 +14,16 @@ To run an individual test suite:
     nosetests --nocapture test/12-use-correct-index.py 
 
 To run the tests with text index support:
-    MANGO_TEXT_INDEXES=1 nosetests --nocapture test
\ No newline at end of file
+    MANGO_TEXT_INDEXES=1 nosetests --nocapture test
+
+
+Test configuration
+==================
+
+The following environment variables can be used to configure the test fixtures:
+
+COUCH_HOST - root url (including port) of the CouchDB instance to run the tests against. Default is "http://127.0.0.1:15984".
+COUCH_USER - CouchDB username (with admin premissions). Default is "testuser"
+COUCH_PASSWORD -  CouchDB password. Default is "testpass"
+COUCH_AUTH_HEADER - Optional Authorization header value. If specified, this is used instead of basic authentication with the username/password variables above.
+MANGO_TEXT_INDEXES - Set to "1" to run the tests only applicable to text indexes
diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py
index 576cec6..ed4cafb 100644
--- a/src/mango/test/mango.py
+++ b/src/mango/test/mango.py
@@ -29,26 +29,44 @@ def random_db_name():
 def has_text_service():
     return os.environ.get('MANGO_TEXT_INDEXES') == '1'
 
+def get_from_environment(key, default):
+    value = os.environ.get(key)
+    return value if value is not None else default
+
 
 class Database(object):
-    def __init__(self, host, port, dbname, auth=None):
-        self.host = host
-        self.port = port
+    def __init__(self, dbname,
+                 host="127.0.0.1", port="15984",
+                 user='testuser', password='testpass'):
+        root_url = get_from_environment('COUCH_HOST', "http://{}:{}".format(host, port))
+        auth_header = get_from_environment('COUCH_AUTH_HEADER', None)
+        user = get_from_environment('COUCH_USER', user)
+        password = get_from_environment('COUCH_PASSWORD', password)
+
+        self.root_url = root_url
         self.dbname = dbname
         self.sess = requests.session()
-        self.sess.auth = ('testuser', 'testpass')
+
+        # allow explicit auth header to be set to enable testing
+        # against deployments where basic auth isn't available
+        if auth_header is not None:
+            self.sess.headers["Authorization"] = auth_header
+        else:
+            self.sess.auth = (user, password)
+
         self.sess.headers["Content-Type"] = "application/json"
 
+
     @property
     def url(self):
-        return "http://{}:{}/{}".format(self.host, self.port, self.dbname)
+        return "{}/{}".format(self.root_url, self.dbname)
 
     def path(self, parts):
         if isinstance(parts, ("".__class__, u"".__class__)):
             parts = [parts]
         return "/".join([self.url] + parts)
 
-    def create(self, q=1, n=3):
+    def create(self, q=1, n=1):
         r = self.sess.get(self.url)
         if r.status_code == 404:
             r = self.sess.put(self.url, params={"q":q, "n": n})
@@ -206,7 +224,7 @@ class UsersDbTests(unittest.TestCase):
 
     @classmethod
     def setUpClass(klass):
-        klass.db = Database("127.0.0.1", "15984", "_users")
+        klass.db = Database("_users")
         user_docs.setup_users(klass.db)
 
     def setUp(self):
@@ -217,7 +235,7 @@ class DbPerClass(unittest.TestCase):
 
     @classmethod
     def setUpClass(klass):
-        klass.db = Database("127.0.0.1", "15984", random_db_name())
+        klass.db = Database(random_db_name())
         klass.db.create(q=1, n=3)
 
     def setUp(self):

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].