From 40ecf864670030c81e450ca34fda4eb8b6fbe703 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Valentin=20Grou=C3=A8s?= <valentin.groues@uni.lu>
Date: Fri, 31 Mar 2017 15:12:45 +0200
Subject: [PATCH] fix date dependant test

---
 smash/web/tests/test_statistics.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/smash/web/tests/test_statistics.py b/smash/web/tests/test_statistics.py
index 3c6286ce..b4302710 100644
--- a/smash/web/tests/test_statistics.py
+++ b/smash/web/tests/test_statistics.py
@@ -6,16 +6,19 @@ from django.test import TestCase
 from web.models import Visit
 from web.statistics import get_previous_year_and_month_for_date, StatisticsManager
 from web.tests.functions import create_appointment, create_appointment_type
+from web.views.notifications import get_today_midnight_date
 
 __author__ = 'Valentin Grouès'
 
 
 class TestStatistics(TestCase):
     def setUp(self):
-        self.now = datetime.datetime.now()
+        self.now = get_today_midnight_date()
         self.appointment_type = create_appointment_type()
         appointment = create_appointment(when=self.now)
         appointment.appointment_types = [self.appointment_type]
+        self.visit_start = appointment.visit.datetime_begin
+        self.visit_end = appointment.visit.datetime_end
         appointment.save()
         self.subject = appointment.visit.subject
         self.statistics_manager = StatisticsManager()
@@ -31,13 +34,13 @@ class TestStatistics(TestCase):
         self.assertEqual(12, previous_month)
 
     def test_get_statistics_for_month_one_appointment(self):
-        statistics = self.statistics_manager.get_statistics_for_month(self.now.month - 1, self.now.year)
+        statistics = self.statistics_manager.get_statistics_for_month(self.visit_start.month, self.now.year)
         self.check_statistics(statistics, 1, 0, 0, {"C": [0, 0]}, ['Scheduled'])
 
         statistics = self.statistics_manager.get_statistics_for_month(self.now.month, self.now.year)
         self.check_statistics(statistics, 0, 0, 1, {"C": [1, 1]}, ['Scheduled'])
 
-        statistics = self.statistics_manager.get_statistics_for_month(self.now.month + 1, self.now.year)
+        statistics = self.statistics_manager.get_statistics_for_month(self.visit_end.month, self.now.year)
         self.check_statistics(statistics, 0, 1, 0, {"C": [0, 0]}, ['Scheduled'])
 
     def test_get_statistics_for_month_one_appointment_visit(self):
-- 
GitLab