def test_monthly_tables_rejects_invalid_dates(self): """Reject invalid table dates.""" # 2009-01-31 is before M-Lab epoch. with self.assertRaises(ValueError): table_names.monthly_tables( datetime.datetime(2009, 1, 31), datetime.datetime(2009, 3, 1)) # It should never be possible to generate table names for future dates. with self.assertRaises(ValueError): table_names.monthly_tables( datetime.datetime.now(), datetime.datetime.now() + datetime.timedelta(days=1))
def _generate_per_month_query(self): conditions = [] conditions.append(_format_project_condition(self._project)) if _project_has_intermediate_snapshots(self._project): conditions.append('web100_log_entry.is_last_entry = True') conditions.append(self._format_time_range_condition()) tables = table_names.monthly_tables(self._time_range_start, self._time_range_end) return _construct_test_id_subquery(tables, conditions)
def test_monthly_tables(self): """Generate monthly table names for valid date range.""" self.assertSequenceEqual( ('plx.google:m_lab.2009_02.all', 'plx.google:m_lab.2009_03.all'), table_names.monthly_tables( datetime.datetime(2009, 2, 11), datetime.datetime(2009, 3, 1))) # Rounding down to 2009-02-01 is okay even though M-Lab epoch is # 2009-02-11 because the 2009_02 table still exists. self.assertSequenceEqual( ('plx.google:m_lab.2009_02.all',), table_names.monthly_tables( datetime.datetime(2009, 2, 1), datetime.datetime(2009, 2, 15))) # Including the 1-day buffer, 2012-01-01 spills over into the previous # month's table. self.assertSequenceEqual( ('plx.google:m_lab.2011_12.all', 'plx.google:m_lab.2012_01.all', 'plx.google:m_lab.2012_02.all'), table_names.monthly_tables( datetime.datetime(2012, 1, 1), datetime.datetime(2012, 2, 1)))