def test_save_and_destroy_all(): ObjToDelete = Object.extend('ObjToDelete') objs = [ObjToDelete() for _ in range(3)] Object.save_all(objs) assert all(not x.is_new() for x in objs) Object.destroy_all(objs) for obj in objs: try: leancloud.Query(ObjToDelete).get(obj.id) except leancloud.LeanCloudError as e: assert e.code == 101
def test_save_and_destroy_all(): # type: () -> None ObjToDelete = Object.extend('ObjToDelete') objs = [ObjToDelete() for _ in range(3)] already_saved_obj = ObjToDelete() already_saved_obj.save() objs.append(already_saved_obj) Object.save_all(objs) assert all(not x.is_new() for x in objs) Object.destroy_all(objs) for obj in objs: try: leancloud.Query(ObjToDelete).get(obj.id) except leancloud.LeanCloudError as e: assert e.code == 101
def update_rec_list(**params): qRec = Query('Recommend') num_of_user = qRec.count() results = qRec.limit(num_of_user).ascending('uId').find() list_of_rec = [] for result in results: list_of_rec.append({ 'objectId': result.get('objectId'), 'pIds': result.get('pIds'), 'pTitles': result.get('pTitles'), 'uId': result.get('uId'), }) # delete all data in the database Recommend = Object.extend('Recommend') destroy_list = [] for rec in list_of_rec: recommend = Recommend.create_without_data(rec.get('objectId')) destroy_list.append(recommend) Object.destroy_all(destroy_list) # update recommend data for each users cloudfunc.run.local('build_rec_list')