def make_c_document_for_test(test, doc_id, rev, content, has_conflicts=False): if c_backend_wrapper is None: test.skipTest('c_backend_wrapper is not available') return c_backend_wrapper.make_document(doc_id, rev, content, has_conflicts=has_conflicts)
def test_sync_exchange_find_doc_ids_not_including_recently_inserted(self): doc1 = self.db.create_doc_from_json(tests.simple_doc) doc2 = self.db.create_doc_from_json(tests.nested_doc) exc = self.st._get_sync_exchange("source-uid", 0) doc3 = c_backend_wrapper.make_document(doc1.doc_id, doc1.rev + "|zreplica:2", tests.simple_doc) exc.insert_doc_from_source(doc3, 10, 'T-sid') exc.find_doc_ids_to_return() self.assertEqual( (doc2.doc_id, 2), exc.get_doc_ids_to_return()[0][:-1]) self.assertEqual(3, exc.target_gen)
def test_sync_exchange_conflicted_doc(self): doc = self.db.create_doc_from_json(tests.simple_doc) exc = self.st._get_sync_exchange("source-uid", 5) doc2 = c_backend_wrapper.make_document(doc.doc_id, 'replica:1', tests.nested_doc) self.assertEqual([], exc.get_seen_ids()) # The insert should be rejected and the doc_id not considered 'seen' exc.insert_doc_from_source(doc2, 10, 'T-sid') self.assertGetDoc( self.db, doc.doc_id, doc.rev, tests.simple_doc, False) self.assertEqual([], exc.get_seen_ids())
def test_sync_exchange_insert_doc_from_source(self): exc = self.st._get_sync_exchange("source-uid", 5) doc = c_backend_wrapper.make_document('doc-id', 'replica:1', tests.simple_doc) self.assertEqual([], exc.get_seen_ids()) exc.insert_doc_from_source(doc, 10, 'T-sid') self.assertGetDoc(self.db, 'doc-id', 'replica:1', tests.simple_doc, False) self.assertEqual( (10, 'T-sid'), self.db._get_replica_gen_and_trans_id('source-uid')) self.assertEqual(['doc-id'], exc.get_seen_ids())
def test_sync_exchange_find_doc_ids_not_including_recently_inserted(self): doc1 = self.db.create_doc_from_json(tests.simple_doc) doc2 = self.db.create_doc_from_json(tests.nested_doc) exc = self.st._get_sync_exchange("source-uid", 0) doc3 = c_backend_wrapper.make_document(doc1.doc_id, doc1.rev + "|zreplica:2", tests.simple_doc) exc.insert_doc_from_source(doc3, 10, 'T-sid') exc.find_doc_ids_to_return() self.assertEqual((doc2.doc_id, 2), exc.get_doc_ids_to_return()[0][:-1]) self.assertEqual(3, exc.target_gen)
def test_sync_exchange_conflicted_doc(self): doc = self.db.create_doc_from_json(tests.simple_doc) exc = self.st._get_sync_exchange("source-uid", 5) doc2 = c_backend_wrapper.make_document(doc.doc_id, 'replica:1', tests.nested_doc) self.assertEqual([], exc.get_seen_ids()) # The insert should be rejected and the doc_id not considered 'seen' exc.insert_doc_from_source(doc2, 10, 'T-sid') self.assertGetDoc(self.db, doc.doc_id, doc.rev, tests.simple_doc, False) self.assertEqual([], exc.get_seen_ids())
def test_sync_exchange_insert_doc_from_source(self): exc = self.st._get_sync_exchange("source-uid", 5) doc = c_backend_wrapper.make_document('doc-id', 'replica:1', tests.simple_doc) self.assertEqual([], exc.get_seen_ids()) exc.insert_doc_from_source(doc, 10, 'T-sid') self.assertGetDoc(self.db, 'doc-id', 'replica:1', tests.simple_doc, False) self.assertEqual((10, 'T-sid'), self.db._get_replica_gen_and_trans_id('source-uid')) self.assertEqual(['doc-id'], exc.get_seen_ids())
def make_document(self, *args, **kwargs): return c_backend_wrapper.make_document(*args, **kwargs)
def make_c_document_for_test(test, doc_id, rev, content, has_conflicts=False): if c_backend_wrapper is None: test.skipTest('c_backend_wrapper is not available') return c_backend_wrapper.make_document( doc_id, rev, content, has_conflicts=has_conflicts)
def create_c_document(doc_id, rev, content, has_conflicts=False): return c_backend_wrapper.make_document(doc_id, rev, content, has_conflicts=has_conflicts)
def create_c_document(doc_id, rev, content, has_conflicts=False): return c_backend_wrapper.make_document( doc_id, rev, content, has_conflicts=has_conflicts)