1 #############################################################################
2 # Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, Sean Smith, and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from datetime import timedelta, datetime
12 from django.test import TestCase
14 from booking.models import Booking
15 from booking.stats import StatisticsManager as sm
16 from dashboard.testing_utils import make_user
19 class StatsTestCases(TestCase):
21 def test_no_booking_outside_span(self):
22 now = datetime.now(pytz.utc)
24 bad_date = now + timedelta(days=1200)
25 Booking.objects.create(start=now, end=bad_date, owner=make_user(username='jj'))
27 actual = sm.getContinuousBookingTimeSeries()
28 dates = actual['booking'][0]
31 self.assertNotEqual(date, bad_date)
33 def check_booking_and_user_counts(self):
34 now = datetime.now(pytz.utc)
37 Booking.objects.create(
39 end=now + timedelta(weeks=3),
40 owner=make_user(username='a'))
43 Booking.objects.create(
44 start=now + timedelta(days=5),
45 end=now + timedelta(weeks=3, days=5),
46 owner=make_user(username='a'))
49 Booking.objects.create(
50 start=now + timedelta(weeks=1),
51 end=now + timedelta(weeks=4),
52 owner=make_user(username='a'))
54 dates = [[now, 20], [now + timedelta(days=5), 30], [now + timedelta(weeks=1), 120]]
55 actual = sm.getContinuousBookingTimeSeries()
58 self.assertEqual(date[1], actual['booking'][date[0]])
59 self.assertEqual(date[1], actual['booking'][date[1]])