1818from urllib .parse import urlparse , parse_qs
1919from tempfile import NamedTemporaryFile
2020from collections import defaultdict
21+ from zoneinfo import ZoneInfo
2122
2223from django .core .management import call_command
2324from django .urls import reverse as urlreverse
5758from ietf .utils .test_utils import login_testing_unauthorized , unicontent , reload_db_objects
5859from ietf .utils .test_utils import TestCase
5960from ietf .utils .text import normalize_text
61+ from ietf .utils .timezone import datetime_today , DEADLINE_TZINFO
62+
6063
6164class SearchTests (TestCase ):
6265 def test_search (self ):
@@ -1428,6 +1431,8 @@ def _run_test(username=None, expect_buttons=False):
14281431
14291432 def test_draft_group_link (self ):
14301433 """Link to group 'about' page should have correct format"""
1434+ event_datetime = datetime .datetime (2010 , 10 , 10 , tzinfo = ZoneInfo ('America/Los_Angeles' ))
1435+
14311436 for group_type_id in ['wg' , 'rg' , 'ag' ]:
14321437 group = GroupFactory (type_id = group_type_id )
14331438 draft = WgDraftFactory (name = 'draft-document-%s' % group_type_id , group = group )
@@ -1436,7 +1441,7 @@ def test_draft_group_link(self):
14361441 self .assert_correct_wg_group_link (r , group )
14371442
14381443 rfc = WgRfcFactory (name = 'draft-rfc-document-%s' % group_type_id , group = group )
1439- DocEventFactory .create (doc = rfc , type = 'published_rfc' , time = '2010-10-10' )
1444+ DocEventFactory .create (doc = rfc , type = 'published_rfc' , time = event_datetime )
14401445 # get the rfc name to avoid a redirect
14411446 rfc_name = rfc .docalias .filter (name__startswith = 'rfc' ).first ().name
14421447 r = self .client .get (urlreverse ("ietf.doc.views_doc.document_main" , kwargs = dict (name = rfc_name )))
@@ -1451,7 +1456,7 @@ def test_draft_group_link(self):
14511456 self .assert_correct_non_wg_group_link (r , group )
14521457
14531458 rfc = WgRfcFactory (name = 'draft-rfc-document-%s' % group_type_id , group = group )
1454- DocEventFactory .create (doc = rfc , type = 'published_rfc' , time = '2010-10-10' )
1459+ DocEventFactory .create (doc = rfc , type = 'published_rfc' , time = event_datetime )
14551460 # get the rfc name to avoid a redirect
14561461 rfc_name = rfc .docalias .filter (name__startswith = 'rfc' ).first ().name
14571462 r = self .client .get (urlreverse ("ietf.doc.views_doc.document_main" , kwargs = dict (name = rfc_name )))
@@ -1837,7 +1842,7 @@ def test_last_call_feed(self):
18371842 desc = "Last call\x0b " , # include a control character to be sure it does not break anything
18381843 type = "sent_last_call" ,
18391844 by = Person .objects .get (user__username = "secretary" ),
1840- expires = datetime . date . today ( ) + datetime .timedelta (days = 7 ))
1845+ expires = datetime_today ( DEADLINE_TZINFO ) + datetime .timedelta (days = 7 ))
18411846
18421847 r = self .client .get ("/feed/last-call/" )
18431848 self .assertEqual (r .status_code , 200 )
@@ -1885,10 +1890,14 @@ def test_document_bibtex(self):
18851890 #other_aliases = ['rfc6020',],
18861891 states = [('draft' ,'rfc' ),('draft-iesg' ,'pub' )],
18871892 std_level_id = 'ps' ,
1888- time = datetime .datetime (2010 ,10 ,10 ),
1893+ time = datetime .datetime (2010 , 10 , 10 , tzinfo = ZoneInfo ( 'America/Los_Angeles' ) ),
18891894 )
18901895 num = rfc .rfc_number ()
1891- DocEventFactory .create (doc = rfc , type = 'published_rfc' , time = '2010-10-10' )
1896+ DocEventFactory .create (
1897+ doc = rfc ,
1898+ type = 'published_rfc' ,
1899+ time = datetime .datetime (2010 , 10 , 10 , tzinfo = ZoneInfo ('America/Los_Angeles' )),
1900+ )
18921901 #
18931902 url = urlreverse ('ietf.doc.views_doc.document_bibtex' , kwargs = dict (name = rfc .name ))
18941903 r = self .client .get (url )
@@ -1906,10 +1915,14 @@ def test_document_bibtex(self):
19061915 stream_id = 'ise' ,
19071916 states = [('draft' ,'rfc' ),('draft-iesg' ,'pub' )],
19081917 std_level_id = 'inf' ,
1909- time = datetime .datetime (1990 ,0o4 , 0o1 ),
1918+ time = datetime .datetime (1990 , 4 , 1 , tzinfo = ZoneInfo ( 'America/Los_Angeles' ) ),
19101919 )
19111920 num = april1 .rfc_number ()
1912- DocEventFactory .create (doc = april1 , type = 'published_rfc' , time = '1990-04-01' )
1921+ DocEventFactory .create (
1922+ doc = april1 ,
1923+ type = 'published_rfc' ,
1924+ time = datetime .datetime (1990 , 4 , 1 , tzinfo = ZoneInfo ('America/Los_Angeles' )),
1925+ )
19131926 #
19141927 url = urlreverse ('ietf.doc.views_doc.document_bibtex' , kwargs = dict (name = april1 .name ))
19151928 r = self .client .get (url )
@@ -2044,7 +2057,9 @@ def tearDown(self):
20442057 super ().tearDown ()
20452058
20462059 def testManagementCommand (self ):
2047- a_month_ago = timezone .now () - datetime .timedelta (30 )
2060+ tz = ZoneInfo ('America/Los_Angeles' )
2061+ a_month_ago = (timezone .now () - datetime .timedelta (30 )).astimezone (tz )
2062+ a_month_ago = a_month_ago .replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
20482063 ad = RoleFactory (name_id = 'ad' , group__type_id = 'area' , group__state_id = 'active' ).person
20492064 shepherd = PersonFactory ()
20502065 author1 = PersonFactory ()
@@ -2059,9 +2074,9 @@ def testManagementCommand(self):
20592074 doc1 = IndividualDraftFactory (authors = [author1 ], shepherd = shepherd .email (), ad = ad )
20602075 doc2 = WgDraftFactory (name = 'draft-ietf-mars-test' , group__acronym = 'mars' , authors = [author2 ], ad = ad )
20612076 doc3 = WgRfcFactory .create (name = 'draft-ietf-mars-finished' , group__acronym = 'mars' , authors = [author3 ], ad = ad , std_level_id = 'ps' , states = [('draft' ,'rfc' ),('draft-iesg' ,'pub' )], time = a_month_ago )
2062- DocEventFactory .create (doc = doc3 , type = 'published_rfc' , time = a_month_ago . strftime ( "%Y-%m-%d" ) )
2063- doc4 = WgRfcFactory .create (authors = [author4 ,author5 ], ad = ad , std_level_id = 'ps' , states = [('draft' ,'rfc' ),('draft-iesg' ,'pub' )], time = datetime .datetime (2010 ,10 ,10 ))
2064- DocEventFactory .create (doc = doc4 , type = 'published_rfc' , time = ' 2010-10-10' )
2077+ DocEventFactory .create (doc = doc3 , type = 'published_rfc' , time = a_month_ago )
2078+ doc4 = WgRfcFactory .create (authors = [author4 ,author5 ], ad = ad , std_level_id = 'ps' , states = [('draft' ,'rfc' ),('draft-iesg' ,'pub' )], time = datetime .datetime (2010 ,10 ,10 , tzinfo = tz ))
2079+ DocEventFactory .create (doc = doc4 , type = 'published_rfc' , time = datetime . datetime ( 2010 , 10 , 10 , tzinfo = tz ) )
20652080 doc5 = IndividualDraftFactory (authors = [author6 ])
20662081
20672082 args = [ ]
0 commit comments