def test_report(self): tracker = Tracker() tracker.incr_labels('label1:cat1:dom1') tracker.incr_labels('label1:cat1:dom1') self.assertEqual(Statistic.objects.count(), 0) make_daily_report() self.assertEqual(tracker.flush_label('label1'), 0) self.assertEqual(Statistic.objects.count(), 1) stat = Statistic.objects.all()[0] self.assertEqual(stat.counter, 2) self.assertEqual(stat.category, 'cat1') self.assertEqual(stat.dom_id, 'dom1') tracker.incr_labels('label1:cat1:dom1') tracker.incr_labels('label1:cat1:dom1') stat = Statistic.objects.all()[0] self.assertEqual(stat.counter, 2) make_daily_report() stat = Statistic.objects.all()[0] self.assertEqual(stat.counter, 4) tracker.reset_cache()
def test_traker(self): tracker = Tracker() tracker.incr_labels('label1') self.assertEqual(tracker.labels, {'label1': {'lbl': 'label1'}}) tracker.incr_labels('label1') self.assertEqual(tracker.flush_label('label1'), 2) self.assertEqual(tracker.flush_label('label1'), 0) tracker.save() tracker = Tracker() self.assertEqual(tracker.labels, {'label1': {'lbl': 'label1'}}) tracker.reset_cache()