def test_previous_month(self): """Test the previous_month method.""" current_month = timezone.now().replace(microsecond=0, second=0, minute=0, hour=0, day=1) last_month = current_month.replace(month=(current_month.month - 1)) self.assertEqual(last_month, ReportQueryHandler.previous_month(current_month))
def test_get_time_frame_filter_previous_month(self): """Test _get_time_frame_filter for previous month.""" query_params = { 'filter': { 'resolution': 'daily', 'time_scope_value': -2, 'time_scope_units': 'month' } } handler = ReportQueryHandler(query_params, '', self.tenant, 'unblended_cost', 'currency_code') current_month = timezone.now().replace(microsecond=0, second=0, minute=0, hour=0, day=1) prev_month = ReportQueryHandler.previous_month(current_month) start = handler.start_datetime end = handler.end_datetime interval = handler.time_interval self.assertEqual(start, prev_month) self.assertEqual(end, current_month) self.assertIsInstance(interval, list) self.assertTrue(len(interval) >= 28)