summaryrefslogtreecommitdiff
path: root/src/mango/test/01-index-crud-test.py
diff options
context:
space:
mode:
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")