Skip to content
Snippets Groups Projects
Commit 6e14f116 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

tests should use timezoned dates

parent a7a39439
No related branches found
No related tags found
1 merge request!272Resolve "fix datetime without TZ warnings"
...@@ -183,7 +183,7 @@ class AppointmentsViewTests(LoggedInTestCase): ...@@ -183,7 +183,7 @@ class AppointmentsViewTests(LoggedInTestCase):
def test_save_appointments_edit(self): def test_save_appointments_edit(self):
subject = create_study_subject() subject = create_study_subject()
visit = create_visit(subject) visit = create_visit(subject)
visit.datetime_begin = "2011-01-01" visit.datetime_begin = timezone.now().replace(year=2011)
visit.save() visit.save()
visit = Visit.objects.get(id=visit.id) visit = Visit.objects.get(id=visit.id)
......
...@@ -2,6 +2,7 @@ import datetime ...@@ -2,6 +2,7 @@ import datetime
import logging import logging
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.utils import timezone
from web.models import Appointment, Location, AppointmentTypeLink, Study, Visit from web.models import Appointment, Location, AppointmentTypeLink, Study, Visit
from web.models.constants import GLOBAL_STUDY_ID, VOUCHER_STATUS_USED from web.models.constants import GLOBAL_STUDY_ID, VOUCHER_STATUS_USED
...@@ -34,16 +35,16 @@ class NotificationViewTests(LoggedInTestCase): ...@@ -34,16 +35,16 @@ class NotificationViewTests(LoggedInTestCase):
original_notification = get_exceeded_visit_notifications_count(self.user) original_notification = get_exceeded_visit_notifications_count(self.user)
subject = create_study_subject() subject = create_study_subject()
Visit.objects.create(datetime_begin="2011-01-01", Visit.objects.create(datetime_begin=timezone.now().replace(year=2011, month=1, day=1),
datetime_end="2011-01-02", datetime_end=timezone.now().replace(year=2011, month=1, day=2),
subject=subject) subject=subject)
# first visit doesn't go to notifications # first visit doesn't go to notifications
notification = get_exceeded_visit_notifications_count(self.user) notification = get_exceeded_visit_notifications_count(self.user)
self.assertEqual(original_notification.count, notification.count) self.assertEqual(original_notification.count, notification.count)
Visit.objects.create(datetime_begin="2012-01-01", Visit.objects.create(datetime_begin=timezone.now().replace(year=2012, month=1, day=1),
datetime_end="2012-01-02", datetime_end=timezone.now().replace(year=2012, month=1, day=2),
subject=subject) subject=subject)
notification = get_exceeded_visit_notifications_count(self.user) notification = get_exceeded_visit_notifications_count(self.user)
...@@ -51,8 +52,8 @@ class NotificationViewTests(LoggedInTestCase): ...@@ -51,8 +52,8 @@ class NotificationViewTests(LoggedInTestCase):
def test_get_exceeded_visit_notifications_count_for_first_visit(self): def test_get_exceeded_visit_notifications_count_for_first_visit(self):
subject = create_study_subject() subject = create_study_subject()
visit = Visit.objects.create(datetime_begin="2011-01-01", visit = Visit.objects.create(datetime_begin=timezone.now().replace(year=2011, month=1, day=1),
datetime_end="2011-01-02", datetime_end=timezone.now().replace(year=2011, month=1, day=2),
subject=subject) subject=subject)
appointment = create_appointment(visit) appointment = create_appointment(visit)
appointment.status = Appointment.APPOINTMENT_STATUS_FINISHED appointment.status = Appointment.APPOINTMENT_STATUS_FINISHED
...@@ -65,7 +66,7 @@ class NotificationViewTests(LoggedInTestCase): ...@@ -65,7 +66,7 @@ class NotificationViewTests(LoggedInTestCase):
subject = create_study_subject() subject = create_study_subject()
visit = create_visit(subject) visit = create_visit(subject)
visit.datetime_end = "2011-01-01" visit.datetime_end = timezone.now().replace(year=2011)
visit.is_finished = True visit.is_finished = True
visit.save() visit.save()
create_appointment(visit) create_appointment(visit)
...@@ -356,7 +357,7 @@ class NotificationViewTests(LoggedInTestCase): ...@@ -356,7 +357,7 @@ class NotificationViewTests(LoggedInTestCase):
subject = create_study_subject() subject = create_study_subject()
visit = create_visit(subject) visit = create_visit(subject)
appointment = create_appointment(visit) 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.status = Appointment.APPOINTMENT_STATUS_SCHEDULED
appointment.save() appointment.save()
...@@ -366,7 +367,7 @@ class NotificationViewTests(LoggedInTestCase): ...@@ -366,7 +367,7 @@ class NotificationViewTests(LoggedInTestCase):
def test_get_unfinished_appointments_count_for_general_appointments(self): def test_get_unfinished_appointments_count_for_general_appointments(self):
appointment = create_appointment() appointment = create_appointment()
appointment.visit = None 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.status = Appointment.APPOINTMENT_STATUS_SCHEDULED
appointment.save() appointment.save()
...@@ -378,7 +379,7 @@ class NotificationViewTests(LoggedInTestCase): ...@@ -378,7 +379,7 @@ class NotificationViewTests(LoggedInTestCase):
subject = create_study_subject() subject = create_study_subject()
visit = create_visit(subject) visit = create_visit(subject)
appointment = create_appointment(visit) 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.status = Appointment.APPOINTMENT_STATUS_CANCELLED
appointment.save() appointment.save()
...@@ -578,7 +579,7 @@ class NotificationViewTests(LoggedInTestCase): ...@@ -578,7 +579,7 @@ class NotificationViewTests(LoggedInTestCase):
notification = get_subject_voucher_expiry_notifications_count(self.user) notification = get_subject_voucher_expiry_notifications_count(self.user)
self.assertEqual(original_notification.count, notification.count) 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() contact_attempt.save()
notification = get_subject_voucher_expiry_notifications_count(self.user) notification = get_subject_voucher_expiry_notifications_count(self.user)
......
...@@ -2,6 +2,7 @@ import datetime ...@@ -2,6 +2,7 @@ import datetime
import logging import logging
from django.urls import reverse from django.urls import reverse
from django.utils import timezone
from web.forms import VisitDetailForm from web.forms import VisitDetailForm
from web.models import Visit, MailTemplate from web.models import Visit, MailTemplate
...@@ -250,7 +251,7 @@ class VisitViewTests(LoggedInTestCase): ...@@ -250,7 +251,7 @@ class VisitViewTests(LoggedInTestCase):
def test_exceeded_visits(self): def test_exceeded_visits(self):
visit = create_visit() visit = create_visit()
visit.datetime_end = "2011-01-01" visit.datetime_end = timezone.now().replace(year=2011)
visit.save() visit.save()
response = self.client.get(reverse("web.views.exceeded_visits")) response = self.client.get(reverse("web.views.exceeded_visits"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment