From 6e14f116b813d5528060878604ea93c6dd9d5b13 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Mon, 16 Nov 2020 08:37:30 +0100
Subject: [PATCH] tests should use timezoned dates

---
 smash/web/tests/view/test_appointments.py  |  2 +-
 smash/web/tests/view/test_notifications.py | 23 +++++++++++-----------
 smash/web/tests/view/test_visit.py         |  3 ++-
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/smash/web/tests/view/test_appointments.py b/smash/web/tests/view/test_appointments.py
index 38af3ed5..6cf7ec0f 100644
--- a/smash/web/tests/view/test_appointments.py
+++ b/smash/web/tests/view/test_appointments.py
@@ -183,7 +183,7 @@ class AppointmentsViewTests(LoggedInTestCase):
     def test_save_appointments_edit(self):
         subject = create_study_subject()
         visit = create_visit(subject)
-        visit.datetime_begin = "2011-01-01"
+        visit.datetime_begin = timezone.now().replace(year=2011)
         visit.save()
         visit = Visit.objects.get(id=visit.id)
 
diff --git a/smash/web/tests/view/test_notifications.py b/smash/web/tests/view/test_notifications.py
index bcaf2f66..a95c1ddf 100644
--- a/smash/web/tests/view/test_notifications.py
+++ b/smash/web/tests/view/test_notifications.py
@@ -2,6 +2,7 @@ import datetime
 import logging
 
 from django.contrib.auth.models import AnonymousUser
+from django.utils import timezone
 
 from web.models import Appointment, Location, AppointmentTypeLink, Study, Visit
 from web.models.constants import GLOBAL_STUDY_ID, VOUCHER_STATUS_USED
@@ -34,16 +35,16 @@ class NotificationViewTests(LoggedInTestCase):
         original_notification = get_exceeded_visit_notifications_count(self.user)
 
         subject = create_study_subject()
-        Visit.objects.create(datetime_begin="2011-01-01",
-                             datetime_end="2011-01-02",
+        Visit.objects.create(datetime_begin=timezone.now().replace(year=2011, month=1, day=1),
+                             datetime_end=timezone.now().replace(year=2011, month=1, day=2),
                              subject=subject)
 
         # first visit doesn't go to notifications
         notification = get_exceeded_visit_notifications_count(self.user)
         self.assertEqual(original_notification.count, notification.count)
 
-        Visit.objects.create(datetime_begin="2012-01-01",
-                             datetime_end="2012-01-02",
+        Visit.objects.create(datetime_begin=timezone.now().replace(year=2012, month=1, day=1),
+                             datetime_end=timezone.now().replace(year=2012, month=1, day=2),
                              subject=subject)
 
         notification = get_exceeded_visit_notifications_count(self.user)
@@ -51,8 +52,8 @@ class NotificationViewTests(LoggedInTestCase):
 
     def test_get_exceeded_visit_notifications_count_for_first_visit(self):
         subject = create_study_subject()
-        visit = Visit.objects.create(datetime_begin="2011-01-01",
-                                     datetime_end="2011-01-02",
+        visit = Visit.objects.create(datetime_begin=timezone.now().replace(year=2011, month=1, day=1),
+                                     datetime_end=timezone.now().replace(year=2011, month=1, day=2),
                                      subject=subject)
         appointment = create_appointment(visit)
         appointment.status = Appointment.APPOINTMENT_STATUS_FINISHED
@@ -65,7 +66,7 @@ class NotificationViewTests(LoggedInTestCase):
 
         subject = create_study_subject()
         visit = create_visit(subject)
-        visit.datetime_end = "2011-01-01"
+        visit.datetime_end = timezone.now().replace(year=2011)
         visit.is_finished = True
         visit.save()
         create_appointment(visit)
@@ -356,7 +357,7 @@ class NotificationViewTests(LoggedInTestCase):
         subject = create_study_subject()
         visit = create_visit(subject)
         appointment = create_appointment(visit)
-        appointment.datetime_when = "2011-01-01"
+        appointment.datetime_when = timezone.now().replace(year=2011)
         appointment.status = Appointment.APPOINTMENT_STATUS_SCHEDULED
         appointment.save()
 
@@ -366,7 +367,7 @@ class NotificationViewTests(LoggedInTestCase):
     def test_get_unfinished_appointments_count_for_general_appointments(self):
         appointment = create_appointment()
         appointment.visit = None
-        appointment.datetime_when = "2011-01-01"
+        appointment.datetime_when = timezone.now().replace(year=2011, month=1, day=1)
         appointment.status = Appointment.APPOINTMENT_STATUS_SCHEDULED
         appointment.save()
 
@@ -378,7 +379,7 @@ class NotificationViewTests(LoggedInTestCase):
         subject = create_study_subject()
         visit = create_visit(subject)
         appointment = create_appointment(visit)
-        appointment.datetime_when = "2011-01-01"
+        appointment.datetime_when = timezone.now().replace(year=2011, month=1, day=1)
         appointment.status = Appointment.APPOINTMENT_STATUS_CANCELLED
         appointment.save()
 
@@ -578,7 +579,7 @@ class NotificationViewTests(LoggedInTestCase):
         notification = get_subject_voucher_expiry_notifications_count(self.user)
         self.assertEqual(original_notification.count, notification.count)
 
-        contact_attempt.datetime_when = "2011-11-11"
+        contact_attempt.datetime_when = timezone.now().replace(year=2011, month=11, day=11)
         contact_attempt.save()
 
         notification = get_subject_voucher_expiry_notifications_count(self.user)
diff --git a/smash/web/tests/view/test_visit.py b/smash/web/tests/view/test_visit.py
index 7b870c81..9600e0da 100644
--- a/smash/web/tests/view/test_visit.py
+++ b/smash/web/tests/view/test_visit.py
@@ -2,6 +2,7 @@ import datetime
 import logging
 
 from django.urls import reverse
+from django.utils import timezone
 
 from web.forms import VisitDetailForm
 from web.models import Visit, MailTemplate
@@ -250,7 +251,7 @@ class VisitViewTests(LoggedInTestCase):
 
     def test_exceeded_visits(self):
         visit = create_visit()
-        visit.datetime_end = "2011-01-01"
+        visit.datetime_end = timezone.now().replace(year=2011)
         visit.save()
 
         response = self.client.get(reverse("web.views.exceeded_visits"))
-- 
GitLab