Commit e3f926a3 authored by Patrick Kimber's avatar Patrick Kimber

test 'get_calendars' for bookings with no end date #1181

parent df4a5645
......@@ -92,20 +92,26 @@ class HtmlCalendar(object):
def _get_bookings(self):
qs = Booking.objects.public_calendar_widget(
self.start_date, self.end_date
self.start_date,
self.end_date,
)
result = {}
for b in qs:
if not b.start_date in result:
result[b.start_date] = BookingCount()
result[b.start_date].set_afternoon()
if not b.end_date in result:
result[b.end_date] = BookingCount()
result[b.end_date].set_morning()
for d in rrule(DAILY, dtstart=b.start_date, until=b.end_date):
if not d.date() in result:
result[d.date()] = BookingCount()
result[d.date()].increment()
if b.end_date:
if not b.end_date in result:
result[b.end_date] = BookingCount()
result[b.end_date].set_morning()
# fill the in-between dates
for d in rrule(DAILY, dtstart=b.start_date, until=b.end_date):
if not d.date() in result:
result[d.date()] = BookingCount()
result[d.date()].increment()
else:
# start_date is the end date - set morning and afternoon
result[b.start_date].set_morning()
return result
def _generate_html(self, d, bookings):
......
......@@ -66,6 +66,20 @@ def test_get_calendars_html():
assert "<td>06</td>" in html
@pytest.mark.django_db
def test_get_calendars_no_end_date_html():
today = date.today()
BookingFactory(start_date=date(today.year, today.month, 3))
c = HtmlCalendar()
result = c.get_calendars(count=1)
assert list is type(result)
assert 1 == len(result)
html = result[0]
assert "<td>02</td>" in html
assert "<td class='booked'>03</td>" in html
assert "<td>04</td>" in html
@pytest.mark.django_db
def test_booking_count():
c = BookingCount()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment