You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2017/07/13 16:28:18 UTC

[couchdb] branch master updated (11afc8b -> 779f00e)

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

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


    from 11afc8b  Fix timeout in couchdb_views_test for couchdb_1283
     new d909cd2  Pass UserCtx to fabric's all_docs from mango query
     new 6d9673c  Send user_ctx to query_view
     new 022925a  Send user_ctx to fabric's open_doc
     new 779f00e  Add tests for queries against _users db

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/mango/src/mango_cursor_view.erl     |  9 ++--
 src/mango/src/mango_httpd.erl           |  3 +-
 src/mango/src/mango_util.erl            |  6 ++-
 src/mango/test/13-users-db-find-test.py | 83 +++++++++++++++++++++++++++++++++
 src/mango/test/mango.py                 | 11 +++++
 src/mango/test/user_docs.py             | 36 ++++++++++++++
 6 files changed, 143 insertions(+), 5 deletions(-)
 create mode 100644 src/mango/test/13-users-db-find-test.py

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

[couchdb] 02/04: Send user_ctx to query_view

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6d9673cbbafec2ec07c63eef2c1ed7f5b75f384e
Author: Eric Avdey <ei...@eiri.ca>
AuthorDate: Fri Jul 7 16:52:36 2017 -0300

    Send user_ctx to query_view
---
 src/mango/src/mango_cursor_view.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl
index 4763277..538877c 100644
--- a/src/mango/src/mango_cursor_view.erl
+++ b/src/mango/src/mango_cursor_view.erl
@@ -98,7 +98,7 @@ execute(#cursor{db = Db, index = Idx} = Cursor0, UserFun, UserAcc) ->
                     % Normal view
                     DDoc = ddocid(Idx),
                     Name = mango_idx:name(Idx),
-                    fabric:query_view(Db, DDoc, Name, CB, Cursor, Args)
+                    fabric:query_view(Db, DbOpts, DDoc, Name, CB, Cursor, Args)
             end,
             case Result of
                 {ok, LastCursor} ->

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

[couchdb] 01/04: Pass UserCtx to fabric's all_docs from mango query

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d909cd2128f2ebba333cedf6cfe3d49e9ad573ed
Author: Eric Avdey <ei...@eiri.ca>
AuthorDate: Fri Jun 30 15:37:49 2017 -0300

    Pass UserCtx to fabric's all_docs from mango query
---
 src/mango/src/mango_cursor_view.erl | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl
index e97311c..4763277 100644
--- a/src/mango/src/mango_cursor_view.erl
+++ b/src/mango/src/mango_cursor_view.erl
@@ -85,11 +85,14 @@ execute(#cursor{db = Db, index = Idx} = Cursor0, UserFun, UserAcc) ->
                 end_key = mango_idx:end_key(Idx, Cursor#cursor.ranges),
                 include_docs = true
             },
-            Args = apply_opts(Cursor#cursor.opts, BaseArgs),
+            #cursor{opts = Opts} = Cursor,
+            Args = apply_opts(Opts, BaseArgs),
+            UserCtx = couch_util:get_value(user_ctx, Opts, #user_ctx{}),
+            DbOpts = [{user_ctx, UserCtx}],
             Result = case mango_idx:def(Idx) of
                 all_docs ->
                     CB = fun ?MODULE:handle_all_docs_message/2,
-                    fabric:all_docs(Db, CB, Cursor, Args);
+                    fabric:all_docs(Db, DbOpts, CB, Cursor, Args);
                 _ ->
                     CB = fun ?MODULE:handle_message/2,
                     % Normal view

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

[couchdb] 04/04: Add tests for queries against _users db

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 779f00e2bd8fa6a59be112418801def559623c8a
Author: Eric Avdey <ei...@eiri.ca>
AuthorDate: Fri Jul 7 16:54:59 2017 -0300

    Add tests for queries against _users db
---
 src/mango/test/13-users-db-find-test.py | 83 +++++++++++++++++++++++++++++++++
 src/mango/test/mango.py                 | 11 +++++
 src/mango/test/user_docs.py             | 36 ++++++++++++++
 3 files changed, 130 insertions(+)

diff --git a/src/mango/test/13-users-db-find-test.py b/src/mango/test/13-users-db-find-test.py
new file mode 100644
index 0000000..d8d32ad
--- /dev/null
+++ b/src/mango/test/13-users-db-find-test.py
@@ -0,0 +1,83 @@
+# -*- coding: latin-1 -*-
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
+import mango, requests
+
+
+class UsersDbFindTests(mango.UsersDbTests):
+
+    def test_simple_find(self):
+        docs = self.db.find({"name": {"$eq": "demo02"}})
+        assert len(docs) == 1
+        assert docs[0]["_id"] == "org.couchdb.user:demo02"
+
+    def test_multi_cond_and(self):
+        self.db.create_index(["type", "roles"])
+        docs = self.db.find({"type": "user", "roles": {"$eq": ["reader"]}})
+        assert len(docs) == 1
+        assert docs[0]["_id"] == "org.couchdb.user:demo02"
+
+    def test_multi_cond_or(self):
+        docs = self.db.find({
+                "$and":[
+                    {"type": "user"},
+                    {"$or": [
+                        {"order": 1},
+                        {"order": 3}
+                    ]}
+                ]
+            })
+        assert len(docs) == 2
+        assert docs[0]["_id"] == "org.couchdb.user:demo01"
+        assert docs[1]["_id"] == "org.couchdb.user:demo03"
+
+    def test_sort(self):
+        self.db.create_index(["order", "name"])
+        selector = {"name": {"$gt": "demo01"}}
+        docs1 = self.db.find(selector, sort=[{"order": "asc"}])
+        docs2 = list(sorted(docs1, key=lambda d: d["order"]))
+        assert docs1 is not docs2 and docs1 == docs2
+
+        docs1 = self.db.find(selector, sort=[{"order": "desc"}])
+        docs2 = list(reversed(sorted(docs1, key=lambda d: d["order"])))
+        assert docs1 is not docs2 and docs1 == docs2
+
+    def test_fields(self):
+        selector = {"name": {"$eq": "demo02"}}
+        docs = self.db.find(selector, fields=["name", "order"])
+        assert len(docs) == 1
+        assert sorted(docs[0].keys()) == ["name", "order"]
+
+    def test_empty(self):
+        docs = self.db.find({})
+        assert len(docs) == 3
+
+
+class UsersDbIndexFindTests(UsersDbFindTests):
+
+    def setUp(self):
+        self.db.create_index(["name"])
+
+    def test_multi_cond_and(self):
+        self.db.create_index(["type", "roles"])
+        super(UsersDbIndexFindTests, self).test_multi_cond_and()
+
+    def test_multi_cond_or(self):
+        self.db.create_index(["type", "order"])
+        super(UsersDbIndexFindTests, self).test_multi_cond_or()
+
+    def test_sort(self):
+        self.db.create_index(["order", "name"])
+        super(UsersDbIndexFindTests, self).test_sort()
+
diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py
index da51180..bd34edc 100644
--- a/src/mango/test/mango.py
+++ b/src/mango/test/mango.py
@@ -192,6 +192,17 @@ class Database(object):
             return None
 
 
+class UsersDbTests(unittest.TestCase):
+
+    @classmethod
+    def setUpClass(klass):
+        klass.db = Database("127.0.0.1", "15984", "_users")
+        user_docs.setup_users(klass.db)
+
+    def setUp(self):
+        self.db = self.__class__.db
+
+
 class DbPerClass(unittest.TestCase):
 
     @classmethod
diff --git a/src/mango/test/user_docs.py b/src/mango/test/user_docs.py
index e2f1705..41d8602 100644
--- a/src/mango/test/user_docs.py
+++ b/src/mango/test/user_docs.py
@@ -54,6 +54,11 @@ With this pattern:
 import copy
 
 
+def setup_users(db, **kwargs):
+    db.recreate()
+    db.save_docs(copy.deepcopy(USERS_DOCS))
+
+
 def setup(db, index_type="view", **kwargs):
     db.recreate()
     db.save_docs(copy.deepcopy(DOCS))
@@ -488,3 +493,34 @@ DOCS = [
         ]
     }
 ]
+
+
+USERS_DOCS = [
+    {
+        "_id": "org.couchdb.user:demo01",
+        "name": "demo01",
+        "username": "demo01",
+        "password": "apple01",
+        "roles": ["design"],
+        "order": 1,
+        "type": "user"
+    },
+    {
+        "_id": "org.couchdb.user:demo02",
+        "name": "demo02",
+        "username": "demo02",
+        "password": "apple02",
+        "roles": ["reader"],
+        "order": 2,
+        "type": "user"
+    },
+    {
+        "_id": "org.couchdb.user:demo03",
+        "name": "demo03",
+        "username": "demo03",
+        "password": "apple03",
+        "roles": ["reader", "writer"],
+        "order": 3,
+        "type": "user"
+    }
+]

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

[couchdb] 03/04: Send user_ctx to fabric's open_doc

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 022925aefb8bbdc9ff818beff4c6f37382f1f248
Author: Eric Avdey <ei...@eiri.ca>
AuthorDate: Fri Jul 7 16:53:18 2017 -0300

    Send user_ctx to fabric's open_doc
---
 src/mango/src/mango_httpd.erl | 3 ++-
 src/mango/src/mango_util.erl  | 6 +++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/mango/src/mango_httpd.erl b/src/mango/src/mango_httpd.erl
index a088276..5bc61f5 100644
--- a/src/mango/src/mango_httpd.erl
+++ b/src/mango/src/mango_httpd.erl
@@ -85,7 +85,8 @@ handle_index_req(#httpd{method='POST', path_parts=[_, _]}=Req, Db) ->
     {ok, Opts} = mango_opts:validate_idx_create(chttpd:json_body_obj(Req)),
     {ok, Idx0} = mango_idx:new(Db, Opts),
     {ok, Idx} = mango_idx:validate_new(Idx0, Db),
-    {ok, DDoc} = mango_util:load_ddoc(Db, mango_idx:ddoc(Idx)),
+    DbOpts = [{user_ctx, Req#httpd.user_ctx}, deleted, ejson_body],
+    {ok, DDoc} = mango_util:load_ddoc(Db, mango_idx:ddoc(Idx), DbOpts),
     Id = Idx#idx.ddoc,
     Name = Idx#idx.name,
     Status = case mango_idx:add(DDoc, Idx) of
diff --git a/src/mango/src/mango_util.erl b/src/mango/src/mango_util.erl
index c3513dc..a734717 100644
--- a/src/mango/src/mango_util.erl
+++ b/src/mango/src/mango_util.erl
@@ -17,6 +17,7 @@
     open_doc/2,
     open_ddocs/1,
     load_ddoc/2,
+    load_ddoc/3,
 
     defer/3,
     do_defer/3,
@@ -104,7 +105,10 @@ open_ddocs(Db) ->
 
 
 load_ddoc(Db, DDocId) ->
-    case open_doc(Db, DDocId, [deleted, ejson_body]) of
+    load_ddoc(Db, DDocId, [deleted, ejson_body]).
+
+load_ddoc(Db, DDocId, DbOpts) ->
+    case open_doc(Db, DDocId, DbOpts) of
         {ok, Doc} ->
             {ok, check_lang(Doc)};
         not_found ->

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