analytics: Disallow non-UTC fill times in process_count_stat.

No change in behavior, but we aren't supporting non-UTC times in analytics
as a whole any more, so might as well change this check as well.
This commit is contained in:
Rishi Gupta 2017-10-04 17:06:43 -07:00 committed by Tim Abbott
parent 0596c4a810
commit c7bdabbda8
2 changed files with 5 additions and 6 deletions

View File

@ -8,7 +8,7 @@ from analytics.models import InstallationCount, RealmCount, \
from zerver.models import Realm, UserProfile, Message, Stream, \
UserActivityInterval, RealmAuditLog, models
from zerver.lib.timestamp import floor_to_day, floor_to_hour, ceiling_to_day, \
ceiling_to_hour
ceiling_to_hour, verify_UTC
from typing import Any, Callable, Dict, List, Optional, Text, Tuple, Type, Union
@ -78,8 +78,7 @@ def process_count_stat(stat, fill_to_time):
else:
raise AssertionError("Unknown frequency: %s" % (stat.frequency,))
if fill_to_time.tzinfo is None:
raise ValueError("fill_to_time must be timezone aware: %s" % (fill_to_time,))
verify_UTC(fill_to_time)
if floor_to_hour(fill_to_time) != fill_to_time:
raise ValueError("fill_to_time must be on an hour boundary: %s" % (fill_to_time,))

View File

@ -15,7 +15,7 @@ from analytics.models import BaseCount, InstallationCount, RealmCount, \
last_successful_fill
from zerver.lib.actions import do_create_user, do_deactivate_user, \
do_activate_user, do_reactivate_user, update_user_activity_interval
from zerver.lib.timestamp import floor_to_day
from zerver.lib.timestamp import floor_to_day, TimezoneNotUTCException
from zerver.models import Realm, UserProfile, Message, Stream, Recipient, \
Huddle, Client, UserActivityInterval, RealmAuditLog, get_client, get_user
@ -198,8 +198,8 @@ class TestProcessCountStat(AnalyticsTestCase):
stat = self.make_dummy_count_stat('test stat')
with self.assertRaises(ValueError):
process_count_stat(stat, installation_epoch() + 65*self.MINUTE)
with self.assertRaises(ValueError):
process_count_stat(stat, installation_epoch().replace(tzinfo=None) + self.HOUR)
with self.assertRaises(TimezoneNotUTCException):
process_count_stat(stat, installation_epoch().replace(tzinfo=None))
# This tests the LoggingCountStat branch of the code in do_delete_counts_at_hour.
# It is important that do_delete_counts_at_hour not delete any of the collected