From 473bd093c9fa74a32b12e47f93e06b099dd099b8 Mon Sep 17 00:00:00 2001 From: Jacek Lebioda <jacek.lebioda@uni.lu> Date: Wed, 7 Oct 2020 11:05:04 +0200 Subject: [PATCH] fix: corrections to make_aware --- smash/web/tests/functions.py | 10 +++++++--- smash/web/utils.py | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/smash/web/tests/functions.py b/smash/web/tests/functions.py index 459c2479..9d735aaf 100644 --- a/smash/web/tests/functions.py +++ b/smash/web/tests/functions.py @@ -3,7 +3,7 @@ import logging import os from django.contrib.auth.models import User -from django.utils.timezone import make_aware +from django.utils.timezone import make_aware, is_aware from web.models import Location, AppointmentType, StudySubject, Worker, Visit, Appointment, ConfigurationItem, \ Language, ContactAttempt, FlyingTeam, Availability, Subject, Study, StudyColumns, StudyNotificationParameters, \ @@ -312,6 +312,8 @@ def create_visit(subject=None, datetime_begin=None, datetime_end=None): def create_appointment(visit=None, when=None, length=30): if visit is None: visit = create_visit() + if not is_aware(when): + when = make_aware(when) # if when is None: # when = get_today_midnight_date() return Appointment.objects.create( @@ -319,15 +321,17 @@ def create_appointment(visit=None, when=None, length=30): length=length, location=get_test_location(), status=Appointment.APPOINTMENT_STATUS_SCHEDULED, - datetime_when=make_aware(when)) + datetime_when=when) def create_appointment_without_visit(when=None, length=30): + if not is_aware(when): + when = make_aware(when) return Appointment.objects.create( length=length, location=get_test_location(), status=Appointment.APPOINTMENT_STATUS_SCHEDULED, - datetime_when=make_aware(when)) + datetime_when=when) def create_configuration_item(): diff --git a/smash/web/utils.py b/smash/web/utils.py index 3bc35e31..dd61c944 100644 --- a/smash/web/utils.py +++ b/smash/web/utils.py @@ -3,10 +3,9 @@ from django.utils import timezone import datetime from datetime import timedelta -from django.utils.timezone import make_aware - from web.algorithm import VerhoeffAlgorithm, LuhnAlgorithm + def is_valid_social_security_number(number): if number is not None and number != '': if len(number) != 13: @@ -24,8 +23,12 @@ def is_valid_social_security_number(number): def get_today_midnight_date(): today = timezone.now() today_midnight = datetime.datetime( - today.year, today.month, today.day, tzinfo=today.tzinfo) - return make_aware(today_midnight) + today.year, + today.month, + today.day, + tzinfo=today.tzinfo + ) + return today_midnight def get_weekdays_in_period(fromdate, todate): -- GitLab