def test_simple_get(self): k = self.gen_key("itm_simple_get") it = Item(k, "simple_value") rvs = self.cb.upsert_multi(ItemSequence([it])) self.assertTrue(rvs.all_ok) it_out = rvs[it.key] self.assertEqual(it_out, it) it = Item() it.key = k itcoll = ItemSequence([it]) rvs = self.cb.get_multi(ItemSequence([it])) self.assertTrue(rvs.all_ok) it_out = rvs[it.key] self.assertEqual(it_out, it) self.assertEqual(it_out.value, "simple_value") # Now, set it again self.cb.replace_multi(itcoll) # Now, delete it self.cb.remove_multi(itcoll) self.assertRaises(NotFoundError, self.cb.get_multi, itcoll)
def _wrap_dsop(self, sdres, has_value=False): from couchbase_core.items import Item it = Item(sdres.key) it.cas = sdres.cas if has_value: it.value = sdres[0] return it
def test_apiwrap(self): it = Item(self.gen_key("item_apiwrap")) self.cb.upsert_multi(it.as_itcoll()) self.assertTrue(it.cas) # Set with 'ignorecas' it.cas = 1234 self.cb.upsert_multi(it.as_itcoll(ignore_cas=True)) self.cb.upsert_multi(ItemSequence(it))
def test_construction(self): # Test whether we can construct a simple Item it = Item("some_key", "some_value") it.cas = 123456 it.flags = 1000 self.assertEqual(it.key, "some_key") self.assertEqual(it.value, "some_value") self.assertEqual(it.cas, 123456) self.assertEqual(it.flags, 1000) hash(it)
def test_item_format(self): # Tests whether things like 'CAS' and 'format' are honored k = self.gen_key("itm_format_options") it = Item(k, {}) itcoll = ItemOptionDict() itcoll.dict[it] = {"format": FMT_BYTES} self.assertRaises(ValueFormatError, self.cb.upsert_multi, itcoll)
def test_items_append(self): k = self.gen_key("itm_append") it = Item(k, "MIDDLE") itcoll = ItemOptionDict() itcoll.add(it) self.cb.upsert_multi(itcoll, format=FMT_UTF8) itcoll.add(it, fragment="_END") self.cb.append_items(itcoll, format=FMT_UTF8) self.assertEqual(it.value, "MIDDLE_END") itcoll.add(it, fragment="BEGIN_") self.cb.prepend_items(itcoll, format=FMT_UTF8) self.assertEqual(it.value, "BEGIN_MIDDLE_END") rv = self.cb.get(it.key) self.assertEqual(rv.value, "BEGIN_MIDDLE_END") # Try without a 'fragment' specifier self.assertRaises(InvalidArgumentException, self.cb.append_items, ItemSequence([it])) itcoll.add(it) self.assertRaises(InvalidArgumentException, self.cb.append_items, itcoll)
def test_items_ignorecas(self): k = self.gen_key("itm_ignorecas") it = Item(k, "a value") itcoll = ItemOptionDict() itcoll.add(it) self.cb.upsert_multi(itcoll) self.assertTrue(it.cas) # Set it again rv = self.cb.upsert(it.key, it.value) self.assertTrue(rv.cas) self.assertFalse(rv.cas == it.cas) # Should raise an error without ignore_cas self.assertRaises(KeyExistsError, self.cb.upsert_multi, itcoll) self.assertTrue(it.cas) itcoll.add(it, ignore_cas=True) self.cb.upsert_multi(itcoll) rv = self.cb.get(it.key) self.assertEqual(rv.cas, it.cas)