def sdk3_to_sdk2_durability(durability, num_replicas):
     if durability == Durability.NONE:
         return ClientDurability(PersistTo.NONE, ReplicateTo.NONE)
     if durability == Durability.MAJORITY:
         return ClientDurability(replicate_to=ReplicateTo(int((num_replicas+1)/2)), persist_to=PersistTo.NONE)
     if durability == Durability.MAJORITY_AND_PERSIST_TO_ACTIVE:
         return ClientDurability(replicate_to=ReplicateTo(int((num_replicas+1)/2)), persist_to=PersistTo.ONE)
     if durability == Durability.PERSIST_TO_MAJORITY:
         return ClientDurability(persist_to=PersistTo(int((num_replicas+1)/2 + 1)), replicate_to=ReplicateTo.NONE)
 def test_client_durable_insert(self):
     num_replicas = self.bucket._bucket.configured_replica_count
     durability = ClientDurability(persist_to=PersistTo.ONE,
                                   replicate_to=ReplicateTo(num_replicas))
     self.cb.insert(self.NOKEY, self.CONTENT,
                    InsertOptions(durability=durability))
     result = self.cb.get(self.NOKEY)
     self.assertEqual(self.CONTENT, result.content_as[dict])
 def test_client_durable_replace(self):
     num_replicas = self.bucket._bucket.configured_replica_count
     content = {"new": "content"}
     durability = ClientDurability(persist_to=PersistTo.ONE,
                                   replicate_to=ReplicateTo(num_replicas))
     self.cb.replace(self.KEY, content,
                     ReplaceOptions(durability=durability))
     result = self.cb.get(self.KEY)
     self.assertEqual(content, result.content_as[dict])
 def test_client_durable_remove(self):
     num_replicas = self.bucket._bucket.configured_replica_count
     durability = ClientDurability(persist_to=PersistTo.ONE,
                                   replicate_to=ReplicateTo(num_replicas))
     self.cb.remove(self.KEY, RemoveOptions(durability=durability))
     self.assertRaises(DocumentNotFoundException, self.cb.get, self.KEY)