def setUp(self): app.config['TESTING'] = True self.app = app.test_client() self.login('*****@*****.**', 'testuser') # generate data for reports self.r = Report(start=date(year=2011, month=2, day=1), end=date(year=2011, month=3, day=1), finished=True) self.r.put() stats = { 'id': str(self.r.key()), 'stats': { '0000_01': { 'id': '01', 'table': '0000', 'def': 1, 'deg': 2 }, '0000_02': { 'id': '02', 'table': '0000', 'def': 1, 'deg': 2 }, '0001_02': { 'id': '02', 'table': '0001', 'def': 1, 'deg': 2 } } } StatsStore(report_id=str(self.r.key()), json=json.dumps(stats)).put()
def update_report_stats(report_id): r = Report.get(Key(report_id)) stats = {'id': report_id, 'stats': {}} for desc, table, name in tables: stats['stats'].update(stats_for(str(r.key().id()), r.assetid, table)) # sleep for some time to avoid problems with FT time.sleep(4) data = json.dumps(stats) s = StatsStore.get_for_report(report_id) if s: s.json = data s.put() else: StatsStore(report_id=report_id, json=data).put() # wait a little bit to allow app store saves the data time.sleep(1.0) update_total_stats_for_report(report_id)