def test_set_dueDate_reporting_auto(self):
        self.prepare_mocked_contract()
        manager = CeasefireMilestoneManager(Mock())

        approval_milestone_mock = Mock()
        approval_milestone_mock.type_ = 'approval'
        approval_milestone_mock.get.return_value = 'approval'
        approval_milestone_mock.dateMet = datetime.now()
        reporting_milestone_mock = Mock()
        reporting_milestone_mock.type_ = 'reporting'
        reporting_milestone_mock.dueDate = None
        self.contract.milestones = (approval_milestone_mock,
                                    reporting_milestone_mock)
        self.contract.dateSigned = datetime.now()

        target_dueDate = datetime.combine(
            date(
                approval_milestone_mock.dateMet.year +
                MILESTONE_REPORTING_DUEDATE_OFFSET_YEARS,
                approval_milestone_mock.dateMet.month,
                approval_milestone_mock.dateMet.day,
            ), approval_milestone_mock.dateMet.time())
        manager.set_dueDate(reporting_milestone_mock, self.contract)
        self.assertEqual(reporting_milestone_mock.dueDate, target_dueDate,
                         'dueDate has been calculated incorrectly')
    def test_set_dueDate_financing(self):
        self.prepare_mocked_contract()
        manager = CeasefireMilestoneManager(Mock())

        milestone_mock = Mock()
        milestone_mock.type_ = 'financing'

        self.contract.dateSigned = datetime.now()
        target_dueDate = calculate_business_date(
            self.contract.dateSigned,
            MILESTONE_FINANCING_DUEDATE_OFFSET,
            context=None,
            working_days=True,
            specific_hour=18)
        manager.set_dueDate(milestone_mock, self.contract)
        self.assertEqual(milestone_mock.dueDate, target_dueDate,
                         'dueDate has been calculated incorrectly')
    def test_set_dueDate_financing_with_accelerator(self):
        self.prepare_mocked_contract()
        manager = CeasefireMilestoneManager(Mock())

        milestone_mock = Mock()
        milestone_mock.type_ = 'financing'

        if SANDBOX_MODE:
            self.contract.sandbox_parameters = 'quick, accelerator=1440'
        self.contract.dateSigned = datetime.now()

        target_dueDate = calculate_business_date(
            self.contract.dateSigned,
            MILESTONE_FINANCING_DUEDATE_OFFSET,
            context=self.contract,
            working_days=True,
            specific_hour=18)
        manager.set_dueDate(milestone_mock, self.contract)
        self.assertEqual(milestone_mock.dueDate, target_dueDate,
                         'dueDate has been calculated incorrectly')
    def test_set_dueDate_approval(self):
        self.prepare_mocked_contract()
        manager = CeasefireMilestoneManager(Mock())

        financing_milestone_mock = Mock()
        financing_milestone_mock.type_ = 'financing'
        financing_milestone_mock.get.return_value = 'financing'
        financing_milestone_mock.dateMet = datetime.now()
        approval_milestone_mock = Mock()
        approval_milestone_mock.type_ = 'approval'
        self.contract.milestones = (financing_milestone_mock, approval_milestone_mock)

        self.contract.dateSigned = datetime.now()
        target_dueDate = calculate_business_date(
            financing_milestone_mock.dateMet,
            MILESTONE_APPROVAL_DUEDATE_OFFSET,
            context=None,
            working_days=False,
            specific_hour=18,
            result_is_working_day=True)
        manager.set_dueDate(approval_milestone_mock, self.contract)
        self.assertEqual(approval_milestone_mock.dueDate, target_dueDate, 'dueDate has been calculated incorrectly')