summaryrefslogtreecommitdiff
path: root/src/mango/test/01-index-crud-test.py
diff options
context:
space:
mode:
authorGabor Pali <gabor.pali@ibm.com>2023-05-16 14:21:33 +0200
committerNick Vatamaniuc <nickva@users.noreply.github.com>2023-05-16 12:28:37 -0400
commitb195f3734e8bae24728b98a57ae863a9a6bbb796 (patch)
treeecb27338f60a2f74212d521128a72b595cfcc569 /src/mango/test/01-index-crud-test.py
parentdcf57c710c52b0a55c596f65f07b85855130f66f (diff)
downloadcouchdb-b195f3734e8bae24728b98a57ae863a9a6bbb796.tar.gz
mango: address missing parts of the `_index` API
Many of the requests aimed outside the scope of the `_index` endpoint are not handled gracefully but trigger an internal server error. Enhance the index HTTP REST API handler logic to return proper answers for invalid queries and supply it with more exhaustive integration tests. Provide documentation for the existing `_index/_bulk_delete` endpoint as it was missing, and mention that the `_design` prefix is not needed when deleting indexes.
Diffstat (limited to 'src/mango/test/01-index-crud-test.py')
-rw-r--r--src/mango/test/01-index-crud-test.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/mango/test/01-index-crud-test.py b/src/mango/test/01-index-crud-test.py
index dd70e7eea..24409b49a 100644
--- a/src/mango/test/01-index-crud-test.py
+++ b/src/mango/test/01-index-crud-test.py
@@ -11,6 +11,7 @@
# the License.
import random
+from functools import partial
import mango
import copy
@@ -88,6 +89,56 @@ class IndexCrudTests(mango.DbPerClass):
else:
raise AssertionError("bad create index")
+ def test_bad_urls(self):
+ # These are only the negative test cases because ideally the
+ # positive ones are implicitly tested by other ones.
+
+ all_methods = [
+ ("PUT", self.db.sess.put),
+ ("GET", self.db.sess.get),
+ ("POST", self.db.sess.post),
+ ("PATCH", self.db.sess.get),
+ ("DELETE", self.db.sess.delete),
+ ("HEAD", self.db.sess.head),
+ ("COPY", partial(self.db.sess.request, "COPY")),
+ ("OPTIONS", partial(self.db.sess.request, "OPTIONS")),
+ ("TRACE", partial(self.db.sess.request, "TRACE")),
+ ("CONNECT", partial(self.db.sess.request, "CONNECT")),
+ ]
+
+ def all_but(method):
+ return list(filter(lambda x: x[0] != method, all_methods))
+
+ # Three-element subpaths are used as a shorthand to delete
+ # indexes via design documents, see below.
+ for subpath in ["a", "a/b", "a/b/c/d", "a/b/c/d/e", "a/b/c/d/e/f"]:
+ path = self.db.path("_index/{}".format(subpath))
+ for method_name, method in all_methods:
+ with self.subTest(path=path, method=method_name):
+ r = method(path)
+ self.assertEqual(r.status_code, 404)
+
+ for method_name, method in all_but("POST"):
+ path = self.db.path("_index/_bulk_delete")
+ with self.subTest(path=path, method=method_name):
+ r = method(path)
+ self.assertEqual(r.status_code, 405)
+
+ fields = ["foo", "bar"]
+ ddoc = "dd"
+ idx = "idx_01"
+ ret = self.db.create_index(fields, name=idx, ddoc=ddoc)
+ assert ret is True
+ for subpath in [
+ "{}/json/{}".format(ddoc, idx),
+ "_design/{}/json/{}".format(ddoc, idx),
+ ]:
+ path = self.db.path("_index/{}".format(subpath))
+ for method_name, method in all_but("DELETE"):
+ r = method(path)
+ with self.subTest(path=path, method=method_name):
+ self.assertEqual(r.status_code, 405)
+
def test_create_idx_01(self):
fields = ["foo", "bar"]
ret = self.db.create_index(fields, name="idx_01")