diff options
author | Sean <ssmith@iol.unh.edu> | 2020-03-03 10:54:20 -0500 |
---|---|---|
committer | Sean <ssmith@iol.unh.edu> | 2020-03-16 14:50:00 -0400 |
commit | aaff0c1a5abc850db49dc72a79abb581be8cfcfc (patch) | |
tree | 385931496aba116c6d8f2c4f1cefc99e92b1e591 /src/booking/tests | |
parent | 8eab4c4a801a367f74347627c19dd721f75c7a62 (diff) |
Fixed a few bugs for the stats functions and created a few tests.
Signed-off-by: Sean <ssmith@iol.unh.edu>
Change-Id: I2e4598811bddabe5b7447c3a92d39d16acb77a03
Signed-off-by: Sean <ssmith@iol.unh.edu>
Diffstat (limited to 'src/booking/tests')
-rw-r--r-- | src/booking/tests/test_stats.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/booking/tests/test_stats.py b/src/booking/tests/test_stats.py new file mode 100644 index 0000000..5501355 --- /dev/null +++ b/src/booking/tests/test_stats.py @@ -0,0 +1,59 @@ +############################################################################# +# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, Sean Smith, and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import pytz +from datetime import timedelta, datetime + +from django.test import TestCase + +from booking.models import Booking +from booking.stats import StatisticsManager as sm +from dashboard.testing_utils import make_user + + +class StatsTestCases(TestCase): + + def test_no_booking_outside_span(self): + now = datetime.now(pytz.utc) + + bad_date = now + timedelta(days=1200) + Booking.objects.create(start=now, end=bad_date, owner=make_user(username='jj')) + + actual = sm.getContinuousBookingTimeSeries() + dates = actual['booking'][0] + + for date in dates: + self.assertNotEqual(date, bad_date) + + def check_booking_and_user_counts(self): + now = datetime.now(pytz.utc) + + for i in range(20): + Booking.objects.create( + start=now, + end=now + timedelta(weeks=3), + owner=make_user(username='a')) + + for i in range(30): + Booking.objects.create( + start=now + timedelta(days=5), + end=now + timedelta(weeks=3, days=5), + owner=make_user(username='a')) + + for i in range(120): + Booking.objects.create( + start=now + timedelta(weeks=1), + end=now + timedelta(weeks=4), + owner=make_user(username='a')) + + dates = [[now, 20], [now + timedelta(days=5), 30], [now + timedelta(weeks=1), 120]] + actual = sm.getContinuousBookingTimeSeries() + + for date in dates: + self.assertEqual(date[1], actual['booking'][date[0]]) + self.assertEqual(date[1], actual['booking'][date[1]]) |