def test_create_reminder_email( self, mock_send_estimated_land_date_reminder, adviser, ): """ Create reminder should create a model instance and send an email. """ days_left = 30 estimated_land_date = self.current_date + relativedelta(months=1) project = ActiveInvestmentProjectFactory( project_manager=adviser, estimated_land_date=estimated_land_date, status=InvestmentProject.Status.ONGOING, ) create_reminder( project=project, adviser=adviser, days_left=days_left, send_email=True, current_date=self.current_date, ) reminders = UpcomingEstimatedLandDateReminder.objects.filter( adviser=adviser, project=project, ) assert reminders.count() == 1 assert reminders[ 0].event == f'{days_left} days left to estimated land date' mock_send_estimated_land_date_reminder.assert_called_with( project=project, adviser=adviser, days_left=days_left, )
def test_create_another_reminder_after_estimated_land_date_change( self, mock_send_estimated_land_date_reminder, adviser, ): """ If the estimated land date is changed and a reminder has already been sent out, a new reminder should be created and a new email sent. """ days_left = 30 estimated_land_date = self.current_date + relativedelta(months=1) project = ActiveInvestmentProjectFactory( project_manager=adviser, estimated_land_date=estimated_land_date, status=InvestmentProject.Status.ONGOING, ) with freeze_time('2010-07-01T10:00:00'): UpcomingEstimatedLandDateReminder.objects.create( adviser=adviser, project=project, event=f'{days_left} days left to estimated land date', ) create_reminder( project=project, adviser=adviser, days_left=days_left, send_email=True, current_date=self.current_date, ) reminders = UpcomingEstimatedLandDateReminder.objects.filter( adviser=adviser, project=project, ) assert reminders.count() == 2 assert mock_send_estimated_land_date_reminder.call_count == 1
def test_create_existing_reminder_slow_queue( self, mock_send_estimated_land_date_reminder, adviser, ): """ If the queue is still processing tasks from yesterday and a reminder was already sent, do not send another one. """ days_left = 30 estimated_land_date = self.current_date + relativedelta(months=1) project = ActiveInvestmentProjectFactory( project_manager=adviser, estimated_land_date=estimated_land_date, status=InvestmentProject.Status.ONGOING, ) with freeze_time('2022-07-01T10:00:00'): UpcomingEstimatedLandDateReminder.objects.create( adviser=adviser, project=project, event=f'{days_left} days left to estimated land date', ) with freeze_time('2022-07-02T10:00:00'): create_reminder( project=project, adviser=adviser, days_left=days_left, send_email=True, current_date=self.current_date, ) reminders = UpcomingEstimatedLandDateReminder.objects.filter( adviser=adviser, project=project, ) assert reminders.count() == 1 assert mock_send_estimated_land_date_reminder.call_count == 0