2222from ietf .doc .utils import create_ballot_if_not_open
2323from ietf .group .factories import RoleFactory , GroupFactory
2424from ietf .group .models import Group , GroupMilestone , Role
25- from ietf .iesg .agenda import get_agenda_date , agenda_data
26- from ietf .iesg .models import TelechatDate
27- from ietf .name .models import StreamName
25+ from ietf .iesg .agenda import get_agenda_date , agenda_data , fill_in_agenda_administrivia , agenda_sections
26+ from ietf .iesg .models import TelechatDate , TelechatAgendaContent
27+ from ietf .name .models import StreamName , TelechatAgendaSectionName
2828from ietf .person .models import Person
2929from ietf .utils .test_utils import TestCase , login_testing_unauthorized , unicontent
30- from ietf .iesg .factories import IESGMgmtItemFactory
30+ from ietf .iesg .factories import IESGMgmtItemFactory , TelechatAgendaContentFactory
3131from ietf .utils .timezone import date_today , DEADLINE_TZINFO
3232
3333
@@ -141,6 +141,16 @@ def setUp(self):
141141 for i in range (0 , 10 ):
142142 self .mgmt_items .append (IESGMgmtItemFactory ())
143143
144+ def test_fill_in_agenda_administrivia (self ):
145+ roll_call = TelechatAgendaContentFactory (section_id = 'roll_call' )
146+ minutes = TelechatAgendaContentFactory (section_id = 'minutes' )
147+ action_items = TelechatAgendaContentFactory (section_id = 'action_items' )
148+ sections = agenda_sections ()
149+ fill_in_agenda_administrivia (None , sections ) # n.b., date parameter is unused at present
150+ self .assertIn (roll_call .text , sections ["1.1" ]["text" ])
151+ self .assertIn (minutes .text , sections ["1.3" ]["text" ])
152+ self .assertIn (action_items .text , sections ["1.4" ]["text" ])
153+
144154 def test_fill_in_agenda_docs (self ):
145155 draft = self .telechat_docs ["ietf_draft" ]
146156 statchg = self .telechat_docs ["statchg" ]
@@ -337,9 +347,12 @@ def test_agenda_json(self):
337347 self .assertTrue (r .json ())
338348
339349 def test_agenda (self ):
350+ action_items = TelechatAgendaContentFactory (section_id = 'action_items' )
340351 r = self .client .get (urlreverse ("ietf.iesg.views.agenda" ))
341352 self .assertEqual (r .status_code , 200 )
342353
354+ self .assertContains (r , action_items .text )
355+
343356 for k , d in self .telechat_docs .items ():
344357 if d .type_id == "charter" :
345358 self .assertContains (r , d .group .name , msg_prefix = "%s '%s' not in response" % (k , d .group .name ))
@@ -356,6 +369,29 @@ def test_agenda(self):
356369 # Make sure the sort places 6.9 before 6.10
357370 self .assertLess (r .content .find (b"6.9" ), r .content .find (b"6.10" ))
358371
372+ def test_agenda_restricted_sections (self ):
373+ r = self .client .get (urlreverse ("ietf.iesg.views.agenda" ))
374+ # not logged in
375+ for section_id in ("roll_call" , "minutes" ):
376+ self .assertNotContains (
377+ r , urlreverse ("ietf.iesg.views.telechat_agenda_content_view" , kwargs = {"section" : section_id })
378+ )
379+
380+ self .client .login (username = "plain" , password = "plain+password" )
381+ for section_id in ("roll_call" , "minutes" ):
382+ self .assertNotContains (
383+ r , urlreverse ("ietf.iesg.views.telechat_agenda_content_view" , kwargs = {"section" : section_id })
384+ )
385+
386+ for username in ("ad" , "secretary" , "iab chair" ):
387+ self .client .login (username = username , password = f"{ username } +password" )
388+ r = self .client .get (urlreverse ("ietf.iesg.views.agenda" ))
389+ self .assertEqual (r .status_code , 200 )
390+ for section_id in ("roll_call" , "minutes" ):
391+ self .assertContains (
392+ r , urlreverse ("ietf.iesg.views.telechat_agenda_content_view" , kwargs = {"section" : section_id })
393+ )
394+
359395 def test_agenda_txt (self ):
360396 r = self .client .get (urlreverse ("ietf.iesg.views.agenda_txt" ))
361397 self .assertEqual (r .status_code , 200 )
@@ -549,3 +585,104 @@ def test_reschedule(self):
549585 self .assertEqual (draft .latest_event (TelechatDocEvent , "scheduled_for_telechat" ).telechat_date , d )
550586 self .assertTrue (not draft .latest_event (TelechatDocEvent , "scheduled_for_telechat" ).returning_item )
551587 self .assertEqual (draft .docevent_set .count (), events_before + 1 )
588+
589+
590+ class TelechatAgendaContentTests (TestCase ):
591+ def test_telechat_agenda_content_view (self ):
592+ self .client .login (username = "ad" , password = "ad+password" )
593+ r = self .client .get (urlreverse ("ietf.iesg.views.telechat_agenda_content_view" , kwargs = {"section" : "fake" }))
594+ self .assertEqual (r .status_code , 404 , "Nonexistent section should 404" )
595+ for section in TelechatAgendaSectionName .objects .filter (used = True ).values_list ("slug" , flat = True ):
596+ r = self .client .get (
597+ urlreverse ("ietf.iesg.views.telechat_agenda_content_view" , kwargs = {"section" : section })
598+ )
599+ self .assertEqual (r .status_code , 404 , "Section with no content should 404" )
600+ for section in TelechatAgendaSectionName .objects .filter (used = True ).values_list ("slug" , flat = True ):
601+ content = TelechatAgendaContentFactory (section_id = section ).text
602+ r = self .client .get (
603+ urlreverse ("ietf.iesg.views.telechat_agenda_content_view" , kwargs = {"section" : section })
604+ )
605+ self .assertContains (r , content , status_code = 200 )
606+ self .assertEqual (r .get ("Content-Type" , None ), "text/plain" )
607+
608+ def test_telechat_agenda_content_view_permissions (self ):
609+ for section in TelechatAgendaSectionName .objects .filter (used = True ).values_list ("slug" , flat = True ):
610+ TelechatAgendaContentFactory (section_id = section )
611+ url = urlreverse ("ietf.iesg.views.telechat_agenda_content_view" , kwargs = {"section" : section })
612+ self .client .logout ()
613+ login_testing_unauthorized (self , "plain" , url )
614+ login_testing_unauthorized (self , "ad" , url )
615+ self .assertEqual (self .client .get (url ).status_code , 200 )
616+ self .client .login (username = "iab chair" , password = "iab chair+password" )
617+ self .assertEqual (self .client .get (url ).status_code , 200 )
618+ self .client .login (username = "secretary" , password = "secretary+password" )
619+ self .assertEqual (self .client .get (url ).status_code , 200 )
620+
621+ def test_telechat_agenda_content_edit (self ):
622+ for section in TelechatAgendaSectionName .objects .filter (used = True ):
623+ self .assertFalse (TelechatAgendaContent .objects .filter (section = section ).exists ())
624+ url = urlreverse ("ietf.iesg.views.telechat_agenda_content_edit" , kwargs = {"section" : section .slug })
625+ self .client .logout ()
626+ login_testing_unauthorized (self , "plain" , url , method = "get" )
627+ login_testing_unauthorized (self , "ad" , url , method = "get" )
628+ login_testing_unauthorized (self , "iab chair" , url , method = "get" )
629+ login_testing_unauthorized (self , "secretary" , url , method = "get" )
630+ r = self .client .get (url )
631+ self .assertContains (r , str (section ), status_code = 200 )
632+
633+ self .client .logout ()
634+ login_testing_unauthorized (self , "plain" , url , method = "post" )
635+ login_testing_unauthorized (self , "ad" , url , method = "post" )
636+ login_testing_unauthorized (self , "iab chair" , url , method = "post" )
637+ login_testing_unauthorized (self , "secretary" , url , method = "post" )
638+ r = self .client .post (url , {"text" : "This is some content" })
639+ self .assertRedirects (r , urlreverse ("ietf.iesg.views.telechat_agenda_content_manage" ))
640+ contents = TelechatAgendaContent .objects .filter (section = section )
641+ self .assertEqual (contents .count (), 1 )
642+ self .assertEqual (contents .first ().text , "This is some content" )
643+
644+ self .client .logout ()
645+ login_testing_unauthorized (self , "plain" , url , method = "post" )
646+ login_testing_unauthorized (self , "ad" , url , method = "post" )
647+ login_testing_unauthorized (self , "iab chair" , url , method = "post" )
648+ login_testing_unauthorized (self , "secretary" , url , method = "post" )
649+ r = self .client .post (url , {"text" : "This is some different content" })
650+ self .assertRedirects (r , urlreverse ("ietf.iesg.views.telechat_agenda_content_manage" ))
651+ contents = TelechatAgendaContent .objects .filter (section = section )
652+ self .assertEqual (contents .count (), 1 )
653+ self .assertEqual (contents .first ().text , "This is some different content" )
654+
655+ def test_telechat_agenda_content_manage (self ):
656+ url = urlreverse ("ietf.iesg.views.telechat_agenda_content_manage" )
657+ login_testing_unauthorized (self , "plain" , url )
658+ login_testing_unauthorized (self , "ad" , url )
659+ login_testing_unauthorized (self , "iab chair" , url )
660+ login_testing_unauthorized (self , "secretary" , url )
661+ self .assertEqual (TelechatAgendaContent .objects .count (), 0 )
662+ r = self .client .get (url )
663+ self .assertEqual (r .status_code , 200 )
664+ pq = PyQuery (r .content )
665+ for section in TelechatAgendaSectionName .objects .filter (used = True ):
666+ # check that there's a tab even when section is empty
667+ nav_button = pq (f"button.nav-link#{ section .slug } -tab" )
668+ self .assertEqual (nav_button .text (), str (section ))
669+ edit_url = urlreverse ("ietf.iesg.views.telechat_agenda_content_edit" , kwargs = {"section" : section .pk })
670+ edit_button = pq (f'div#{ section .slug } a[href="{ edit_url } "]' )
671+ self .assertEqual (len (edit_button ), 1 )
672+ self .assertIn (f"No { section } " , pq (f"div#{ section .slug } " ).text ())
673+ # and create a section for the next test
674+ TelechatAgendaContentFactory (section_id = section .slug )
675+ r = self .client .get (url )
676+ self .assertEqual (r .status_code , 200 )
677+ pq = PyQuery (r .content )
678+ for section in TelechatAgendaSectionName .objects .filter (used = True ):
679+ # check that there's a tab with the content
680+ nav_button = pq (f"button.nav-link#{ section .slug } -tab" )
681+ self .assertEqual (nav_button .text (), str (section ))
682+ edit_url = urlreverse ("ietf.iesg.views.telechat_agenda_content_edit" , kwargs = {"section" : section .pk })
683+ edit_button = pq (f'div#{ section .slug } a[href="{ edit_url } "]' )
684+ self .assertEqual (len (edit_button ), 1 )
685+ self .assertIn (
686+ TelechatAgendaContent .objects .get (section = section ).text , pq (f"div#{ section .slug } " ).text ()
687+ )
688+
0 commit comments