def test_with_now_equal_to_booking_start_should_raise_error(
            self, datetime_mock):
        conditions = [{'percent': 50}]
        datetime_mock.now.return_value = datetime(2020, 4, 29)
        booking_end = datetime_mock.now()
        exc = None

        try:
            get_cancellation_policy(conditions, 10, booking_end)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Invalid booking start.')
Exemplo n.º 2
0
    def test_with_given_correct_data_should_calculate_correctly(self):
        # current_time = datetime(2020, 4, 27, 14, 0, 22, 599054)
        c_t = datetime.datetime(year=2020, month=4, day=24)

        datetime = Mock()
        datetime.now.return_value = c_t

        now = datetime.now()
        booking_start = now + timedelta(hours=0)
        price = 1000
        conditions = [{
            'hours': 24,
            'percent': 10
        }, {
            'hours': 12,
            'percent': 50
        }, {
            'hours': 6,
            'percent': 80
        }, {
            'percent': 100
        }]

        result = get_cancellation_policy(conditions, price, booking_start, now)

        assertEqual(result, price)
Exemplo n.º 3
0
    def test_cancellation_fee_with_several_conditions_and_now_in_them_and_decimal_percent(
            self, datetime_mock):
        conditions = [{
            'hours': 24,
            'percent': 10
        }, {
            'hours': 12,
            'percent': 50
        }, {
            'hours': 6,
            'percent': 65.5
        }, {
            'percent': 100
        }]
        price = 200
        datetime_mock.now.return_value = datetime(year=2020,
                                                  month=4,
                                                  day=25,
                                                  hour=12,
                                                  minute=33,
                                                  second=22)
        booking_start = datetime_mock.now() + timedelta(hours=10)

        result = get_cancellation_policy(conditions, price, booking_start)

        self.assertEqual(result, price * (65.5 / 100))
    def test_cancellation_fee_with_only_one_condition(self, datetime_mock):
        conditions = [{'percent': 50}]
        datetime_mock.now.return_value = datetime(2020, 4, 29)
        price = 100
        booking_end = datetime_mock.now() + timedelta(hours=100)

        result = get_cancellation_policy(conditions, price, booking_end)

        self.assertEqual(result, 50.0)
Exemplo n.º 5
0
    def test_with_now_equal_to_booking_start_should_raise_error(
            self, datetime_mock):
        conditions = [{'percent': 50}]

        datetime_mock.now.return_value = datetime(year=2020,
                                                  month=4,
                                                  day=25,
                                                  hour=12,
                                                  minute=33,
                                                  second=22)
        booking_start = datetime_mock.now()
        exc = None

        try:
            get_cancellation_policy(conditions, 10, booking_start)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Invalid booking start.')
Exemplo n.º 6
0
    def test_cancellation_fee_with_only_one_condition(self, datetime_mock):
        conditions = [{'percent': 50}]
        price = 100

        datetime_mock.now.return_value = datetime(year=2020,
                                                  month=4,
                                                  day=25,
                                                  hour=12,
                                                  minute=33,
                                                  second=22)
        booking_start = datetime_mock.now() + timedelta(hours=100)

        result = get_cancellation_policy(conditions, price, booking_start)

        self.assertEqual(result, 50.0)
    def test_cancellation_fee_with_several_conditions_and_now_in_them_and_decimal_percent(
            self, datetime_mock):
        conditions = [{
            'hours': 24,
            'percent': 10
        }, {
            'hours': 12,
            'percent': 50
        }, {
            'hours': 6,
            'percent': 65.5
        }, {
            'percent': 100
        }]
        price = 200
        datetime_mock.now.return_value = datetime(2020, 4, 29)
        booking_end = datetime_mock.now() + timedelta(hours=10)

        result = get_cancellation_policy(conditions, price, booking_end)

        self.assertEqual(result, price * (65.5 / 100))