willholley commented on code in PR #4810:
URL: https://github.com/apache/couchdb/pull/4810#discussion_r1375875992
##########
src/mango/test/03-operator-test.py:
##########
@@ -141,6 +142,38 @@ def test_exists_false_returns_missing_but_not_null(self):
for d in docs:
self.assertNotIn("twitter", d)
+ def test_beginswith(self):
+ self.db.save_docs(
+ [
+ {"user_id": 99, "location": {"state": ":Bar"}},
+ ]
+ )
+
+ cases = [
+ {"prefix": "New", "user_ids": [2, 10]},
+ # test characters that require escaping
+ {"prefix": "New ", "user_ids": [2, 10]},
+ {"prefix": ":", "user_ids": [99]},
+ {"prefix": "Foo", "user_ids": []},
+ {"prefix": '"Foo', "user_ids": []},
+ {"prefix": " New", "user_ids": []},
+ ]
+
+ for case in cases:
+ with self.subTest(prefix=case["prefix"]):
+ selector = {"location.state": {"$beginsWith":
case["prefix"]}}
+ docs = self.db.find(selector)
+ self.assertEqual(len(docs), len(case["user_ids"]))
+ self.assertUserIds(case["user_ids"], docs)
+
+ # non-string prefixes should return an error
+ def test_beginswith_invalid_prefix(self):
+ cases = [123, True, [], {}]
+ for prefix in cases:
+ with self.subTest(prefix=prefix):
+ with self.assertRaises(HTTPError):
Review Comment:
I'm not too worried about importing requests but you are correct it would be
better to test the explicit status_code here. In general I prefer the assertion
functions provided by `unittest` because you get useful failure descriptions by
default, but I don't think that's the case here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]