Esempio n. 1
0
    def _test_setup_review_summary(self, time_zone, start_date_utc,
            end_date_utc, expected_stats):
        # Don't expect any reviews
        cursor = connection.cursor()
        review_stats = stats.select_review_stats(cursor, self.test_project_id,
                start_date_utc, end_date_utc, time_zone)
        self.assertEqual(review_stats, [])

        # Add test reviews
        self.add_test_reviews()

        # Expect empty summary table
        self.assert_empty_summary_table(cursor)

        # Expect correct statistics without summary tables
        review_stats = stats.select_review_stats(cursor, self.test_project_id,
                start_date_utc, end_date_utc, time_zone)
        self.assertEqual(review_stats, expected_stats)

        # Populate summary tables for two test time zones
        stats.populate_review_stats_summary(self.test_project_id, cursor=cursor)
        p = self.test_project_id
        expected_summary = set([
            (datetime.datetime(2017, 6, 1, 7, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 6, 30, 22, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 7, 2, 8, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 8, 2, 8, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 7, 1, 2, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 3),
            (datetime.datetime(2017, 7, 1, 7, 0, tzinfo=pytz.utc), 0, 2, 0, 0, 0, 0, 0, 0.0, p, 3),
            (datetime.datetime(2017, 7, 1, 22, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 3),
        ])
        summary_table = set(self.get_summary_table(cursor))
        self.assertEqual(summary_table, expected_summary)
Esempio n. 2
0
    def _test_setup_review_summary(self, time_zone, start_date_utc,
            end_date_utc, expected_stats):
        # Don't expect any reviews
        cursor = connection.cursor()
        review_stats = stats.select_review_stats(cursor, self.test_project_id,
                start_date_utc, end_date_utc, time_zone)
        self.assertEqual(review_stats, [])

        # Add test reviews
        self.add_test_reviews()

        # Expect empty summary table
        self.assert_empty_summary_table(cursor)

        # Expect correct statistics without summary tables
        review_stats = stats.select_review_stats(cursor, self.test_project_id,
                start_date_utc, end_date_utc, time_zone)
        self.assertEqual(review_stats, expected_stats)

        # Populate summary tables for two test time zones
        stats.populate_review_stats_summary(self.test_project_id, cursor=cursor)
        p = self.test_project_id
        expected_summary = set([
            (datetime.datetime(2017, 6, 1, 7, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 6, 30, 22, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 7, 2, 8, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 8, 2, 8, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 7, 1, 2, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 3),
            (datetime.datetime(2017, 7, 1, 7, 0, tzinfo=pytz.utc), 0, 2, 0, 0, 0, 0, 0, 0.0, p, 3),
            (datetime.datetime(2017, 7, 1, 22, 0, tzinfo=pytz.utc), 0, 1, 0, 0, 0, 0, 0, 0.0, p, 3),
        ])
        summary_table = set(self.get_summary_table(cursor))
        self.assertEqual(summary_table, expected_summary)
Esempio n. 3
0
    def _test_setup_connector_summary(self, time_zone, start_date_utc,
            end_date_utc, expected_stats):
        cursor = connection.cursor()

        # Remove connector links from fixture
        cursor.execute("""TRUNCATE treenode_connector""")

        # Don't expect any connector links
        review_stats = stats.select_review_stats(cursor, self.test_project_id,
                start_date_utc, end_date_utc, time_zone)
        self.assertEqual(review_stats, [])

        # Add test reviews
        self.add_test_connector_links()

        # Expect empty summary table
        self.assert_empty_summary_table(cursor)

        # Expect correct statistics without summary tables
        connector_stats = stats.select_connector_stats(cursor,
                self.test_project_id, start_date_utc, end_date_utc, time_zone)
        self.assertEqual(connector_stats, expected_stats)

        # Populate summary tables for two test time zones
        stats.populate_connector_stats_summary(self.test_project_id, cursor=cursor)
        p = self.test_project_id
        expected_summary = set([
            (datetime.datetime(2017, 6, 30, 22, 0, tzinfo=pytz.utc), 1, 0, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 7, 2, 8, 0, tzinfo=pytz.utc), 1, 0, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 8, 2, 8, 0, tzinfo=pytz.utc), 2, 0, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 7, 1, 7, 0, tzinfo=pytz.utc), 2, 0, 0, 0, 0, 0, 0, 0.0, p, 3),
            (datetime.datetime(2017, 7, 1, 22, 0, tzinfo=pytz.utc), 1, 0, 0, 0, 0, 0, 0, 0.0, p, 3),
        ])
        summary_table = set(self.get_summary_table(cursor))
        self.assertEqual(summary_table, expected_summary)
Esempio n. 4
0
    def _test_setup_connector_summary(self, time_zone, start_date_utc,
            end_date_utc, expected_stats):
        cursor = connection.cursor()

        # Remove connector links from fixture
        cursor.execute("""TRUNCATE treenode_connector""")

        # Don't expect any connector links
        review_stats = stats.select_review_stats(cursor, self.test_project_id,
                start_date_utc, end_date_utc, time_zone)
        self.assertEqual(review_stats, [])

        # Add test reviews
        self.add_test_connector_links()

        # Expect empty summary table
        self.assert_empty_summary_table(cursor)

        # Expect correct statistics without summary tables
        connector_stats = stats.select_connector_stats(cursor,
                self.test_project_id, start_date_utc, end_date_utc, time_zone)
        self.assertEqual(connector_stats, expected_stats)

        # Populate summary tables for two test time zones
        stats.populate_connector_stats_summary(self.test_project_id, cursor=cursor)
        p = self.test_project_id
        expected_summary = set([
            (datetime.datetime(2017, 6, 30, 22, 0, tzinfo=pytz.utc), 1, 0, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 7, 2, 8, 0, tzinfo=pytz.utc), 1, 0, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 8, 2, 8, 0, tzinfo=pytz.utc), 2, 0, 0, 0, 0, 0, 0, 0.0, p, 1),
            (datetime.datetime(2017, 7, 1, 7, 0, tzinfo=pytz.utc), 2, 0, 0, 0, 0, 0, 0, 0.0, p, 3),
            (datetime.datetime(2017, 7, 1, 22, 0, tzinfo=pytz.utc), 1, 0, 0, 0, 0, 0, 0, 0.0, p, 3),
        ])
        summary_table = set(self.get_summary_table(cursor))
        self.assertEqual(summary_table, expected_summary)
Esempio n. 5
0
    def test_review_stats_summary_population_no_tz_offset(self):
        time_zone = pytz.timezone('UTC')
        start_date_utc = time_zone.localize(datetime.datetime(
            2017, 7, 1, 0, 0))
        end_date_utc = time_zone.localize(datetime.datetime(2017, 8, 1, 0, 0))
        expected_stats = [(1, datetime.datetime(2017, 7, 2, 0, 0), 1),
                          (3, datetime.datetime(2017, 7, 1, 0, 0), 4)]

        self._test_setup_review_summary(time_zone, start_date_utc,
                                        end_date_utc, expected_stats)

        cursor = connection.cursor()
        # Expect correct statistics with summary tables with matching time zone
        review_stats = stats.select_review_stats(cursor, self.test_project_id,
                                                 start_date_utc, end_date_utc,
                                                 time_zone)
        self.assertEqual(review_stats, expected_stats)
Esempio n. 6
0
    def test_review_stats_summary_population_no_tz_offset(self):
        time_zone = pytz.timezone('UTC')
        start_date_utc = time_zone.localize(datetime.datetime(2017, 7, 1, 0, 0))
        end_date_utc = time_zone.localize(datetime.datetime(2017, 8, 1, 0, 0))
        expected_stats = [
            (1, datetime.datetime(2017, 7, 2, 0, 0), 1),
            (3, datetime.datetime(2017, 7, 1, 0, 0), 4)
        ]

        self._test_setup_review_summary(time_zone, start_date_utc,
                end_date_utc, expected_stats)

        cursor = connection.cursor()
        # Expect correct statistics with summary tables with matching time zone
        review_stats = stats.select_review_stats(cursor, self.test_project_id,
                start_date_utc, end_date_utc, time_zone)
        self.assertEqual(review_stats, expected_stats)