Esempio n. 1
0
    def test_stats_per_month(self):
        month = datetime.combine(datetime(2013, 10, 01), datetime.min.time())

        # check, if the stats for past month 10 get saved in log_db.stats_per_month
        stats = database.get_stats_per_month(self.db, month)
        self.assertIsNotNone(self.db.stats_per_month.find_one({"_id": month}))

        # check, if the days are in correct order
        for day in range(1, 30):
            self.assertEqual(stats["day_stats"][day-1]["day"],\
                datetime(2013, 10, day))

        # check, if the stats for october 12th are correct
        day_stats = stats["day_stats"][11]
        self.assertEqual(day_stats["num_page_impressions"], 3)
        self.assertEqual(day_stats["num_visits"], 2)

        # get correct values for months without any visits
        stats = database.get_stats_per_month(self.db, datetime(1999, 1, 1))
        self.assertEqual(stats["num_page_impressions"], 0)
        self.assertEqual(stats["num_visits"], 0)

        # the stats document should not be saved in log_db.stats_per_month
        # for the current month
        month = datetime.combine(datetime.now(), datetime.min.time())
        stats = database.get_stats_per_month(self.db, month)
        self.assertIsNone(self.db.get_stats_per_month.find_one({"_id": month}))
Esempio n. 2
0
    def test_stats_per_month(self):
        month = datetime.combine(datetime(2013, 10, 01), datetime.min.time())

        # check, if the stats for past month 10 get saved in log_db.stats_per_month
        stats = database.get_stats_per_month(self.db, month)
        self.assertIsNotNone(self.db.stats_per_month.find_one({"_id": month}))

        # check, if the days are in correct order
        for day in range(1,30):
            self.assertEqual(stats["day_stats"][day-1]["day"],\
                datetime(2013, 10, day))

        # check, if the stats for october 12th are correct
        day_stats = stats["day_stats"][11]
        self.assertEqual(day_stats["num_page_impressions"], 3)
        self.assertEqual(day_stats["num_visits"], 2)

        # get correct values for months without any visits
        stats = database.get_stats_per_month(self.db, datetime(1999, 1, 1))
        self.assertEqual(stats["num_page_impressions"], 0)
        self.assertEqual(stats["num_visits"], 0)

        # the stats document should not be saved in log_db.stats_per_month
        # for the current month
        month = datetime.combine(datetime.now(), datetime.min.time())
        stats = database.get_stats_per_month(self.db, month)
        self.assertIsNone(self.db.get_stats_per_month.find_one({"_id": month}))
Esempio n. 3
0
    def test_stats_per_path_per_month(self):
        month = datetime.combine(datetime(2013, 10, 01), datetime.min.time())
        stats = database.get_stats_per_month(self.db, month)

        # get correct values for number of path visits
        self.assertEqual(stats["path_stats"]["/abc"], 3)
        self.assertEqual(stats["path_stats"]["/def"], 1)
Esempio n. 4
0
    def test_stats_per_path_per_month(self):
        month = datetime.combine(datetime(2013, 10, 01), datetime.min.time())
        stats = database.get_stats_per_month(self.db, month)

        # get correct values for number of path visits
        self.assertEqual(stats["path_stats"]["/abc"], 3)
        self.assertEqual(stats["path_stats"]["/def"], 1)