def test_multiple_subscriptions_due_today(self):
        # Create two subscriptions with end_date 0 days from now.
        subscription_one = self.create_subscription(self.account,
                                                    end_date=days_later(0))
        workflow_state_one = self.create_conversion_workflow_state(
            subscription_one, ConversionWorkflowStatus.sent_one_week_notice)

        subscription_two = self.create_subscription(self.account,
                                                    end_date=days_later(0))
        workflow_state_two = self.create_conversion_workflow_state(
            subscription_two, ConversionWorkflowStatus.sent_two_week_notice)

        process = NotifySubscriptionsDueToday()
        process.process()

        workflow_state_one.refresh()
        self.assertEqual(workflow_state_one.status,
                         ConversionWorkflowStatus.sent_final_notice)

        workflow_state_two.refresh()
        self.assertEqual(workflow_state_two.status,
                         ConversionWorkflowStatus.sent_final_notice)
    def test_subscriptions_due_in_twenty_eight_days_process(self):
        # Create subscription with end_date 28 days from now.
        subscription = self.create_subscription(self.account,
                                                end_date=days_later(28))
        workflow_state = self.create_conversion_workflow_state(
            subscription, ConversionWorkflowStatus.ok)

        process = NotifySubscriptionsDueInTwentyEightDays()
        process.process()

        workflow_state.refresh()
        self.assertEqual(workflow_state.status,
                         ConversionWorkflowStatus.sent_four_week_notice)
    def test_subscriptions_due_today_with_overdue_subscription(self):
        # Create subscription with end_date 1 days from now.
        subscription = self.create_subscription(self.account,
                                                end_date=days_later(-1))
        workflow_state = self.create_conversion_workflow_state(
            subscription, ConversionWorkflowStatus.sent_one_week_notice)

        process = NotifySubscriptionsDueToday()
        process.process()

        workflow_state.refresh()
        self.assertEqual(workflow_state.status,
                         ConversionWorkflowStatus.sent_final_notice)
    def test_subscriptions_due_in_fourteen_days_process(self):
        # Create subscription with end_date 14 days from now.
        subscription = self.create_subscription(self.account,
                                                end_date=days_later(14))
        workflow_state = self.create_conversion_workflow_state(
            subscription, ConversionWorkflowStatus.sent_four_week_notice)

        process = NotifySubscriptionsDueInFourteenDays()
        process.process()

        workflow_state.refresh()
        self.assertEqual(workflow_state.status,
                         ConversionWorkflowStatus.sent_two_week_notice)
    def test_subscriptions_due_today_with_older_status(self):
        # Create subscription with end_date 0 days from now.
        subscription = self.create_subscription(self.account,
                                                end_date=days_later(0))

        # Create a workflow state that is drastically out of date by multiple statuses
        workflow_state = self.create_conversion_workflow_state(
            subscription, ConversionWorkflowStatus.sent_four_week_notice)

        process = NotifySubscriptionsDueToday()
        process.process()

        workflow_state.refresh()
        self.assertEqual(workflow_state.status,
                         ConversionWorkflowStatus.sent_final_notice)