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/09/12 12:53:05 UTC

[couchdb] branch master updated (bc43efb -> cf00dc2)

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

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


    from bc43efb  Use unittest assert in index selection tests
     new 41e2984  Use unittest assertions in mango index tests
     new 302126b  Return 400 when no index can fulfil a sort
     new cf00dc2  Log unhandled mango errors

The 3 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_error.erl             |  6 ++---
 src/mango/src/mango_httpd.erl             | 14 ++++++------
 src/mango/test/05-index-selection-test.py | 38 +++++++++++++++++++------------
 3 files changed, 33 insertions(+), 25 deletions(-)

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

[couchdb] 02/03: Return 400 when no index can fulfil a sort

Posted by wi...@apache.org.
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

commit 302126b75b124f4f00a8c9629b086c8b92d42784
Author: Will Holley <wi...@gmail.com>
AuthorDate: Mon Sep 11 17:13:00 2017 +0100

    Return 400 when no index can fulfil a sort
    
    Fixes a regression where a 500 status code was returned when
    no index is available to service a _find query because the
    sort order does not match any available indexes.
---
 src/mango/src/mango_error.erl             | 6 +++---
 src/mango/test/05-index-selection-test.py | 8 ++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/mango/src/mango_error.erl b/src/mango/src/mango_error.erl
index 3610165..4f8ae20 100644
--- a/src/mango/src/mango_error.erl
+++ b/src/mango/src/mango_error.erl
@@ -21,19 +21,19 @@
 ]).
 
 
-info(mango_cursor, {no_usable_index, no_indexes_defined}) ->
+info(mango_idx, {no_usable_index, no_indexes_defined}) ->
     {
         400,
         <<"no_usable_index">>,
         <<"There are no indexes defined in this database.">>
     };
-info(mango_cursor, {no_usable_index, no_index_matching_name}) ->
+info(mango_idx, {no_usable_index, no_index_matching_name}) ->
     {
         400,
         <<"no_usable_index">>,
         <<"No index matches the index specified with \"use_index\"">>
     };
-info(mango_cursor, {no_usable_index, missing_sort_index}) ->
+info(mango_idx, {no_usable_index, missing_sort_index}) ->
     {
         400,
         <<"no_usable_index">>,
diff --git a/src/mango/test/05-index-selection-test.py b/src/mango/test/05-index-selection-test.py
index a78c12f..2fb0a40 100644
--- a/src/mango/test/05-index-selection-test.py
+++ b/src/mango/test/05-index-selection-test.py
@@ -74,6 +74,14 @@ class IndexSelectionTests(mango.UserDocsTests):
             }, use_index=ddocid, explain=True)
         self.assertEqual(resp["index"]["ddoc"], ddocid)
 
+    def test_no_valid_sort_index(self):
+        try:
+            self.db.find({"_id": {"$gt": None}}, sort=["name"], return_raw=True)
+        except Exception, e:
+            self.assertEqual(e.response.status_code, 400)
+        else:
+            raise AssertionError("bad find")
+
     def test_invalid_use_index(self):
         # ddoc id for the age index
         ddocid = "_design/ad3d537c03cd7c6a43cf8dff66ef70ea54c2b40f"

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

[couchdb] 03/03: Log unhandled mango errors

Posted by wi...@apache.org.
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

commit cf00dc26447ed44d3a8be0d77e4923367b02bb6b
Author: Will Holley <wi...@gmail.com>
AuthorDate: Mon Sep 11 18:12:16 2017 +0100

    Log unhandled mango errors
---
 src/mango/src/mango_httpd.erl | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/mango/src/mango_httpd.erl b/src/mango/src/mango_httpd.erl
index 33e0c1c..d3ebf48 100644
--- a/src/mango/src/mango_httpd.erl
+++ b/src/mango/src/mango_httpd.erl
@@ -38,13 +38,13 @@ handle_req(#httpd{} = Req, Db0) ->
         handle_req_int(Req, Db)
     catch
         throw:{mango_error, Module, Reason} ->
-            %Stack = erlang:get_stacktrace(),
-            {Code, ErrorStr, ReasonStr} = mango_error:info(Module, Reason),
-            Resp = {[
-                {<<"error">>, ErrorStr},
-                {<<"reason">>, ReasonStr}
-            ]},
-            chttpd:send_json(Req, Code, Resp)
+            case mango_error:info(Module, Reason) of
+            {500, ErrorStr, ReasonStr} ->
+                Stack = erlang:get_stacktrace(),
+                chttpd:send_error(Req, 500, [], ErrorStr, ReasonStr, Stack);
+            {Code, ErrorStr, ReasonStr} ->
+                chttpd:send_error(Req, Code, ErrorStr, ReasonStr)
+            end
     end.
 
 

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

[couchdb] 01/03: Use unittest assertions in mango index tests

Posted by wi...@apache.org.
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

commit 41e2984166d65677634c36bb204195c770a5cb03
Author: Will Holley <wi...@gmail.com>
AuthorDate: Mon Sep 11 17:12:41 2017 +0100

    Use unittest assertions in mango index tests
    
    The assertion functions inherited from unittest
    provide clearer errors when tests fail - use these
    in preference to plain assert.
---
 src/mango/test/05-index-selection-test.py | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/mango/test/05-index-selection-test.py b/src/mango/test/05-index-selection-test.py
index bbd3aa7..a78c12f 100644
--- a/src/mango/test/05-index-selection-test.py
+++ b/src/mango/test/05-index-selection-test.py
@@ -24,14 +24,14 @@ class IndexSelectionTests(mango.UserDocsTests):
 
     def test_basic(self):
         resp = self.db.find({"name.last": "A last name"}, explain=True)
-        assert resp["index"]["type"] == "json"
+        self.assertEqual(resp["index"]["type"], "json")
 
     def test_with_and(self):
         resp = self.db.find({
                 "name.first": "Stephanie",
                 "name.last": "This doesn't have to match anything."
             }, explain=True)
-        assert resp["index"]["type"] == "json"
+        self.assertEqual(resp["index"]["type"], "json")
 
     @unittest.skipUnless(mango.has_text_service(), "requires text service")
     def test_with_text(self):
@@ -40,12 +40,12 @@ class IndexSelectionTests(mango.UserDocsTests):
                 "name.first": "Stephanie",
                 "name.last": "This doesn't have to match anything."
             }, explain=True)
-        assert resp["index"]["type"] == "text"
+        self.assertEqual(resp["index"]["type"], "text")
 
     @unittest.skipUnless(mango.has_text_service(), "requires text service")
     def test_no_view_index(self):
         resp = self.db.find({"name.first": "Ohai!"}, explain=True)
-        assert resp["index"]["type"] == "text"
+        self.assertEqual(resp["index"]["type"], "text")
 
     @unittest.skipUnless(mango.has_text_service(), "requires text service")
     def test_with_or(self):
@@ -55,7 +55,7 @@ class IndexSelectionTests(mango.UserDocsTests):
                     {"name.last": "This doesn't have to match anything."}
                 ]
             }, explain=True)
-        assert resp["index"]["type"] == "text"
+        self.assertEqual(resp["index"]["type"], "text")
 
     def test_use_most_columns(self):
         # ddoc id for the age index
@@ -65,22 +65,22 @@ class IndexSelectionTests(mango.UserDocsTests):
                 "name.last": "Something or other",
                 "age": {"$gt": 1}
             }, explain=True)
-        assert resp["index"]["ddoc"] != "_design/" + ddocid
+        self.assertNotEqual(resp["index"]["ddoc"], "_design/" + ddocid)
 
         resp = self.db.find({
                 "name.first": "Stephanie",
                 "name.last": "Something or other",
                 "age": {"$gt": 1}
             }, use_index=ddocid, explain=True)
-        assert resp["index"]["ddoc"] == ddocid
+        self.assertEqual(resp["index"]["ddoc"], ddocid)
 
-    def test_use_most_columns(self):
+    def test_invalid_use_index(self):
         # ddoc id for the age index
         ddocid = "_design/ad3d537c03cd7c6a43cf8dff66ef70ea54c2b40f"
         try:
             self.db.find({}, use_index=ddocid)
         except Exception, e:
-            assert e.response.status_code == 400
+            self.assertEqual(e.response.status_code, 400)
         else:
             raise AssertionError("bad find")
 
@@ -149,9 +149,9 @@ class IndexSelectionTests(mango.UserDocsTests):
         }
         self.db.save_doc(design_doc)
         docs= self.db.find({"age" : 48})
-        assert len(docs) == 1
-        assert docs[0]["name"]["first"] == "Stephanie"
-        assert docs[0]["age"] == 48
+        self.assertEqual(len(docs), 1)
+        self.assertEqual(docs[0]["name"]["first"], "Stephanie")
+        self.assertEqual(docs[0]["age"], 48)
 
 
 @unittest.skipUnless(mango.has_text_service(), "requires text service")
@@ -165,14 +165,14 @@ class MultiTextIndexSelectionTests(mango.UserDocsTests):
 
     def test_view_ok_with_multi_text(self):
         resp = self.db.find({"name.last": "A last name"}, explain=True)
-        assert resp["index"]["type"] == "json"
+        self.assertEqual(resp["index"]["type"], "json")
 
     def test_multi_text_index_is_error(self):
         try:
             self.db.find({"$text": "a query"}, explain=True)
         except Exception, e:
-            assert e.response.status_code == 400
+            self.assertEqual(e.response.status_code, 400)
 
     def test_use_index_works(self):
         resp = self.db.find({"$text": "a query"}, use_index="foo", explain=True)
-        assert resp["index"]["ddoc"] == "_design/foo"
+        self.assertEqual(resp["index"]["ddoc"], "_design/foo")

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