Skip to content

Commit 5a55ec0

Browse files
test: fix date-related timezone errors in tests (ietf-tools#4717)
* test: compare UTC dates in test_search_mail_archive() * test: compare datetimes, not dates, in action holders test * test: adjust test to match TZ used for IPR notification message * test: fix timezone in date_today() calls for liaisons tests * test: use settings.TIME_ZONE for date in nomination tests * test: correctly use settings.TIME_ZONE instead of system time zone
1 parent eb4b523 commit 5a55ec0

5 files changed

Lines changed: 24 additions & 16 deletions

File tree

ietf/doc/tests_review.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def test_search_mail_archive(self):
526526
messages = r.json()["messages"]
527527
self.assertEqual(len(messages), 2)
528528

529-
today = date_today()
529+
today = date_today(datetime.timezone.utc)
530530

531531
self.assertEqual(messages[0]["url"], "https://www.example.com/testmessage")
532532
self.assertTrue("John Doe" in messages[0]["content"])

ietf/doc/tests_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from unittest.mock import patch
66

77
from django.db import IntegrityError
8+
from django.utils import timezone
89

910
from ietf.group.factories import GroupFactory, RoleFactory
1011
from ietf.name.models import DocTagName
@@ -16,7 +17,6 @@
1617
from ietf.doc.utils import (update_action_holders, add_state_change_event, update_documentauthors,
1718
fuzzy_find_documents, rebuild_reference_relations)
1819
from ietf.utils.draft import Draft, PlaintextDraft
19-
from ietf.utils.timezone import date_today
2020
from ietf.utils.xmldraft import XMLDraft
2121

2222

@@ -147,10 +147,10 @@ def test_update_action_holders_resets_age(self):
147147
dah.time_added = datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc) # arbitrary date in the past
148148
dah.save()
149149

150-
today = date_today()
151-
self.assertNotEqual(doc.documentactionholder_set.get(person=self.ad).time_added.date(), today)
150+
right_now = timezone.now()
151+
self.assertLess(doc.documentactionholder_set.get(person=self.ad).time_added, right_now)
152152
self.update_doc_state(doc, State.objects.get(slug='ad-eval'))
153-
self.assertEqual(doc.documentactionholder_set.get(person=self.ad).time_added.date(), today)
153+
self.assertGreaterEqual(doc.documentactionholder_set.get(person=self.ad).time_added, right_now)
154154

155155
def test_update_action_holders_add_tag_need_rev(self):
156156
"""Adding need-rev tag adds authors as action holders"""

ietf/ipr/tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from pyquery import PyQuery
99
from urllib.parse import quote, urlparse
10+
from zoneinfo import ZoneInfo
1011

1112
from django.conf import settings
1213
from django.urls import reverse as urlreverse
@@ -595,7 +596,10 @@ def test_notify_generic(self):
595596
r = self.client.post(url, data )
596597
self.assertEqual(r.status_code,302)
597598
self.assertEqual(len(outbox),2)
598-
self.assertIn('Secretariat on '+ipr.get_latest_event_submitted().time.strftime("%Y-%m-%d"), get_payload_text(outbox[1]).replace('\n',' '))
599+
self.assertIn(
600+
'Secretariat on ' + ipr.get_latest_event_submitted().time.astimezone(ZoneInfo(settings.TIME_ZONE)).strftime("%Y-%m-%d"),
601+
get_payload_text(outbox[1]).replace('\n',' '),
602+
)
599603
self.assertIn(f'{settings.IDTRACKER_BASE_URL}{urlreverse("ietf.ipr.views.showlist")}', get_payload_text(outbox[1]).replace('\n',' '))
600604

601605
def send_ipr_email_helper(self):

ietf/liaisons/tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ def test_add_incoming_liaison(self):
700700
from_groups = [ str(g.pk) for g in Group.objects.filter(type="sdo") ]
701701
to_group = Group.objects.get(acronym="mars")
702702
submitter = Person.objects.get(user__username="marschairman")
703-
today = date_today()
703+
today = date_today(datetime.timezone.utc)
704704
related_liaison = liaison
705705
r = self.client.post(url,
706706
dict(from_groups=from_groups,
@@ -779,7 +779,7 @@ def test_add_outgoing_liaison(self):
779779
from_group = Group.objects.get(acronym="mars")
780780
to_group = Group.objects.filter(type="sdo")[0]
781781
submitter = Person.objects.get(user__username="marschairman")
782-
today = date_today()
782+
today = date_today(datetime.timezone.utc)
783783
related_liaison = liaison
784784
r = self.client.post(url,
785785
dict(from_groups=str(from_group.pk),
@@ -847,7 +847,7 @@ def test_add_outgoing_liaison_unapproved_post_only(self):
847847
from_group = Group.objects.get(acronym="mars")
848848
to_group = Group.objects.filter(type="sdo")[0]
849849
submitter = Person.objects.get(user__username="marschairman")
850-
today = date_today()
850+
today = date_today(datetime.timezone.utc)
851851
r = self.client.post(url,
852852
dict(from_groups=str(from_group.pk),
853853
from_contact=submitter.email_address(),
@@ -866,7 +866,7 @@ def test_add_outgoing_liaison_unapproved_post_only(self):
866866
self.assertEqual(len(outbox), mailbox_before + 1)
867867

868868
def test_liaison_add_attachment(self):
869-
liaison = LiaisonStatementFactory(deadline=date_today()+datetime.timedelta(days=1))
869+
liaison = LiaisonStatementFactory(deadline=date_today(DEADLINE_TZINFO)+datetime.timedelta(days=1))
870870
LiaisonStatementEventFactory(statement=liaison,type_id='submitted')
871871

872872
self.assertEqual(liaison.attachments.count(),0)

ietf/nomcom/tests.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pyquery import PyQuery
1111
from urllib.parse import urlparse
1212
from itertools import combinations
13+
from zoneinfo import ZoneInfo
1314

1415
from django.db import IntegrityError
1516
from django.db.models import Max
@@ -1506,11 +1507,12 @@ def test_help(self):
15061507
def test_accept_reject_nomination_edges(self):
15071508
self.client.logout()
15081509
np = self.nc.nominee_set.order_by('pk').first().nomineeposition_set.order_by('pk').first()
1510+
date_str = np.time.astimezone(ZoneInfo(settings.TIME_ZONE)).strftime("%Y%m%d")
15091511
kwargs={'year':self.nc.year(),
15101512
'nominee_position_id':np.id,
15111513
'state':'accepted',
1512-
'date':np.time.strftime("%Y%m%d"),
1513-
'hash':get_hash_nominee_position(np.time.strftime("%Y%m%d"),np.id),
1514+
'date':date_str,
1515+
'hash':get_hash_nominee_position(date_str, np.id),
15141516
}
15151517
url = reverse('ietf.nomcom.views.process_nomination_status', kwargs=kwargs)
15161518
response = self.client.get(url)
@@ -1520,8 +1522,9 @@ def test_accept_reject_nomination_edges(self):
15201522
settings.DAYS_TO_EXPIRE_NOMINATION_LINK = 2
15211523
np.time = np.time - datetime.timedelta(days=3)
15221524
np.save()
1523-
kwargs['date'] = np.time.strftime("%Y%m%d")
1524-
kwargs['hash'] = get_hash_nominee_position(np.time.strftime("%Y%m%d"),np.id)
1525+
date_str = np.time.astimezone(ZoneInfo(settings.TIME_ZONE)).strftime("%Y%m%d")
1526+
kwargs['date'] = date_str
1527+
kwargs['hash'] = get_hash_nominee_position(date_str, np.id)
15251528
url = reverse('ietf.nomcom.views.process_nomination_status', kwargs=kwargs)
15261529
response = self.client.get(url)
15271530
self.assertEqual(response.status_code,403)
@@ -1535,12 +1538,13 @@ def test_accept_reject_nomination_edges(self):
15351538

15361539
def test_accept_reject_nomination_comment(self):
15371540
np = self.nc.nominee_set.order_by('pk').first().nomineeposition_set.order_by('pk').first()
1538-
hash = get_hash_nominee_position(np.time.strftime("%Y%m%d"),np.id)
1541+
date_str = np.time.astimezone(ZoneInfo(settings.TIME_ZONE)).strftime("%Y%m%d")
1542+
hash = get_hash_nominee_position(date_str, np.id)
15391543
url = reverse('ietf.nomcom.views.process_nomination_status',
15401544
kwargs={'year':self.nc.year(),
15411545
'nominee_position_id':np.id,
15421546
'state':'accepted',
1543-
'date':np.time.strftime("%Y%m%d"),
1547+
'date':date_str,
15441548
'hash':hash,
15451549
}
15461550
)

0 commit comments

Comments
 (0)