def populate(historian=None): historian = historian or mincepy.get_historian() colours = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') makes = ('honda', 'ferrari', 'zonda', 'fiat') cars = [] for make in makes: for colour in colours: # Make some cars car = Car(make, colour) historian.save(car) cars.append(car) # Now randomly change some of them for _ in range(int(len(cars) / 4)): car = random.choice(cars) car.colour = random.choice(colours) car.save() # Now change one a number of times car = random.choice(cars) for colour in colours: car.colour = colour car.save() people = mincepy.RefList() for name in ('martin', 'sonia', 'gavin', 'upul', 'martin', 'sebastiaan', 'irene'): person = Person(name, random.randint(20, 40)) historian.save(person) people.append(person) historian.save(people)
def test_update_meta_in_save_with_sticky(historian: mincepy.Historian): class Info(mincepy.ConvenientSavable): TYPE_ID = uuid.UUID('6744689d-5f88-482e-bb42-2bec5f139cc2') def save_instance_state(self, saver: mincepy.Saver) -> dict: state = super().save_instance_state(saver) saver.get_historian().meta.update(self, dict(msg='good news')) return state historian = mincepy.get_historian() historian.meta.sticky['all'] = 'good' info = Info() info.save() meta = historian.meta.get(info) assert meta == {'all': 'good', 'msg': 'good news'}
def query(obj_type, filter, limit): # pylint: disable=redefined-builtin historian = mincepy.get_historian() results = historian.find_recods(obj_type, state=filter, limit=limit, version=-1) historian.register_types(mincepy.testing.HISTORIAN_TYPES) # Gather by object types gathered = {} for result in results: gathered.setdefault(result.type_id, []).append(result) for type_id, records in gathered.items(): print(f'type: {type_id}') print_records(records, historian)