def mock_fetch_ladder(self, status=200, fetch_time=None, members=None, **kwargs): self.bnet.fetch_ladder = \ Mock(return_value=LadderResponse(status, gen_api_ladder(members, **kwargs), fetch_time or utcnow(), 0))
def test_exception_if_ap_and_strange_points(self): al = gen_api_ladder(members=[ gen_member(points=1.1, join_time=self.datetime(days=-7)), ], gd=False) with self.assertRaises(Exception): get_strangeness(self.datetime(), al, ap=1)
def test_categorize_as_nop_if_ceritain_time_good_points_and_no_ap(self): al = gen_api_ladder(members=[ gen_member(points=1, join_time=self.datetime(days=-20)), ], gd=False) self.assertEqual(Ladder.NOP, get_strangeness(self.datetime(), al, ap=None))
def test_categorize_as_genuine_strange_imediatly(self): al = gen_api_ladder(members=[ gen_member(points=1.2, join_time=self.s16_time), ], gd=False) self.assertEqual(Ladder.STRANGE, get_strangeness(self.datetime(), al, ap=None))
def test_what_happens_if_low_member_count_and_random_strange_but_even_( self): al = gen_api_ladder(members=[ gen_member(points=1, join_time=self.datetime(days=-20)), ], gd=False) self.assertEqual(Ladder.NOP, get_strangeness(self.datetime(), al, ap=None))
def test_categorize_as_good_if_ap(self): al = gen_api_ladder(members=[ gen_member(points=1, join_time=self.datetime(days=-7)), ], gd=False) self.assertEqual(Ladder.GOOD, get_strangeness(self.datetime(), al, ap=1))
def test_refetch_past_seasons_will_refetch_ladder_and_ranking_will_be_updated( self): p1 = self.db.create_player(name="arne") t1 = self.db.create_team() l = self.db.create_ladder(bid=100, season=self.s15, max_points=20, updated=self.datetime(days=-30)) c = self.db.create_cache(bid=100) r = self.db.create_ranking(season=self.s15, data_time=self.datetime(days=-21)) self.db.create_ranking_data(data=[ dict(team_id=t1.id, points=20, data_time=self.unix_time(days=-30)) ]) self.db.update_ranking_stats() al = gen_api_ladder(data=[dict(team_id=t1.id, points=40)], bid=100) fetch_time = utcnow() self.mock_fetch_ladder(fetch_time=fetch_time, members=[gen_member(bid=p1.bid, points=40)]) self.refetch_past_seasons() self.bnet.fetch_ladder.assert_called_once_with(self.s15.id, Region.EU, 100, timeout=20) l.refresh_from_db() r.refresh_from_db() self.assertTrue(abs(fetch_time - l.updated) < timedelta(hours=1)) self.assertEqual(40, l.max_points) self.assertEqual({c.id}, {c.id for c in r.sources.all()}) self.assert_team_ranks(r.id, dict(points=40)) self.assertEqual(self.s15.end_time(), r.data_time)