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

[GitHub] willholley closed pull request #899: Mango test configuration

willholley closed pull request #899: Mango test configuration
URL: https://github.com/apache/couchdb/pull/899
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/mango/test/README.md b/src/mango/test/README.md
index 3aace39b09..a7f6350b0a 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 576cec6ebc..ed4cafbe5f 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):


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services