test: fix date-related timezone errors in tests (#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
This commit is contained in:
parent
eb4b523e66
commit
5a55ec0959
|
@ -526,7 +526,7 @@ class ReviewTests(TestCase):
|
||||||
messages = r.json()["messages"]
|
messages = r.json()["messages"]
|
||||||
self.assertEqual(len(messages), 2)
|
self.assertEqual(len(messages), 2)
|
||||||
|
|
||||||
today = date_today()
|
today = date_today(datetime.timezone.utc)
|
||||||
|
|
||||||
self.assertEqual(messages[0]["url"], "https://www.example.com/testmessage")
|
self.assertEqual(messages[0]["url"], "https://www.example.com/testmessage")
|
||||||
self.assertTrue("John Doe" in messages[0]["content"])
|
self.assertTrue("John Doe" in messages[0]["content"])
|
||||||
|
|
|
@ -5,6 +5,7 @@ import debug # pyflakes:ignore
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from ietf.group.factories import GroupFactory, RoleFactory
|
from ietf.group.factories import GroupFactory, RoleFactory
|
||||||
from ietf.name.models import DocTagName
|
from ietf.name.models import DocTagName
|
||||||
|
@ -16,7 +17,6 @@ from ietf.doc.models import State, DocumentActionHolder, DocumentAuthor, Documen
|
||||||
from ietf.doc.utils import (update_action_holders, add_state_change_event, update_documentauthors,
|
from ietf.doc.utils import (update_action_holders, add_state_change_event, update_documentauthors,
|
||||||
fuzzy_find_documents, rebuild_reference_relations)
|
fuzzy_find_documents, rebuild_reference_relations)
|
||||||
from ietf.utils.draft import Draft, PlaintextDraft
|
from ietf.utils.draft import Draft, PlaintextDraft
|
||||||
from ietf.utils.timezone import date_today
|
|
||||||
from ietf.utils.xmldraft import XMLDraft
|
from ietf.utils.xmldraft import XMLDraft
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,10 +147,10 @@ class ActionHoldersTests(TestCase):
|
||||||
dah.time_added = datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc) # arbitrary date in the past
|
dah.time_added = datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc) # arbitrary date in the past
|
||||||
dah.save()
|
dah.save()
|
||||||
|
|
||||||
today = date_today()
|
right_now = timezone.now()
|
||||||
self.assertNotEqual(doc.documentactionholder_set.get(person=self.ad).time_added.date(), today)
|
self.assertLess(doc.documentactionholder_set.get(person=self.ad).time_added, right_now)
|
||||||
self.update_doc_state(doc, State.objects.get(slug='ad-eval'))
|
self.update_doc_state(doc, State.objects.get(slug='ad-eval'))
|
||||||
self.assertEqual(doc.documentactionholder_set.get(person=self.ad).time_added.date(), today)
|
self.assertGreaterEqual(doc.documentactionholder_set.get(person=self.ad).time_added, right_now)
|
||||||
|
|
||||||
def test_update_action_holders_add_tag_need_rev(self):
|
def test_update_action_holders_add_tag_need_rev(self):
|
||||||
"""Adding need-rev tag adds authors as action holders"""
|
"""Adding need-rev tag adds authors as action holders"""
|
||||||
|
|
|
@ -7,6 +7,7 @@ import datetime
|
||||||
|
|
||||||
from pyquery import PyQuery
|
from pyquery import PyQuery
|
||||||
from urllib.parse import quote, urlparse
|
from urllib.parse import quote, urlparse
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.urls import reverse as urlreverse
|
from django.urls import reverse as urlreverse
|
||||||
|
@ -595,7 +596,10 @@ I would like to revoke this declaration.
|
||||||
r = self.client.post(url, data )
|
r = self.client.post(url, data )
|
||||||
self.assertEqual(r.status_code,302)
|
self.assertEqual(r.status_code,302)
|
||||||
self.assertEqual(len(outbox),2)
|
self.assertEqual(len(outbox),2)
|
||||||
self.assertIn('Secretariat on '+ipr.get_latest_event_submitted().time.strftime("%Y-%m-%d"), get_payload_text(outbox[1]).replace('\n',' '))
|
self.assertIn(
|
||||||
|
'Secretariat on ' + ipr.get_latest_event_submitted().time.astimezone(ZoneInfo(settings.TIME_ZONE)).strftime("%Y-%m-%d"),
|
||||||
|
get_payload_text(outbox[1]).replace('\n',' '),
|
||||||
|
)
|
||||||
self.assertIn(f'{settings.IDTRACKER_BASE_URL}{urlreverse("ietf.ipr.views.showlist")}', get_payload_text(outbox[1]).replace('\n',' '))
|
self.assertIn(f'{settings.IDTRACKER_BASE_URL}{urlreverse("ietf.ipr.views.showlist")}', get_payload_text(outbox[1]).replace('\n',' '))
|
||||||
|
|
||||||
def send_ipr_email_helper(self):
|
def send_ipr_email_helper(self):
|
||||||
|
|
|
@ -700,7 +700,7 @@ class LiaisonManagementTests(TestCase):
|
||||||
from_groups = [ str(g.pk) for g in Group.objects.filter(type="sdo") ]
|
from_groups = [ str(g.pk) for g in Group.objects.filter(type="sdo") ]
|
||||||
to_group = Group.objects.get(acronym="mars")
|
to_group = Group.objects.get(acronym="mars")
|
||||||
submitter = Person.objects.get(user__username="marschairman")
|
submitter = Person.objects.get(user__username="marschairman")
|
||||||
today = date_today()
|
today = date_today(datetime.timezone.utc)
|
||||||
related_liaison = liaison
|
related_liaison = liaison
|
||||||
r = self.client.post(url,
|
r = self.client.post(url,
|
||||||
dict(from_groups=from_groups,
|
dict(from_groups=from_groups,
|
||||||
|
@ -779,7 +779,7 @@ class LiaisonManagementTests(TestCase):
|
||||||
from_group = Group.objects.get(acronym="mars")
|
from_group = Group.objects.get(acronym="mars")
|
||||||
to_group = Group.objects.filter(type="sdo")[0]
|
to_group = Group.objects.filter(type="sdo")[0]
|
||||||
submitter = Person.objects.get(user__username="marschairman")
|
submitter = Person.objects.get(user__username="marschairman")
|
||||||
today = date_today()
|
today = date_today(datetime.timezone.utc)
|
||||||
related_liaison = liaison
|
related_liaison = liaison
|
||||||
r = self.client.post(url,
|
r = self.client.post(url,
|
||||||
dict(from_groups=str(from_group.pk),
|
dict(from_groups=str(from_group.pk),
|
||||||
|
@ -847,7 +847,7 @@ class LiaisonManagementTests(TestCase):
|
||||||
from_group = Group.objects.get(acronym="mars")
|
from_group = Group.objects.get(acronym="mars")
|
||||||
to_group = Group.objects.filter(type="sdo")[0]
|
to_group = Group.objects.filter(type="sdo")[0]
|
||||||
submitter = Person.objects.get(user__username="marschairman")
|
submitter = Person.objects.get(user__username="marschairman")
|
||||||
today = date_today()
|
today = date_today(datetime.timezone.utc)
|
||||||
r = self.client.post(url,
|
r = self.client.post(url,
|
||||||
dict(from_groups=str(from_group.pk),
|
dict(from_groups=str(from_group.pk),
|
||||||
from_contact=submitter.email_address(),
|
from_contact=submitter.email_address(),
|
||||||
|
@ -866,7 +866,7 @@ class LiaisonManagementTests(TestCase):
|
||||||
self.assertEqual(len(outbox), mailbox_before + 1)
|
self.assertEqual(len(outbox), mailbox_before + 1)
|
||||||
|
|
||||||
def test_liaison_add_attachment(self):
|
def test_liaison_add_attachment(self):
|
||||||
liaison = LiaisonStatementFactory(deadline=date_today()+datetime.timedelta(days=1))
|
liaison = LiaisonStatementFactory(deadline=date_today(DEADLINE_TZINFO)+datetime.timedelta(days=1))
|
||||||
LiaisonStatementEventFactory(statement=liaison,type_id='submitted')
|
LiaisonStatementEventFactory(statement=liaison,type_id='submitted')
|
||||||
|
|
||||||
self.assertEqual(liaison.attachments.count(),0)
|
self.assertEqual(liaison.attachments.count(),0)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import shutil
|
||||||
from pyquery import PyQuery
|
from pyquery import PyQuery
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from itertools import combinations
|
from itertools import combinations
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
|
@ -1506,11 +1507,12 @@ class NewActiveNomComTests(TestCase):
|
||||||
def test_accept_reject_nomination_edges(self):
|
def test_accept_reject_nomination_edges(self):
|
||||||
self.client.logout()
|
self.client.logout()
|
||||||
np = self.nc.nominee_set.order_by('pk').first().nomineeposition_set.order_by('pk').first()
|
np = self.nc.nominee_set.order_by('pk').first().nomineeposition_set.order_by('pk').first()
|
||||||
|
date_str = np.time.astimezone(ZoneInfo(settings.TIME_ZONE)).strftime("%Y%m%d")
|
||||||
kwargs={'year':self.nc.year(),
|
kwargs={'year':self.nc.year(),
|
||||||
'nominee_position_id':np.id,
|
'nominee_position_id':np.id,
|
||||||
'state':'accepted',
|
'state':'accepted',
|
||||||
'date':np.time.strftime("%Y%m%d"),
|
'date':date_str,
|
||||||
'hash':get_hash_nominee_position(np.time.strftime("%Y%m%d"),np.id),
|
'hash':get_hash_nominee_position(date_str, np.id),
|
||||||
}
|
}
|
||||||
url = reverse('ietf.nomcom.views.process_nomination_status', kwargs=kwargs)
|
url = reverse('ietf.nomcom.views.process_nomination_status', kwargs=kwargs)
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
|
@ -1520,8 +1522,9 @@ class NewActiveNomComTests(TestCase):
|
||||||
settings.DAYS_TO_EXPIRE_NOMINATION_LINK = 2
|
settings.DAYS_TO_EXPIRE_NOMINATION_LINK = 2
|
||||||
np.time = np.time - datetime.timedelta(days=3)
|
np.time = np.time - datetime.timedelta(days=3)
|
||||||
np.save()
|
np.save()
|
||||||
kwargs['date'] = np.time.strftime("%Y%m%d")
|
date_str = np.time.astimezone(ZoneInfo(settings.TIME_ZONE)).strftime("%Y%m%d")
|
||||||
kwargs['hash'] = get_hash_nominee_position(np.time.strftime("%Y%m%d"),np.id)
|
kwargs['date'] = date_str
|
||||||
|
kwargs['hash'] = get_hash_nominee_position(date_str, np.id)
|
||||||
url = reverse('ietf.nomcom.views.process_nomination_status', kwargs=kwargs)
|
url = reverse('ietf.nomcom.views.process_nomination_status', kwargs=kwargs)
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
self.assertEqual(response.status_code,403)
|
self.assertEqual(response.status_code,403)
|
||||||
|
@ -1535,12 +1538,13 @@ class NewActiveNomComTests(TestCase):
|
||||||
|
|
||||||
def test_accept_reject_nomination_comment(self):
|
def test_accept_reject_nomination_comment(self):
|
||||||
np = self.nc.nominee_set.order_by('pk').first().nomineeposition_set.order_by('pk').first()
|
np = self.nc.nominee_set.order_by('pk').first().nomineeposition_set.order_by('pk').first()
|
||||||
hash = get_hash_nominee_position(np.time.strftime("%Y%m%d"),np.id)
|
date_str = np.time.astimezone(ZoneInfo(settings.TIME_ZONE)).strftime("%Y%m%d")
|
||||||
|
hash = get_hash_nominee_position(date_str, np.id)
|
||||||
url = reverse('ietf.nomcom.views.process_nomination_status',
|
url = reverse('ietf.nomcom.views.process_nomination_status',
|
||||||
kwargs={'year':self.nc.year(),
|
kwargs={'year':self.nc.year(),
|
||||||
'nominee_position_id':np.id,
|
'nominee_position_id':np.id,
|
||||||
'state':'accepted',
|
'state':'accepted',
|
||||||
'date':np.time.strftime("%Y%m%d"),
|
'date':date_str,
|
||||||
'hash':hash,
|
'hash':hash,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue