From 3220bf3c40f96b129c6b43af9c4056b9d41ca7c5 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 18 Oct 2022 12:45:47 -0300 Subject: [PATCH] chore: replace last few datetime.date.today() calls with date_today() --- bin/add-old-drafts-from-archive.py | 3 ++- ietf/bin/rfc-editor-index-updates | 3 ++- ietf/doc/factories.py | 3 ++- ietf/doc/models.py | 5 +++-- ietf/doc/tests_ballot.py | 3 ++- ietf/doc/tests_review.py | 2 +- ietf/doc/tests_utils.py | 6 ++++-- ietf/doc/utils.py | 2 +- ietf/doc/utils_search.py | 7 +++++-- ietf/doc/views_review.py | 4 ++-- ietf/group/tests_js.py | 3 ++- ietf/group/tests_review.py | 2 +- ietf/group/views.py | 2 +- ietf/ietfauth/tests.py | 2 +- ietf/liaisons/tests.py | 2 +- .../management/commands/meetecho_conferences.py | 3 ++- ietf/meeting/models.py | 2 +- ietf/meeting/tests_helpers.py | 8 +++++--- ietf/meeting/tests_js.py | 4 ++-- ietf/nomcom/tests.py | 12 ++++++------ ietf/nomcom/utils.py | 4 ++-- ietf/review/tests.py | 8 ++++---- ietf/secr/sreq/tests.py | 10 +++++----- ietf/submit/forms.py | 2 +- ietf/submit/models.py | 3 ++- ietf/submit/views.py | 2 +- ietf/utils/draft.py | 5 ++++- 27 files changed, 65 insertions(+), 47 deletions(-) diff --git a/bin/add-old-drafts-from-archive.py b/bin/add-old-drafts-from-archive.py index 5f7b37783..239ba7837 100755 --- a/bin/add-old-drafts-from-archive.py +++ b/bin/add-old-drafts-from-archive.py @@ -16,6 +16,7 @@ from django.conf import settings from django.core.validators import validate_email, ValidationError from ietf.utils.draft import PlaintextDraft from ietf.submit.utils import update_authors +from ietf.utils.timezone import date_today import debug # pyflakes:ignore @@ -140,7 +141,7 @@ for name in sorted(names): doc = doc, rev = rev, by = system, - desc = "Revision added from id-archive on %s by %s"%(datetime.date.today(),sys.argv[0]), + desc = "Revision added from id-archive on %s by %s"%(date_today(),sys.argv[0]), time=time, ) events.append(e) diff --git a/ietf/bin/rfc-editor-index-updates b/ietf/bin/rfc-editor-index-updates index 4ff3bf373..dc7abe26b 100755 --- a/ietf/bin/rfc-editor-index-updates +++ b/ietf/bin/rfc-editor-index-updates @@ -29,6 +29,7 @@ from django.core.mail import mail_admins from ietf.doc.utils import rebuild_reference_relations from ietf.utils.log import log from ietf.utils.pipe import pipe +from ietf.utils.timezone import date_today import ietf.sync.rfceditor @@ -39,7 +40,7 @@ parser.add_option("-d", dest="skip_date", options, args = parser.parse_args() -skip_date = datetime.date.today() - datetime.timedelta(days=365) +skip_date = date_today() - datetime.timedelta(days=365) if options.skip_date: skip_date = datetime.datetime.strptime(options.skip_date, "%Y-%m-%d").date() diff --git a/ietf/doc/factories.py b/ietf/doc/factories.py index 568e79cc7..40e0f506b 100644 --- a/ietf/doc/factories.py +++ b/ietf/doc/factories.py @@ -19,6 +19,7 @@ from ietf.group.models import Group from ietf.person.factories import PersonFactory from ietf.group.factories import RoleFactory from ietf.utils.text import xslugify +from ietf.utils.timezone import date_today def draft_name_generator(type_id,group,n): @@ -321,7 +322,7 @@ class ConflictReviewFactory(BaseDocumentFactory): # This is very skeletal. It is enough for the tests that use it now, but when it's needed, it will need to be improved with, at least, a group generator that backs the object with a review team. class ReviewFactory(BaseDocumentFactory): type_id = 'review' - name = factory.LazyAttribute(lambda o: 'review-doesnotexist-00-%s-%s'%(o.group.acronym,datetime.date.today().isoformat())) + name = factory.LazyAttribute(lambda o: 'review-doesnotexist-00-%s-%s'%(o.group.acronym,date_today().isoformat())) group = factory.SubFactory('ietf.group.factories.GroupFactory',type_id='review') class DocAliasFactory(factory.django.DjangoModelFactory): diff --git a/ietf/doc/models.py b/ietf/doc/models.py index 9ef5cc657..c6e06fecd 100644 --- a/ietf/doc/models.py +++ b/ietf/doc/models.py @@ -922,8 +922,9 @@ class Document(DocumentInfo): def last_presented(self): """ returns related SessionPresentation objects for the most recent meeting in the past""" # Assumes no two meetings have the same start date - if the assumption is violated, one will be chosen arbitrariy - candidate_presentations = self.sessionpresentation_set.filter(session__meeting__date__lte=datetime.date.today()) - candidate_meetings = set([p.session.meeting for p in candidate_presentations if p.session.meeting.end_date() 5) draft_search_string = draft.name[-5:] diff --git a/ietf/group/tests_review.py b/ietf/group/tests_review.py index b00d4dc20..fc09e27e0 100644 --- a/ietf/group/tests_review.py +++ b/ietf/group/tests_review.py @@ -558,7 +558,7 @@ class ReviewTests(TestCase): # get r = self.client.get(url) self.assertEqual(r.status_code, 200) - self.assertEqual(r.context['period_form']['start_date'].initial, datetime.date.today()) + self.assertEqual(r.context['period_form']['start_date'].initial, date_today()) # set settings empty_outbox() diff --git a/ietf/group/views.py b/ietf/group/views.py index f4352599c..4bc31d09f 100644 --- a/ietf/group/views.py +++ b/ietf/group/views.py @@ -1028,7 +1028,7 @@ def edit(request, group_type=None, acronym=None, action="edit", field=None): change_text=title + ' deleted: ' + ", ".join(x.name_and_email() for x in deleted) personnel_change_text+=change_text+"\n" - today = datetime.date.today() + today = date_today() for deleted_email in deleted: # Verify the person doesn't have a separate reviewer role for the group with a different address if not group.role_set.filter(name_id='reviewer',person=deleted_email.person).exists(): diff --git a/ietf/ietfauth/tests.py b/ietf/ietfauth/tests.py index be1d52f80..e2b842a86 100644 --- a/ietf/ietfauth/tests.py +++ b/ietf/ietfauth/tests.py @@ -394,7 +394,7 @@ class IetfAuthTests(TestCase): self.assertFalse(q('#volunteer-button')) self.assertFalse(q('#volunteered')) - year = datetime.date.today().year + year = date_today().year nomcom = NomComFactory(group__acronym=f'nomcom{year}',is_accepting_volunteers=True) r = self.client.get(url) self.assertEqual(r.status_code,200) diff --git a/ietf/liaisons/tests.py b/ietf/liaisons/tests.py index 293277fef..845271db7 100644 --- a/ietf/liaisons/tests.py +++ b/ietf/liaisons/tests.py @@ -866,7 +866,7 @@ class LiaisonManagementTests(TestCase): self.assertEqual(len(outbox), mailbox_before + 1) def test_liaison_add_attachment(self): - liaison = LiaisonStatementFactory(deadline=datetime.date.today()+datetime.timedelta(days=1)) + liaison = LiaisonStatementFactory(deadline=date_today()+datetime.timedelta(days=1)) LiaisonStatementEventFactory(statement=liaison,type_id='submitted') self.assertEqual(liaison.attachments.count(),0) diff --git a/ietf/meeting/management/commands/meetecho_conferences.py b/ietf/meeting/management/commands/meetecho_conferences.py index e6525d7dc..c3220d4cf 100644 --- a/ietf/meeting/management/commands/meetecho_conferences.py +++ b/ietf/meeting/management/commands/meetecho_conferences.py @@ -9,6 +9,7 @@ from django.core.management.base import BaseCommand, CommandError from ietf.meeting.models import Session from ietf.utils.meetecho import ConferenceManager, MeetechoAPIError +from ietf.utils.timezone import date_today class Command(BaseCommand): @@ -85,7 +86,7 @@ class Command(BaseCommand): for conf in confs: conf_sessions[conf.id] = Session.objects.filter( group__acronym=group, - meeting__date__gte=datetime.date.today(), + meeting__date__gte=date_today(), remote_instructions__contains=conf.url, ) return confs, conf_sessions diff --git a/ietf/meeting/models.py b/ietf/meeting/models.py index 523548b5c..83b245f76 100644 --- a/ietf/meeting/models.py +++ b/ietf/meeting/models.py @@ -750,7 +750,7 @@ class Schedule(models.Model): @property def is_official_record(self): return (self.is_official and - self.meeting.end_date() <= datetime.date.today() ) + self.meeting.end_date() <= date_today() ) # returns a dictionary {group -> [schedtimesessassignment+]} # and it has [] if the session is not placed. diff --git a/ietf/meeting/tests_helpers.py b/ietf/meeting/tests_helpers.py index 3160f9388..d77610baa 100644 --- a/ietf/meeting/tests_helpers.py +++ b/ietf/meeting/tests_helpers.py @@ -18,6 +18,7 @@ from ietf.meeting.models import SchedTimeSessAssignment, Session from ietf.meeting.test_data import make_meeting_test_data from ietf.utils.meetecho import Conference from ietf.utils.test_utils import TestCase +from ietf.utils.timezone import date_today # override the legacy office hours setting to guarantee consistency with the tests @@ -623,12 +624,13 @@ class HelperTests(TestCase): def test_get_ietf_meeting(self): """get_ietf_meeting() should only return IETF meetings""" # put the IETF far in the past so it's not "current" - ietf = MeetingFactory(type_id='ietf', date=datetime.date.today() - datetime.timedelta(days=5 * 365)) + today = date_today() + ietf = MeetingFactory(type_id='ietf', date=today- datetime.timedelta(days=5 * 365)) # put the interim meeting now so it will be picked up as "current" if there's a bug - interim = MeetingFactory(type_id='interim', date=datetime.date.today()) + interim = MeetingFactory(type_id='interim', date=today) self.assertEqual(get_ietf_meeting(ietf.number), ietf, 'Return IETF meeting by number') self.assertIsNone(get_ietf_meeting(interim.number), 'Ignore non-IETF meetings') self.assertIsNone(get_ietf_meeting(), 'Return None if there is no current IETF meeting') - ietf.date = datetime.date.today() + ietf.date = today ietf.save() self.assertEqual(get_ietf_meeting(), ietf, 'Return current meeting if there is one') diff --git a/ietf/meeting/tests_js.py b/ietf/meeting/tests_js.py index 68feae0a0..d93835ac6 100644 --- a/ietf/meeting/tests_js.py +++ b/ietf/meeting/tests_js.py @@ -831,7 +831,7 @@ class EditMeetingScheduleTests(IetfSeleniumTestCase): To test for recurrence of https://trac.ietf.org/trac/ietfdb/ticket/3327 need to have some constraints that do not conflict. Testing with only violated constraints does not exercise the code adequately. """ - meeting = MeetingFactory(type_id='ietf', date=datetime.date.today(), populate_schedule=False) + meeting = MeetingFactory(type_id='ietf', date=date_today(), populate_schedule=False) TimeSlotFactory.create_batch(5, meeting=meeting) schedule = ScheduleFactory(meeting=meeting) sessions = SessionFactory.create_batch(5, meeting=meeting, add_to_schedule=False) @@ -1444,7 +1444,7 @@ class ProceedingsMaterialTests(IetfSeleniumTestCase): def setUp(self): super().setUp() self.wait = WebDriverWait(self.driver, 2) - self.meeting = MeetingFactory(type_id='ietf', number='123', date=datetime.date.today()) + self.meeting = MeetingFactory(type_id='ietf', number='123', date=date_today()) def test_add_proceedings_material(self): url = self.absreverse( diff --git a/ietf/nomcom/tests.py b/ietf/nomcom/tests.py index 1a5365cf2..0577ca558 100644 --- a/ietf/nomcom/tests.py +++ b/ietf/nomcom/tests.py @@ -2244,7 +2244,8 @@ class EligibilityUnitTests(TestCase): def test_get_eligibility_date(self): # No Nomcoms exist: - self.assertEqual(get_eligibility_date(), datetime.date(datetime.date.today().year,5,1)) + this_year = date_today().year + self.assertEqual(get_eligibility_date(), datetime.date(this_year,5,1)) # a provided date trumps anything in the database self.assertEqual(get_eligibility_date(date=datetime.date(2001,2,3)), datetime.date(2001,2,3)) @@ -2258,7 +2259,7 @@ class EligibilityUnitTests(TestCase): n.save() self.assertEqual(get_eligibility_date(nomcom=n), datetime.date(2015,5,17)) # No nomcoms in the database with seated members - self.assertEqual(get_eligibility_date(), datetime.date(datetime.date.today().year,5,1)) + self.assertEqual(get_eligibility_date(), datetime.date(this_year,5,1)) RoleFactory(group=n.group,name_id='member') self.assertEqual(get_eligibility_date(),datetime.date(2016,5,1)) @@ -2266,7 +2267,6 @@ class EligibilityUnitTests(TestCase): NomComFactory(group__acronym='nomcom2016', populate_personnel=False, first_call_for_volunteers=datetime.date(2016,5,4)) self.assertEqual(get_eligibility_date(),datetime.date(2016,5,4)) - this_year = datetime.date.today().year NomComFactory(group__acronym=f'nomcom{this_year}', first_call_for_volunteers=datetime.date(this_year,5,6)) self.assertEqual(get_eligibility_date(),datetime.date(this_year,5,6)) @@ -2636,8 +2636,8 @@ class VolunteerTests(TestCase): r = self.client.get(url) self.assertContains(r, 'NomCom is not accepting volunteers at this time', status_code=200) - year = datetime.date.today().year - nomcom = NomComFactory(group__acronym=f'nomcom{year}', is_accepting_volunteers=False) + this_year = date_today().year + nomcom = NomComFactory(group__acronym=f'nomcom{this_year}', is_accepting_volunteers=False) r = self.client.get(url) self.assertContains(r, 'NomCom is not accepting volunteers at this time', status_code=200) nomcom.is_accepting_volunteers = True @@ -2660,7 +2660,7 @@ class VolunteerTests(TestCase): self.assertContains(r, 'already volunteered', status_code=200) person.volunteer_set.all().delete() - nomcom2 = NomComFactory(group__acronym=f'nomcom{year-1}', is_accepting_volunteers=True) + nomcom2 = NomComFactory(group__acronym=f'nomcom{this_year-1}', is_accepting_volunteers=True) r = self.client.get(url) self.assertEqual(r.status_code, 200) q = PyQuery(r.content) diff --git a/ietf/nomcom/utils.py b/ietf/nomcom/utils.py index d8eaf25e9..50712f9aa 100644 --- a/ietf/nomcom/utils.py +++ b/ietf/nomcom/utils.py @@ -626,7 +626,7 @@ def get_eligibility_date(nomcom=None, date=None): last_seated=Role.objects.filter(group__type_id='nomcom',name_id='member').order_by('-group__acronym').first() if last_seated: last_nomcom_year = int(last_seated.group.acronym[6:]) - if last_nomcom_year == datetime.date.today().year: + if last_nomcom_year == date_today().year: next_nomcom_year = last_nomcom_year else: next_nomcom_year = int(last_seated.group.acronym[6:])+1 @@ -640,7 +640,7 @@ def get_eligibility_date(nomcom=None, date=None): def previous_five_meetings(date = None): if date is None: - date = datetime.date.today() + date = date_today() return Meeting.objects.filter(type='ietf',date__lte=date).order_by('-date')[:5] def three_of_five_eligible_8713(previous_five, queryset=None): diff --git a/ietf/review/tests.py b/ietf/review/tests.py index 260a8646d..43294801e 100644 --- a/ietf/review/tests.py +++ b/ietf/review/tests.py @@ -5,7 +5,7 @@ import datetime from ietf.group.factories import RoleFactory from ietf.utils.mail import empty_outbox, get_payload_text, outbox from ietf.utils.test_utils import TestCase, reload_db_objects -from ietf.utils.timezone import datetime_from_date +from ietf.utils.timezone import date_today, datetime_from_date from .factories import ReviewAssignmentFactory, ReviewRequestFactory, ReviewerSettingsFactory from .mailarch import hash_list_message_id from .models import ReviewerSettings, ReviewSecretarySettings, ReviewTeamSettings, UnavailablePeriod @@ -75,7 +75,7 @@ class ReviewAssignmentTest(TestCase): class ReviewAssignmentReminderTests(TestCase): - today = datetime.date.today() + today = date_today() deadline = today + datetime.timedelta(days=6) def setUp(self): @@ -346,7 +346,7 @@ class ReviewAssignmentReminderTests(TestCase): def test_send_unavailability_period_ending_reminder(self): secretary = self.make_secretary(username='reviewsecretary') empty_outbox() - today = datetime.date.today() + today = date_today() UnavailablePeriod.objects.create( team=self.team, person=self.reviewer, @@ -470,7 +470,7 @@ class ReviewAssignmentReminderTests(TestCase): self.assertIn('1 overdue review', log[0]) def test_send_reminder_all_open_reviews(self): - today = datetime.date.today() + today = date_today() self.make_secretary(username='reviewsecretary') ReviewerSettingsFactory(team=self.team, person=self.reviewer, remind_days_open_reviews=1) diff --git a/ietf/secr/sreq/tests.py b/ietf/secr/sreq/tests.py index dd945beaf..7f6707b4d 100644 --- a/ietf/secr/sreq/tests.py +++ b/ietf/secr/sreq/tests.py @@ -244,7 +244,7 @@ class SessionRequestTestCase(TestCase): def test_edit_constraint_bethere(self): - meeting = MeetingFactory(type_id='ietf', date=datetime.date.today()) + meeting = MeetingFactory(type_id='ietf', date=date_today()) mars = RoleFactory(name_id='chair', person__user__username='marschairman', group__acronym='mars').group session = SessionFactory(meeting=meeting, group=mars, status_id='sched') Constraint.objects.create( @@ -311,7 +311,7 @@ class SessionRequestTestCase(TestCase): def test_edit_inactive_conflicts(self): """Inactive conflicts should be displayed and removable""" - meeting = MeetingFactory(type_id='ietf', date=datetime.date.today(), group_conflicts=['chair_conflict']) + meeting = MeetingFactory(type_id='ietf', date=date_today(), group_conflicts=['chair_conflict']) mars = RoleFactory(name_id='chair', person__user__username='marschairman', group__acronym='mars').group session = SessionFactory(meeting=meeting, group=mars, status_id='sched') other_group = GroupFactory() @@ -383,7 +383,7 @@ class SessionRequestTestCase(TestCase): Relies on SessionForm representing constraint values with element IDs like id_constraint_ """ - meeting = MeetingFactory(type_id='ietf', date=datetime.date.today()) + meeting = MeetingFactory(type_id='ietf', date=date_today()) RoleFactory(name_id='chair', person__user__username='marschairman', group__acronym='mars') url = reverse('ietf.secr.sreq.views.new', kwargs=dict(acronym='mars')) self.client.login(username="marschairman", password="marschairman+password") @@ -406,7 +406,7 @@ class SessionRequestTestCase(TestCase): def test_edit_req_constraint_types(self): """Editing a request constraint should show the expected constraints""" - meeting = MeetingFactory(type_id='ietf', date=datetime.date.today()) + meeting = MeetingFactory(type_id='ietf', date=date_today()) SessionFactory(group__acronym='mars', status_id='schedw', meeting=meeting, @@ -701,7 +701,7 @@ class SubmitRequestCase(TestCase): self.assertNotIn('The third session requires your approval', notification_payload) def test_request_notification_third_session(self): - meeting = MeetingFactory(type_id='ietf', date=datetime.date.today()) + meeting = MeetingFactory(type_id='ietf', date=date_today()) ad = Person.objects.get(user__username='ad') area = GroupFactory(type_id='area') RoleFactory(name_id='ad', person=ad, group=area) diff --git a/ietf/submit/forms.py b/ietf/submit/forms.py index 828387280..4715f9bb5 100644 --- a/ietf/submit/forms.py +++ b/ietf/submit/forms.py @@ -156,7 +156,7 @@ class SubmissionBaseUploadForm(forms.Form): raise forms.ValidationError('The submission tool is currently shut down') # check general submission rate thresholds before doing any more work - today = datetime.date.today() + today = date_today() self.check_submissions_thresholds( "for the same submitter", dict(remote_ip=self.remote_ip, submission_date=today), diff --git a/ietf/submit/models.py b/ietf/submit/models.py index 629303296..09d52b368 100644 --- a/ietf/submit/models.py +++ b/ietf/submit/models.py @@ -19,6 +19,7 @@ from ietf.name.models import DraftSubmissionStateName, FormalLanguageName from ietf.utils.accesstoken import generate_random_key, generate_access_token from ietf.utils.text import parse_unicode from ietf.utils.models import ForeignKey +from ietf.utils.timezone import date_today def parse_email_line(line): @@ -54,7 +55,7 @@ class Submission(models.Model): file_types = models.CharField(max_length=50, blank=True) file_size = models.IntegerField(null=True, blank=True) document_date = models.DateField(null=True, blank=True) - submission_date = models.DateField(default=datetime.date.today) + submission_date = models.DateField(default=date_today) xml_version = models.CharField(null=True, max_length=4, default=None) submitter = models.CharField(max_length=255, blank=True, help_text="Name and email of submitter, e.g. \"John Doe <john@example.org>\".") diff --git a/ietf/submit/views.py b/ietf/submit/views.py index 80137eba4..9dcb88d13 100644 --- a/ietf/submit/views.py +++ b/ietf/submit/views.py @@ -163,7 +163,7 @@ def api_submission(request): submission.state = DraftSubmissionStateName.objects.get(slug="validating") submission.remote_ip = form.remote_ip submission.file_types = ','.join(form.file_types) - submission.submission_date = datetime.date.today() + submission.submission_date = date_today() submission.submitter = user.person.formatted_email() submission.replaces = form.cleaned_data['replaces'] submission.save() diff --git a/ietf/utils/draft.py b/ietf/utils/draft.py index 12a614701..0a379b0e9 100755 --- a/ietf/utils/draft.py +++ b/ietf/utils/draft.py @@ -50,6 +50,9 @@ import time from typing import Dict, List # pyflakes:ignore +from .timezone import date_today + + version = "0.35" program = os.path.basename(sys.argv[0]) progdir = os.path.dirname(sys.argv[0]) @@ -467,7 +470,7 @@ class PlaintextDraft(Draft): month = int(mon) else: continue - today = datetime.date.today() + today = date_today() if day==0: # if the date was given with only month and year, use # today's date if month and year is today's month and