def test_stats_container(): "Tests the Stats container used in the templates" # Test basic API and null total count ipdata = [{"foo":1}]*100 s = Stats(ipdata, "foo", "nothing") expected_op = [(x, 1) for x in range(0, 140, 5)] assert s.get_counts() == expected_op assert s.get_summary() == 28 assert s.total == ""
def test_status_timerange(): "Tests the stats container with a time X-axis" d = datetime.datetime.now().replace(hour = 0, minute = 0, second = 0, microsecond = 0) ipdata = [] expected_op = [] for i in range(10): doc = MockDoc(_id = d.strftime("counts-%Y-%m-%d"), foo = 1) ipdata.append(doc) expected_op.append([calendar.timegm(d.timetuple()) * 1000, 1]) d += datetime.timedelta(days = 1) s = Stats(ipdata, "foo", "nothing") assert s.get_counts(10, True) == expected_op[:10]