def __next__(self): for item in self.iterator: obj = self.cls.get(debyte_string(item)) if self.matches_filters(obj): return obj raise StopIteration
def test_delete_index(nrm): ship = Ship(code='A12').save() assert debyte_string(nrm.redis.hget('ship:index_code', 'A12')) == ship.id ship.delete() assert not nrm.redis.hexists('ship:index_code', 'A12')
def test_update_changes_index(nrm): ship = Ship(code='THECODE').save() ship.update(code='NEWCODE') assert ship.code == 'NEWCODE' assert debyte_string(nrm.redis.hget('ship:index_code', 'NEWCODE')) == ship.id assert nrm.redis.hget('ship:index_code', 'THECODE') is None
def test_update_keep_index(nrm): ship = Ship(name='the ship', code='TS').save() ship.update(name='updated name') assert ship.code == 'TS' assert ship.name == 'updated name' assert debyte_string(nrm.redis.hget('ship:index_code', 'TS')) == ship.id
def get_by(cls, field, value): ''' Tries to retrieve an isinstance of this model from the database given a value for a defined index. Return None in case of failure ''' redis = cls.get_redis() key = cls.cls_key() + ':index_' + field id = redis.hget(key, value) if id: return cls.get(debyte_string(id)) return None