analytics: Do a stylistic cleanup of TestProcessCountStat.

This commit is contained in:
Rishi Gupta
2017-02-18 16:59:45 -08:00
committed by Tim Abbott
parent 6c784d6321
commit 8bea47d6b5
2 changed files with 15 additions and 15 deletions

View File

@@ -1,7 +1,6 @@
from django.conf import settings
from django.db import connection, models
from django.utils import timezone
from django.conf import settings
from datetime import timedelta, datetime
from analytics.models import InstallationCount, RealmCount, \
UserCount, StreamCount, BaseCount, FillState, installation_epoch
@@ -10,6 +9,7 @@ from zerver.lib.timestamp import floor_to_day
from typing import Any, Optional, Type, Tuple, Text
from datetime import timedelta, datetime
import logging
import time

View File

@@ -151,15 +151,15 @@ class TestProcessCountStat(AnalyticsTestCase):
# type: (datetime) -> CountStat
dummy_query = """INSERT INTO analytics_realmcount (realm_id, property, end_time, value)
VALUES (1, 'test stat', '%(end_time)s', 22)""" % {'end_time': current_time}
count_stat = CountStat('test stat', ZerverCountQuery(Recipient, UserCount, dummy_query),
stat = CountStat('test stat', ZerverCountQuery(Recipient, UserCount, dummy_query),
{}, None, CountStat.HOUR, False)
return count_stat
return stat
def assertFillStateEquals(self, end_time, state=FillState.DONE, property=None):
# type: (datetime, int, Optional[Text]) -> None
count_stat = self.make_dummy_count_stat(end_time)
stat = self.make_dummy_count_stat(end_time)
if property is None:
property = count_stat.property
property = stat.property
fill_state = FillState.objects.filter(property=property).first()
self.assertEqual(fill_state.end_time, end_time)
self.assertEqual(fill_state.state, state)
@@ -168,27 +168,27 @@ class TestProcessCountStat(AnalyticsTestCase):
# type: () -> None
# process new stat
current_time = installation_epoch() + self.HOUR
count_stat = self.make_dummy_count_stat(current_time)
property = count_stat.property
process_count_stat(count_stat, current_time)
stat = self.make_dummy_count_stat(current_time)
property = stat.property
process_count_stat(stat, current_time)
self.assertFillStateEquals(current_time)
self.assertEqual(InstallationCount.objects.filter(property=property).count(), 1)
# dirty stat
FillState.objects.filter(property=property).update(state=FillState.STARTED)
process_count_stat(count_stat, current_time)
process_count_stat(stat, current_time)
self.assertFillStateEquals(current_time)
self.assertEqual(InstallationCount.objects.filter(property=property).count(), 1)
# clean stat, no update
process_count_stat(count_stat, current_time)
process_count_stat(stat, current_time)
self.assertFillStateEquals(current_time)
self.assertEqual(InstallationCount.objects.filter(property=property).count(), 1)
# clean stat, with update
current_time = current_time + self.HOUR
count_stat = self.make_dummy_count_stat(current_time)
process_count_stat(count_stat, current_time)
stat = self.make_dummy_count_stat(current_time)
process_count_stat(stat, current_time)
self.assertFillStateEquals(current_time)
self.assertEqual(InstallationCount.objects.filter(property=property).count(), 2)