def test_month_skip(self): models.AccountStatsDay( id='2011-03-08', parent=self.userA_key, issues=[1], latencies=[1], lgtms=[10], review_types=[NORMAL], modified=self.yesterday).put() models.AccountStatsMulti( id='2011-03', parent=self.userA_key, issues=[1], latencies=[1], lgtms=[10], review_types=[NORMAL], modified=self.yesterday).put() expected = [ { 'issues': [1], 'latencies': [1], 'lgtms': [10], 'name': '2011-03', 'review_types': [NORMAL], 'score': 0.01, 'user': self.userA, }, ] text = 'Stored 0 items\nSkipped 1\n' self.trigger_request(self.today, 'monthly', text, expected)
def test_rolling(self): self.assertEqual([], models.AccountStatsDay.query().fetch()) self.assertEqual([], models.AccountStatsMulti.query().fetch()) # UserA models.AccountStatsDay( id='2012-04-20', parent=self.userA_key, issues=[1], latencies=[1], lgtms=[10], review_types=[NORMAL], modified=self.yesterday).put() models.AccountStatsDay( id='2012-04-10', parent=self.userA_key, issues=[13], latencies=[3], lgtms=[0], review_types=[NORMAL], modified=self.yesterday).put() # UserB models.AccountStatsDay( id='2012-04-28', parent=self.userB_key, issues=[3], latencies=[20], lgtms=[1], review_types=[DRIVE_BY], modified=self.yesterday).put() # Old instance. models.AccountStatsDay( id='2012-02-01', parent=self.userB_key, issues=[30, 13], latencies=[-1, 100], lgtms=[0, 1], review_types=[IGNORED, NORMAL], modified=self.yesterday).put() self.assertEqual(4, len(list(models.AccountStatsDay.query()))) # Put a garbagge instance that will be overriden. models.AccountStatsMulti( id='30', parent=self.userB_key, issues=[1, 2, 3], latencies=[1, 2, 3], lgtms=[1, 2, 3], review_types=[NORMAL, NORMAL, NORMAL], modified=self.yesterday).put() expected = [ { 'issues': [1, 13], 'latencies': [1, 3], 'lgtms': [10, 0], 'name': '30', 'review_types': [NORMAL, NORMAL], 'score': 0.01, 'user': self.userA, }, { 'issues': [3], 'latencies': [20], 'lgtms': [1], 'name': '30', 'review_types': [DRIVE_BY], 'score': 0.2, 'user': self.userB, }, ] text = 'Looked up 2 accounts\nStored 2 items\nDeleted 0\n' self.trigger_request(self.yesterday, '30', text, expected)
def test_month(self): models.AccountStatsDay( id='2012-04-08', parent=self.userA_key, issues=[1], latencies=[1], lgtms=[10], review_types=[NORMAL], modified=self.yesterday).put() models.AccountStatsDay( id='2012-04-18', parent=self.userA_key, issues=[13], latencies=[3], lgtms=[0], review_types=[NORMAL], modified=self.yesterday).put() models.AccountStatsDay( id='2012-04-03', parent=self.userB_key, issues=[3], latencies=[30], lgtms=[1], review_types=[DRIVE_BY], modified=self.yesterday).put() models.AccountStatsDay( id='2012-05-02', parent=self.userB_key, issues=[30, 13], latencies=[-1, 1], lgtms=[0, 1], review_types=[IGNORED, NORMAL], modified=self.yesterday).put() self.assertEqual(4, len(list(models.AccountStatsDay.query()))) # Put a garbagge instance. models.AccountStatsMulti( id='2011-03', parent=self.userB_key, issues=[1, 2, 3], latencies=[1, 2, 3], lgtms=[1, 2, 3], review_types=[NORMAL, NORMAL, NORMAL], modified=self.yesterday).put() expected = [ { 'issues': [1, 13], 'latencies': [1, 3], 'lgtms': [10, 0], 'name': '2012-04', 'score': 0.01, 'review_types': [NORMAL, NORMAL], 'user': self.userA, }, { # Old instance. 'issues': [1, 2, 3], 'latencies': [1, 2, 3], 'lgtms': [1, 2, 3], 'name': '2011-03', 'review_types': [NORMAL, NORMAL, NORMAL], 'score': 0.006666666666666666, 'user': self.userB, }, { 'issues': [3], 'latencies': [30], 'lgtms': [1], 'name': '2012-04', 'review_types': [DRIVE_BY], 'score': 0.3, 'user': self.userB, }, { 'issues': [30, 13], 'latencies': [-1, 1], 'lgtms': [0, 1], 'name': '2012-05', 'review_types': [IGNORED, NORMAL], 'score': 0.02, 'user': self.userB, }, ] text = 'Stored 3 items\nSkipped 0\n' self.trigger_request(self.today, 'monthly', text, expected)
def setUp(self): super(TestFetchStats, self).setUp() user = models.Account.get_account_for_user(User('*****@*****.**')) user_key = user.key # Daily. models.AccountStatsDay( id='2011-03-03', parent=user_key, issues=[3], latencies=[20], lgtms=[1], review_types=[DRIVE_BY]).put() # Month. models.AccountStatsMulti( id='2011-01', parent=user_key, issues=[5, 6, 30], latencies=[100, 3, 5], lgtms=[1, 0, 0], review_types=[DRIVE_BY, NORMAL, NORMAL]).put() models.AccountStatsMulti( id='2011-03', parent=user_key, issues=[10], latencies=[110], lgtms=[1], review_types=[NOT_REQUESTED]).put() # Rolling. models.AccountStatsMulti( id='30', parent=user_key, issues=[10, 20], latencies=[100, -1], lgtms=[1, 0], review_types=[NORMAL, IGNORED]).put() user = models.Account.get_account_for_user(User('*****@*****.**')) user_key = user.key # Month. models.AccountStatsMulti( id='2011-02', parent=user_key, issues=[4, 5], latencies=[30, 50], lgtms=[1, 0], review_types=[NORMAL, NORMAL]).put() # Rolling. models.AccountStatsMulti( id='30', parent=user_key, issues=[11, 21], latencies=[100, 200], lgtms=[1, 2], review_types=[NORMAL, NORMAL]).put() user = models.Account.get_account_for_user(User('*****@*****.**')) user_key = user.key # Month. models.AccountStatsMulti( id='2011-02', parent=user_key, issues=[8], latencies=[-1], lgtms=[0], review_types=[IGNORED]).put() # Rolling. models.AccountStatsMulti( id='30', parent=user_key, issues=[11, 21, 34, 35, 36, 37], latencies=[100, 200, 10, 10000, 100, 1000], lgtms=[1, 2, 0, 0, 0, 0], review_types=[NORMAL, NORMAL, NORMAL, NORMAL, NORMAL, NORMAL]).put()