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.db import connection, models
from django.utils import timezone from django.utils import timezone
from django.conf import settings
from datetime import timedelta, datetime
from analytics.models import InstallationCount, RealmCount, \ from analytics.models import InstallationCount, RealmCount, \
UserCount, StreamCount, BaseCount, FillState, installation_epoch 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 typing import Any, Optional, Type, Tuple, Text
from datetime import timedelta, datetime
import logging import logging
import time import time

View File

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