diff options
author | Jan Lehnardt <jan@apache.org> | 2018-07-13 15:08:46 +0200 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2018-07-13 17:04:55 +0200 |
commit | 572234fb5026ae64ec7f6ed84728f2b1ef63d955 (patch) | |
tree | 85af64ceef971cc16d767a4834e12726784a1d9c | |
parent | 45a0ad9e78bbd5596b58f369ddda44254555755b (diff) | |
download | couchdb-572234fb5026ae64ec7f6ed84728f2b1ef63d955.tar.gz |
Add tests for mango conflict finding
I couldn’t find a cleaner way to add _bulk_docs with
`new_edits: false`.
-rw-r--r-- | src/mango/test/19-find-conflicts.py | 41 | ||||
-rw-r--r-- | src/mango/test/mango.py | 5 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/mango/test/19-find-conflicts.py b/src/mango/test/19-find-conflicts.py new file mode 100644 index 000000000..c6d59f00d --- /dev/null +++ b/src/mango/test/19-find-conflicts.py @@ -0,0 +1,41 @@ +# 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 +import copy + +DOC = [ + { + "_id": "doc", + "a": 2 + } +] + +CONFLICT = [ + { + "_id": "doc", + "_rev": "1-23202479633c2b380f79507a776743d5", + "a": 1 + } +] + +class ChooseCorrectIndexForDocs(mango.DbPerClass): + def setUp(self): + self.db.recreate() + self.db.save_docs(copy.deepcopy(DOC)) + self.db.save_docs_with_conflicts(copy.deepcopy(CONFLICT)) + + def test_retrieve_conflicts(self): + self.db.create_index(["_conflicts"]) + result = self.db.find({"_conflicts": { "$exists": True}}, conflicts=True) + self.assertEqual(result[0]['_conflicts'][0], '1-23202479633c2b380f79507a776743d5') + self.assertEqual(result[0]['_rev'], '1-3975759ccff3842adf690a5c10caee42') diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py index 9b6b998cd..bc12bbc68 100644 --- a/src/mango/test/mango.py +++ b/src/mango/test/mango.py @@ -95,6 +95,11 @@ class Database(object): def save_doc(self, doc): self.save_docs([doc]) + def save_docs_with_conflicts(self, docs, **kwargs): + body = json.dumps({"docs": docs, "new_edits": False}) + r = self.sess.post(self.path("_bulk_docs"), data=body, params=kwargs) + r.raise_for_status() + def save_docs(self, docs, **kwargs): body = json.dumps({"docs": docs}) r = self.sess.post(self.path("_bulk_docs"), data=body, params=kwargs) |