booking price test case

This commit is contained in:
Ruidy Nemausat 2020-04-07 11:26:37 +02:00
parent 771e8b7627
commit 9a9bc57a34
2 changed files with 10 additions and 17 deletions

View file

@ -18,13 +18,13 @@ class Booking(models.Model):
end = models.DateField()
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 """
if type(start) == str:
start = datetime.strptime(start, '%Y-%m-%d')
if type(end) == str:
end = datetime.strptime(end, '%Y-%m-%d')
nights = (end - start).days
if type(self.start) == str:
self.start = datetime.strptime(self.start, '%Y-%m-%d')
if type(self.end) == str:
self.end = datetime.strptime(self.end, '%Y-%m-%d')
nights = (self.end - self.start).days
return place.price * nights
return self.place.price * nights

View file

@ -5,15 +5,8 @@ from rental.models.place import Place
from rental.models.booking import Booking
from rental.models.guest import Guest
place_name = 'T2'
place = get_object_or_404(Place, name=place_name)
x = get_reservation_price(place_name, start, end)
print(x)
class TestBooking(TestCase):
class BookingTestCase(TestCase):
def setUp(self):
self.place = Place.objects.create(
name='TX',
@ -28,7 +21,7 @@ class TestBooking(TestCase):
self.start = datetime(2019, 11, 14)
self.end = datetime(2019, 11, 20)
def test_bookingPrice(self):
def test_BookingPrice(self):
# place = Place.objects.get(name='TX')
booking = Booking.objects.create(
place=self.place,
@ -37,4 +30,4 @@ class TestBooking(TestCase):
guest=self.guest
)
self.assertEqual(booking.get_reservation_price())
self.assertEqual(booking.price(), 600)