mirror of
https://github.com/rjNemo/villafleurie
synced 2026-06-12 13:26:47 +00:00
booking price test case
This commit is contained in:
parent
771e8b7627
commit
9a9bc57a34
2 changed files with 10 additions and 17 deletions
|
|
@ -18,13 +18,13 @@ class Booking(models.Model):
|
||||||
end = models.DateField()
|
end = models.DateField()
|
||||||
price = models.DecimalField(max_digits=6, decimal_places=2, null=True)
|
price = models.DecimalField(max_digits=6, decimal_places=2, null=True)
|
||||||
|
|
||||||
def get_reservation_price(place, start, end):
|
def price(self):
|
||||||
""" Compute booking price as a function of place and dates """
|
""" Compute booking price as a function of place and dates """
|
||||||
|
|
||||||
if type(start) == str:
|
if type(self.start) == str:
|
||||||
start = datetime.strptime(start, '%Y-%m-%d')
|
self.start = datetime.strptime(self.start, '%Y-%m-%d')
|
||||||
if type(end) == str:
|
if type(self.end) == str:
|
||||||
end = datetime.strptime(end, '%Y-%m-%d')
|
self.end = datetime.strptime(self.end, '%Y-%m-%d')
|
||||||
nights = (end - start).days
|
nights = (self.end - self.start).days
|
||||||
|
|
||||||
return place.price * nights
|
return self.place.price * nights
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,8 @@ from rental.models.place import Place
|
||||||
from rental.models.booking import Booking
|
from rental.models.booking import Booking
|
||||||
from rental.models.guest import Guest
|
from rental.models.guest import Guest
|
||||||
|
|
||||||
place_name = 'T2'
|
|
||||||
place = get_object_or_404(Place, name=place_name)
|
|
||||||
|
|
||||||
|
class BookingTestCase(TestCase):
|
||||||
x = get_reservation_price(place_name, start, end)
|
|
||||||
print(x)
|
|
||||||
|
|
||||||
|
|
||||||
class TestBooking(TestCase):
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.place = Place.objects.create(
|
self.place = Place.objects.create(
|
||||||
name='TX',
|
name='TX',
|
||||||
|
|
@ -28,7 +21,7 @@ class TestBooking(TestCase):
|
||||||
self.start = datetime(2019, 11, 14)
|
self.start = datetime(2019, 11, 14)
|
||||||
self.end = datetime(2019, 11, 20)
|
self.end = datetime(2019, 11, 20)
|
||||||
|
|
||||||
def test_bookingPrice(self):
|
def test_BookingPrice(self):
|
||||||
# place = Place.objects.get(name='TX')
|
# place = Place.objects.get(name='TX')
|
||||||
booking = Booking.objects.create(
|
booking = Booking.objects.create(
|
||||||
place=self.place,
|
place=self.place,
|
||||||
|
|
@ -37,4 +30,4 @@ class TestBooking(TestCase):
|
||||||
guest=self.guest
|
guest=self.guest
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(booking.get_reservation_price())
|
self.assertEqual(booking.price(), 600)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue