def execute(args): """Build keywords.""" count_diff = 0 query = data_types.Testcase.query().order(-data_types.Testcase.timestamp) for testcases in batcher.iterate(query, BATCH_SIZE): for testcase in testcases: before_testcase = to_dict(testcase) attribute_builder.populate(testcase) after_testcase = to_dict(testcase) diff = get_diff(before_testcase, after_testcase) if (count_diff % 10) == 0 and diff: print('Migrate (dry=%s) id:%s\n%s' % (not args.non_dry_run, testcase.key.id(), diff)) if diff: count_diff += 1 if args.non_dry_run: try: ndb.put_multi(testcases) except Exception: for testcase in testcases: try: testcase.put() except Exception: print('Error: %s %s' % (testcase.key.id(), sys.exc_info())) print('Done (count_diff=%d)' % count_diff)
def _test(self, batch_size, expected_batch_count, expected_count): """Test when the limit is too large.""" query = data_types.Testcase.query().order(data_types.Testcase.timestamp) list_of_testcases = list(batcher.iterate(query, batch_size=batch_size)) self.assertEqual(expected_batch_count, len(list_of_testcases)) count = 0 for testcases in list_of_testcases: for testcase in testcases: self.assertEqual(self.testcase_ids[count], testcase.key.id()) count += 1 self.assertEqual(expected_count, count)