

@unittest.skipUnless(RUN_INDEXES, 'RUN_INDEXES is 0')
def test_secondary_index_store(self):
    if (not self.is_2i_supported()):
        raise unittest.SkipTest('2I not supported')
    bucket = self.client.bucket(self.bucket_name)
    rand = self.randint()
    obj = bucket.new('mykey1', rand)
    obj.add_index('field1_bin', 'val1a')
    obj.add_index('field1_int', 1011)
    obj.store()
    obj = bucket.get('mykey1')
    self.assertEqual(['val1a'], [y for (x, y) in obj.indexes if (x == 'field1_bin')])
    self.assertEqual([1011], [y for (x, y) in obj.indexes if (x == 'field1_int')])
    obj.add_index('field1_bin', 'val1b')
    obj.add_index('field1_int', 1012)
    obj.store()
    obj = bucket.get('mykey1')
    self.assertEqual(['val1a', 'val1b'], sorted([y for (x, y) in obj.indexes if (x == 'field1_bin')]))
    self.assertEqual([1011, 1012], sorted([y for (x, y) in obj.indexes if (x == 'field1_int')]))
    self.assertEqual([('field1_bin', 'val1a'), ('field1_bin', 'val1b'), ('field1_int', 1011), ('field1_int', 1012)], sorted(obj.indexes))
    obj.remove_index('field1_bin', 'val1a')
    obj.remove_index('field1_int', 1011)
    obj.store()
    obj = bucket.get('mykey1')
    self.assertEqual(['val1b'], sorted([y for (x, y) in obj.indexes if (x == 'field1_bin')]))
    self.assertEqual([1012], sorted([y for (x, y) in obj.indexes if (x == 'field1_int')]))
    obj.add_index('field1_bin', 'val1a')
    obj.add_index('field1_bin', 'val1a')
    obj.add_index('field1_bin', 'val1a')
    obj.add_index('field1_int', 1011)
    obj.add_index('field1_int', 1011)
    obj.add_index('field1_int', 1011)
    self.assertEqual([('field1_bin', 'val1a'), ('field1_bin', 'val1b'), ('field1_int', 1011), ('field1_int', 1012)], sorted(obj.indexes))
    obj.store()
    obj = x.get('mykey1')
    self.assertEqual([('field1_bin', 'val1a'), ('field1_bin', 'val1b'), ('field1_int', 1011), ('field1_int', 1012)], sorted(obj.indexes))
    bucket.get('mykey1').delete()

dataset/ETHPy150Open basho/riak-python-client/riak/tests/test_2i.py TwoITests.test_secondary_index_store/VarMisuse@500/753 `bucket`->`x`