def test_determine_if_full_summary_update_needed(self): """Test that we process full month under the correct conditions.""" dh = DateHelper() with schema_context(self.schema): bills = AWSCostEntryBill.objects.all() current_month_bill = bills.filter( billing_period_start=dh.this_month_start).first() last_month_bill = bills.filter( billing_period_start=dh.last_month_start).first() current_month_bill.summary_data_creation_datetime = datetime.now() current_month_bill.save() # Current month, previously summarized self.assertFalse( common_utils.determine_if_full_summary_update_needed( current_month_bill)) # Previous month self.assertTrue( common_utils.determine_if_full_summary_update_needed( last_month_bill)) current_month_bill.summary_data_creation_datetime = None current_month_bill.save() # Current month, has not been summarized before self.assertTrue( common_utils.determine_if_full_summary_update_needed( current_month_bill))
def _get_sql_inputs(self, start_date, end_date): """Get the required inputs for running summary SQL.""" with GCPReportDBAccessor(self._schema) as accessor: # This is the normal processing route if self._manifest: # Override the bill date to correspond with the manifest bill_date = self._manifest.billing_period_start_datetime.date() bills = accessor.get_cost_entry_bills_query_by_provider( self._provider.uuid) bills = bills.filter(billing_period_start=bill_date).all() first_bill = bills.filter( billing_period_start=bill_date).first() do_month_update = False with schema_context(self._schema): if first_bill: do_month_update = determine_if_full_summary_update_needed( first_bill) if do_month_update: last_day_of_month = calendar.monthrange( bill_date.year, bill_date.month)[1] start_date = bill_date end_date = bill_date.replace(day=last_day_of_month) LOG.info( "Overriding start and end date to process full month.") if isinstance(start_date, str): start_date = ciso8601.parse_datetime(start_date).date() if isinstance(end_date, str): end_date = ciso8601.parse_datetime(end_date).date() return start_date, end_date