def prepare_stats(self): self.stats_settings() now = time.time() c1 = yield Cracker(ip_address="192.168.1.1", first_time=now, latest_time=now, total_reports=0, current_reports=0).save() c2 = yield Cracker(ip_address="192.168.1.2", first_time=now, latest_time=now, total_reports=0, current_reports=0).save() yield controllers.add_report_to_cracker(c1, "127.0.0.1", when=now - 25 * 3600) yield controllers.add_report_to_cracker(c1, "127.0.0.2", when=now) yield controllers.add_report_to_cracker(c1, "127.0.0.3", when=now) yield controllers.add_report_to_cracker(c2, "127.0.0.2", when=now) yield controllers.add_report_to_cracker(c2, "127.0.0.3", when=now + 1) yield Registry.DBPOOL.runInteraction(stats.fixup_history_txn) yesterday = datetime.date.today() - datetime.timedelta(days=1) yield Registry.DBPOOL.runInteraction(stats.update_country_history_txn, yesterday, include_history=True) yield stats.update_stats_cache()
def test_empty_state(self): self.stats_settings() yield stats.update_stats_cache() self.assertIsNotNone(stats._cache, "Stats for empty database should not be None") cached = stats._cache["stats"] self.assertEqual(cached["num_hosts"], 0, "Number of hosts in empty database") self.assertEqual(cached["num_reports"], 0, "Number of reports in empty database") self.assertEqual(cached["num_clients"], 0, "Number of clients in empty database") html = yield stats.render_stats() # print(html) self.assertTrue("Number of clients" in html, "HTML should contain number of clients") self.assertTrue("../static/graphs/hourly.svg" in html, "HTML should contain path to hourly graph")
def prepare_stats(self): self.stats_settings() now = time.time() c1 = yield Cracker( ip_address="192.168.1.1", first_time=now, latest_time=now, total_reports=0, current_reports=0 ).save() c2 = yield Cracker( ip_address="192.168.1.2", first_time=now, latest_time=now, total_reports=0, current_reports=0 ).save() yield controllers.add_report_to_cracker(c1, "127.0.0.1", when=now - 25 * 3600) yield controllers.add_report_to_cracker(c1, "127.0.0.2", when=now) yield controllers.add_report_to_cracker(c1, "127.0.0.3", when=now) yield controllers.add_report_to_cracker(c2, "127.0.0.2", when=now) yield controllers.add_report_to_cracker(c2, "127.0.0.3", when=now + 1) yield Registry.DBPOOL.runInteraction(stats.fixup_history_txn) yesterday = datetime.date.today() - datetime.timedelta(days=1) yield Registry.DBPOOL.runInteraction(stats.update_country_history_txn, yesterday, include_history=True) yield stats.update_stats_cache()
def test_empty_state(self): self.stats_settings() yield stats.update_stats_cache() self.assertIsNotNone(stats._cache, "Stats for empty database should not be None") cached = stats._cache["stats"] self.assertEqual(cached["num_hosts"], 0, "Number of hosts in empty database") self.assertEqual(cached["num_reports"], 0, "Number of reports in empty database") self.assertEqual(cached["num_clients"], 0, "Number of clients in empty database") html = yield stats.render_stats() #print(html) self.assertTrue("Number of clients" in html, "HTML should contain number of clients") self.assertTrue("../static/graphs/hourly.svg" in html, "HTML should contain path to hourly graph")