88import io
99import bleach
1010
11+ from unittest .mock import patch
1112from pathlib import Path
1213from pyquery import PyQuery
1314from tempfile import NamedTemporaryFile
@@ -515,12 +516,16 @@ def test_create(self):
515516 self .assertTrue (len (q ('form .has-error' )) > 0 )
516517
517518 # Ok creation
518- r = self .client .post (url , dict (acronym = "testwg" , name = "Testing WG" , state = bof_state .pk , parent = area .pk ))
519+ r = self .client .post (
520+ url ,
521+ dict (acronym = "testwg" , name = "Testing WG" , state = bof_state .pk , parent = area .pk , description = "ignored" ),
522+ )
519523 self .assertEqual (r .status_code , 302 )
520524 self .assertEqual (len (Group .objects .filter (type = "wg" )), num_wgs + 1 )
521525 group = Group .objects .get (acronym = "testwg" )
522526 self .assertEqual (group .name , "Testing WG" )
523527 self .assertEqual (charter_name_for_group (group ), "charter-ietf-testwg" )
528+ self .assertEqual (group .description , '' , 'Description should be ignored for a WG' )
524529
525530 def test_create_rg (self ):
526531
@@ -579,6 +584,28 @@ def test_create_based_on_existing_bof(self):
579584# self.assertEqual(Group.objects.get(acronym=group.acronym).state_id, "proposed")
580585# self.assertEqual(Group.objects.get(acronym=group.acronym).name, "Test")
581586
587+
588+ def test_create_non_chartered_includes_description (self ):
589+ parent = GroupFactory (type_id = 'area' )
590+ group_type = GroupTypeName .objects .filter (used = True , features__has_chartering_process = False ).first ()
591+ self .assertIsNotNone (group_type )
592+ url = urlreverse ('ietf.group.views.edit' , kwargs = dict (group_type = group_type .slug , action = "create" ))
593+ login_testing_unauthorized (self , "secretary" , url )
594+ r = self .client .post (
595+ url ,
596+ {
597+ 'acronym' : "testgrp" ,
598+ 'name' : "Testing" ,
599+ 'state' : GroupStateName .objects .get (slug = 'active' ).pk ,
600+ 'parent' : parent .pk ,
601+ 'description' : "not ignored" ,
602+ },
603+ )
604+ self .assertEqual (r .status_code , 302 )
605+ group = Group .objects .get (acronym = "testgrp" )
606+ self .assertEqual (group .name , "Testing" )
607+ self .assertEqual (group .description , 'not ignored' , 'Description should not be ignored' )
608+
582609 def test_edit_info (self ):
583610 group = GroupFactory (acronym = 'mars' ,parent = GroupFactory (type_id = 'area' ))
584611 CharterFactory (group = group )
@@ -640,6 +667,7 @@ def test_edit_info(self):
640667 list_email = "mars@mail" ,
641668 list_subscribe = "subscribe.mars" ,
642669 list_archive = "archive.mars" ,
670+ description = 'ignored'
643671 ))
644672 self .assertEqual (r .status_code , 302 )
645673
@@ -658,6 +686,7 @@ def test_edit_info(self):
658686 self .assertEqual (group .list_email , "mars@mail" )
659687 self .assertEqual (group .list_subscribe , "subscribe.mars" )
660688 self .assertEqual (group .list_archive , "archive.mars" )
689+ self .assertEqual (group .description , '' )
661690
662691 self .assertTrue ((Path (settings .CHARTER_PATH ) / ("%s-%s.txt" % (group .charter .canonical_name (), group .charter .rev ))).exists ())
663692 self .assertEqual (len (outbox ), 2 )
@@ -843,6 +872,60 @@ def test_edit_reviewers(self):
843872 self .assertEqual (review_assignment .state_id , 'accepted' )
844873 self .assertEqual (other_review_assignment .state_id , 'assigned' )
845874
875+ def test_edit_info_non_chartered_includes_description (self ):
876+ group_type = GroupTypeName .objects .filter (used = True , features__has_chartering_process = False ).first ()
877+ self .assertIsNotNone (group_type )
878+ group = GroupFactory (type_id = group_type .pk , description = 'Original description' )
879+ url = urlreverse ('ietf.group.views.edit' , kwargs = {'acronym' : group .acronym , 'action' : 'edit' })
880+ PersonFactory (user__username = 'plain' )
881+ self .client .login (username = 'plain' , password = 'plain+password' )
882+
883+ # mock the auth check so we don't have to delve into details of GroupFeatures for testing
884+ with patch ('ietf.group.views.can_manage_group' , return_value = True ):
885+ r = self .client .get (url )
886+ self .assertEqual (r .status_code , 200 )
887+ q = PyQuery (r .content )
888+ self .assertTrue (q ('textarea[name="description"]' ))
889+
890+ with patch ('ietf.group.views.can_manage_group' , return_value = True ):
891+ r = self .client .post (url , {
892+ 'name' : group .name ,
893+ 'acronym' : group .acronym ,
894+ 'state' : group .state .pk ,
895+ 'description' : 'Updated description' ,
896+ })
897+ self .assertEqual (r .status_code , 302 )
898+ group = Group .objects .get (pk = group .pk ) # refresh
899+ self .assertEqual (group .description , 'Updated description' )
900+
901+ def test_edit_description_field (self ):
902+ group_type = GroupTypeName .objects .filter (used = True , features__has_chartering_process = False ).first ()
903+ self .assertIsNotNone (group_type )
904+ group = GroupFactory (type_id = group_type .pk , description = 'Original description' )
905+ url = urlreverse ('ietf.group.views.edit' ,
906+ kwargs = {'acronym' : group .acronym , 'action' : 'edit' , 'field' : 'description' })
907+ PersonFactory (user__username = 'plain' )
908+ self .client .login (username = 'plain' , password = 'plain+password' )
909+
910+ # mock the auth check so we don't have to delve into details of GroupFeatures for testing
911+ with patch ('ietf.group.views.can_manage_group' , return_value = True ):
912+ r = self .client .post (url , {
913+ 'description' : 'Updated description' ,
914+ })
915+ self .assertEqual (r .status_code , 302 )
916+ group = Group .objects .get (pk = group .pk ) # refresh
917+ self .assertEqual (group .description , 'Updated description' )
918+
919+ # Convert the group to a chartered type and repeat - should no longer be able to edit the desc
920+ group .type = GroupTypeName .objects .filter (used = True , features__has_chartering_process = True ).first ()
921+ group .save ()
922+ with patch ('ietf.group.views.can_manage_group' , return_value = True ):
923+ r = self .client .post (url , {
924+ 'description' : 'Ignored description' ,
925+ })
926+ self .assertEqual (r .status_code , 302 )
927+ group = Group .objects .get (pk = group .pk ) # refresh
928+ self .assertEqual (group .description , 'Updated description' )
846929
847930 def test_conclude (self ):
848931 group = GroupFactory (acronym = "mars" )
@@ -1037,6 +1120,32 @@ def test_need_parent(self):
10371120 self .assertTrue (form .is_valid ())
10381121 self ._assert_cleaned_data_equal (form .cleaned_data , data )
10391122
1123+ def test_no_description_field_for_chartered_groups (self ):
1124+ group = GroupFactory ()
1125+ self .assertTrue (
1126+ group .features .has_chartering_process ,
1127+ 'Group type must have has_chartering_process=True for this test' ,
1128+ )
1129+ self .assertNotIn ('description' , GroupForm (group = group ).fields )
1130+ self .assertNotIn ('description' , GroupForm (group_type = group .type ).fields )
1131+ self .assertNotIn ('description' , GroupForm (group = group , group_type = group .type ).fields )
1132+ self .assertNotIn ('description' , GroupForm (data = {'description' : 'blah' }, group = group ).fields )
1133+ self .assertNotIn ('description' , GroupForm (data = {'description' : 'blah' }, group_type = group .type ).fields )
1134+ self .assertNotIn ('description' , GroupForm (data = {'description' : 'blah' }, group = group , group_type = group .type ).fields )
1135+
1136+ def test_have_description_field_for_non_chartered_groups (self ):
1137+ group = GroupFactory (type_id = 'dir' )
1138+ self .assertFalse (
1139+ group .features .has_chartering_process ,
1140+ 'Group type must have has_chartering_process=False for this test' ,
1141+ )
1142+ self .assertIn ('description' , GroupForm (group = group ).fields )
1143+ self .assertIn ('description' , GroupForm (group_type = group .type ).fields )
1144+ self .assertIn ('description' , GroupForm (group = group , group_type = group .type ).fields )
1145+ self .assertIn ('description' , GroupForm (data = {'description' : 'blah' }, group = group ).fields )
1146+ self .assertIn ('description' , GroupForm (data = {'description' : 'blah' }, group_type = group .type ).fields )
1147+ self .assertIn ('description' , GroupForm (data = {'description' : 'blah' }, group = group , group_type = group .type ).fields )
1148+
10401149
10411150class MilestoneTests (TestCase ):
10421151 def create_test_milestones (self ):
0 commit comments