def test_with_current_date_in_condition_interval_should_return_higher_condition_percent(
            self, datetime_mock):
        conditions = [({
            'hours': 24,
            'percent': 0
        }, {
            'hours': 18,
            'percent': 20
        }), ({
            'hours': 18,
            'percent': 20
        }, {
            'hours': 12,
            'percent': 50
        }), ({
            'hours': 12,
            'percent': 50
        }, {
            'hours': 6,
            'percent': 80
        }), ({
            'hours': 6,
            'percent': 80
        }, {
            'hours': 0,
            'percent': 100
        })]
        datetime_mock.now.return_value = datetime(year=2020, month=4, day=29)

        booking_start = datetime_mock.now() + timedelta(hours=10)
        # print(timedelta(hours=10))
        result = get_current_condition(conditions, booking_start)

        self.assertEqual(result, 80)
    def test_with_current_date_equal_to_condition_hours_should_return_interval_upper_boundary_percent(
            self, datetime_mock):
        conditions = [({
            'hours': 24,
            'percent': 0
        }, {
            'hours': 18,
            'percent': 20
        }), ({
            'hours': 18,
            'percent': 20
        }, {
            'hours': 12,
            'percent': 50
        }), ({
            'hours': 12,
            'percent': 50
        }, {
            'hours': 6,
            'percent': 80
        }), ({
            'hours': 6,
            'percent': 80
        }, {
            'hours': 0,
            'percent': 100
        })]
        datetime_mock.now.return_value = datetime(2020, 4, 29)
        booking_end = datetime_mock.now() + timedelta(hours=6)

        result = get_current_condition(conditions, booking_end)

        self.assertEqual(result, 100)
 def test_with_current_date_before_min_condition_date_should_return_min_condition_percent(
         self, datetime_mock):
     datetime_mock.now.return_value = datetime(2020, 4, 29)
     conditions = [({
         'hours': 24,
         'percent': 0
     }, {
         'hours': 18,
         'percent': 20
     }), ({
         'hours': 18,
         'percent': 20
     }, {
         'hours': 12,
         'percent': 50
     }), ({
         'hours': 12,
         'percent': 50
     }, {
         'hours': 6,
         'percent': 80
     }), ({
         'hours': 6,
         'percent': 80
     }, {
         'hours': 0,
         'percent': 100
     })]
     booking_end = datetime_mock.now() - timedelta(hours=100)
     result = get_current_condition(conditions, booking_end)
     self.assertEqual(result, 0)
예제 #4
0
    def test_with_current_date_equal_to_condition_hours_should_return_interval_upper_boundary_percent(
            self):
        conditions = [({
            'hours': 24,
            'percent': 0
        }, {
            'hours': 18,
            'percent': 20
        }), ({
            'hours': 18,
            'percent': 20
        }, {
            'hours': 12,
            'percent': 50
        }), ({
            'hours': 12,
            'percent': 50
        }, {
            'hours': 6,
            'percent': 80
        }), ({
            'hours': 6,
            'percent': 80
        }, {
            'hours': 0,
            'percent': 100
        })]
        booking_start = datetime.now()
        now = booking_start - timedelta(hours=6)

        result = get_current_condition(conditions, booking_start, now)

        self.assertEqual(result, 100)
예제 #5
0
    def test_with_current_date_before_min_condition_date_should_return_min_condition_percent(
            self):
        conditions = [({
            'hours': 24,
            'percent': 0
        }, {
            'hours': 18,
            'percent': 20
        }), ({
            'hours': 18,
            'percent': 20
        }, {
            'hours': 12,
            'percent': 50
        }), ({
            'hours': 12,
            'percent': 50
        }, {
            'hours': 6,
            'percent': 80
        }), ({
            'hours': 6,
            'percent': 80
        }, {
            'hours': 0,
            'percent': 100
        })]
        booking_start = datetime.now()
        now = booking_start - timedelta(hours=100)

        result = get_current_condition(conditions, booking_start, now)

        self.assertEqual(result, 0)
예제 #6
0
    def test_get_current_condition_with_one_element_with_given_value_more_than_24_hours(
            self):
        conditions = [{'hours': 0, 'percent': 10}]

        now = datetime.now()
        booking_start = now + timedelta(hours=360)

        percent = get_current_condition(conditions, booking_start, now)

        self.assertEqual(percent, 10)
	def test_get_current_condition_with_two_elements_with_given_value_between_the_two_boundaries(self):
		conditions = [
			{'hours' : 10, 'percent': 20},
			{'hours' : 0, 'percent': 100}
		]

		now = datetime.now()
		booking_start = now + timedelta(hours=5)

		percent = get_current_condition(conditions, booking_start, now)

		self.assertEqual(percent,100)
	def test_get_current_condition_with_more_than_two_elements_with_value_equal_to_first_value_more_than_0(self):

		conditions = [
			{ 'hours' : 24, 'percent' : 10 },
			{ 'hours' : 12, 'percent' : 50 },
			{ 'hours' : 6, 'percent': 80 },
			{ 'hours' : 0, 'percent' : 100 }
		]

		now = datetime.now()
		booking_start = now + timedelta(hours=6)

		percent = get_current_condition(conditions, booking_start, now)

		self.assertEqual(percent,100)