2323
2424from ietf .community .models import CommunityList
2525from ietf .community .utils import reset_name_contains_index_for_rule
26+ from ietf .doc .factories import WgDraftFactory , CharterFactory
2627from ietf .doc .models import Document , DocAlias , DocEvent , State
2728from ietf .doc .utils_charter import charter_name_for_group
2829from ietf .group .factories import GroupFactory , RoleFactory , GroupEventFactory
2930from ietf .group .models import Group , GroupEvent , GroupMilestone , GroupStateTransitions , Role
30- from ietf .group .utils import save_group_in_history
31+ from ietf .group .utils import save_group_in_history , setup_default_community_list_for_group
3132from ietf .meeting .factories import SessionFactory
3233from ietf .name .models import DocTagName , GroupStateName , GroupTypeName
3334from ietf .person .models import Person , Email
3435from ietf .person .factories import PersonFactory
36+ from ietf .review .factories import ReviewRequestFactory
3537from ietf .utils .mail import outbox , empty_outbox
36- from ietf .utils .test_data import make_test_data , make_review_data
3738from ietf .utils .test_utils import login_testing_unauthorized , TestCase , unicontent , reload_db_objects
3839
3940def group_urlreverse_list (group , viewname ):
@@ -54,8 +55,9 @@ def tearDown(self):
5455 shutil .rmtree (self .charter_dir )
5556
5657 def test_active_groups (self ):
57- draft = make_test_data ()
58- group = draft .group
58+ area = GroupFactory .create (type_id = 'area' )
59+ group = GroupFactory .create (type_id = 'wg' ,parent = area )
60+ RoleFactory (group = group ,name_id = 'ad' ,person = PersonFactory ())
5961
6062 url = urlreverse ('ietf.group.views.active_groups' , kwargs = dict (group_type = "wg" ))
6163 r = self .client .get (url )
@@ -86,8 +88,10 @@ def test_active_groups(self):
8688 url = urlreverse ('ietf.group.views.active_groups' , kwargs = dict (group_type = slug ))
8789
8890 def test_group_home (self ):
89- draft = make_test_data ()
91+ draft = WgDraftFactory ()
9092 group = draft .group
93+ # TODO - move this into GroupFactory
94+ setup_default_community_list_for_group (group )
9195
9296 url_list = group_urlreverse_list (group , 'ietf.group.views.group_home' )
9397 next_list = group_urlreverse_list (group , 'ietf.group.views.group_documents' )
@@ -103,8 +107,9 @@ def test_group_home(self):
103107 self .assertTrue (draft .title in unicontent (r ))
104108
105109 def test_wg_summaries (self ):
106- draft = make_test_data ()
107- group = draft .group
110+ group = CharterFactory (group__type_id = 'wg' ,group__parent = GroupFactory (type_id = 'area' )).group
111+ RoleFactory (group = group ,name_id = 'chair' ,person = PersonFactory ())
112+ RoleFactory (group = group ,name_id = 'ad' ,person = PersonFactory ())
108113
109114 chair = Email .objects .filter (role__group = group , role__name = "chair" )[0 ]
110115
@@ -145,9 +150,7 @@ def test_wg_summaries(self):
145150 self .assertTrue ("This is a charter." in unicontent (r ))
146151
147152 def test_chartering_groups (self ):
148- draft = make_test_data ()
149- group = draft .group
150- group .charter .set_state (State .objects .get (used = True , type = "charter" , slug = "intrev" ))
153+ group = CharterFactory (group__type_id = 'wg' ,group__parent = GroupFactory (type_id = 'area' ),states = [('charter' ,'intrev' )]).group
151154
152155 url = urlreverse ('ietf.group.views.chartering_groups' )
153156 r = self .client .get (url )
@@ -172,10 +175,7 @@ def test_chartering_groups(self):
172175
173176
174177 def test_concluded_groups (self ):
175- draft = make_test_data ()
176- group = draft .group
177- group .state = GroupStateName .objects .get (used = True , slug = "conclude" )
178- group .save ()
178+ group = GroupFactory (state_id = 'conclude' )
179179
180180 url = urlreverse ('ietf.group.views.concluded_groups' )
181181 r = self .client .get (url )
@@ -184,10 +184,7 @@ def test_concluded_groups(self):
184184 self .assertEqual (len (q ('#content a:contains("%s")' % group .acronym )), 1 )
185185
186186 def test_bofs (self ):
187- draft = make_test_data ()
188- group = draft .group
189- group .state_id = "bof"
190- group .save ()
187+ group = GroupFactory (state_id = 'bof' )
191188
192189 url = urlreverse ('ietf.group.views.bofs' , kwargs = dict (group_type = "wg" ))
193190 r = self .client .get (url )
@@ -196,32 +193,10 @@ def test_bofs(self):
196193 self .assertEqual (len (q ('#content a:contains("%s")' % group .acronym )), 1 )
197194
198195 def test_group_documents (self ):
199- draft = make_test_data ()
200- group = draft .group
201-
202- draft2 = Document .objects .create (
203- name = "draft-somebody-mars-test" ,
204- time = datetime .datetime .now (),
205- type_id = "draft" ,
206- title = "Test By Somebody" ,
207- stream_id = "ietf" ,
208- group = Group .objects .get (type = "individ" ),
209- abstract = "Abstract." ,
210- rev = "01" ,
211- pages = 2 ,
212- intended_std_level_id = "ps" ,
213- shepherd = None ,
214- ad = None ,
215- expires = datetime .datetime .now () + datetime .timedelta (days = 10 ),
216- notify = "" ,
217- note = "" ,
218- )
219-
220- draft2 .set_state (State .objects .get (used = True , type = "draft" , slug = "active" ))
221- DocAlias .objects .create (
222- document = draft2 ,
223- name = draft2 .name ,
224- )
196+ group = GroupFactory ()
197+ setup_default_community_list_for_group (group )
198+ draft = WgDraftFactory (group = group )
199+ draft2 = WgDraftFactory (group = group )
225200
226201 clist = CommunityList .objects .get (group = group )
227202 related_docs_rule = clist .searchrule_set .get (rule_type = 'name_contains' )
@@ -249,8 +224,8 @@ def test_group_documents(self):
249224 self .assertTrue (draft2 .name in unicontent (r ))
250225
251226 def test_group_charter (self ):
252- draft = make_test_data ()
253- group = draft . group
227+ group = CharterFactory (). group
228+ draft = WgDraftFactory ( group = group )
254229
255230 with open (os .path .join (self .charter_dir , "%s-%s.txt" % (group .charter .canonical_name (), group .charter .rev )), "w" ) as f :
256231 f .write ("This is a charter." )
@@ -273,10 +248,7 @@ def test_group_charter(self):
273248
274249 def test_group_about (self ):
275250
276- make_test_data ()
277-
278- p = PersonFactory (user__username = 'iab-member' )
279- Group .objects .get (acronym = 'iab' ).role_set .create (name_id = 'member' ,person = p ,email = p .email ())
251+ RoleFactory (group = Group .objects .get (acronym = 'iab' ),name_id = 'member' ,person = PersonFactory (user__username = 'iab-member' ))
280252
281253 interesting_users = [ 'plain' ,'iana' ,'iab-chair' ,'irtf-chair' , 'marschairman' , 'teamchairman' ,'ad' , 'iab-member' , 'secretary' , ]
282254
@@ -343,8 +315,7 @@ def verify_can_edit_group(url, group, username):
343315 verify_cannot_edit_group (url , group , username )
344316
345317 def test_materials (self ):
346- make_test_data ()
347- group = Group .objects .create (type_id = "team" , acronym = "testteam" , name = "Test Team" , state_id = "active" )
318+ group = GroupFactory (type_id = "team" , acronym = "testteam" , name = "Test Team" , state_id = "active" )
348319
349320 doc = Document .objects .create (
350321 name = "slides-testteam-test-slides" ,
@@ -372,8 +343,7 @@ def test_materials(self):
372343 self .assertTrue (doc .title not in unicontent (r ))
373344
374345 def test_history (self ):
375- draft = make_test_data ()
376- group = draft .group
346+ group = GroupFactory ()
377347
378348 e = GroupEvent .objects .create (
379349 group = group ,
@@ -387,8 +357,7 @@ def test_history(self):
387357 self .assertTrue (e .desc in unicontent (r ))
388358
389359 def test_feed (self ):
390- draft = make_test_data ()
391- group = draft .group
360+ group = CharterFactory ().group
392361
393362 ge = GroupEvent .objects .create (
394363 group = group ,
@@ -410,7 +379,7 @@ def test_feed(self):
410379
411380
412381 def test_chair_photos (self ):
413- make_test_data ( )
382+ RoleFactory ( name_id = 'chair' )
414383 url = urlreverse ("ietf.group.views.chair_photos" , kwargs = {'group_type' :'wg' })
415384 r = self .client .get (url )
416385 self .assertEqual (r .status_code , 200 )
@@ -419,7 +388,9 @@ def test_chair_photos(self):
419388 self .assertEqual (len (q ('div.photo-thumbnail img' )), chairs .count ())
420389
421390 def test_wg_photos (self ):
422- make_test_data ()
391+ GroupFactory (acronym = 'mars' )
392+ RoleFactory (name_id = 'chair' )
393+ RoleFactory (name_id = 'secr' )
423394 url = urlreverse ("ietf.group.views.group_photos" , kwargs = {'group_type' :'wg' , 'acronym' :'mars' })
424395 r = self .client .get (url )
425396 self .assertEqual (r .status_code , 200 )
@@ -428,7 +399,6 @@ def test_wg_photos(self):
428399 self .assertEqual (len (q ('div.photo-thumbnail img' )), roles .count ())
429400
430401 def test_group_photos (self ):
431- make_test_data ()
432402 url = urlreverse ("ietf.group.views.group_photos" , kwargs = {'acronym' :'iab' })
433403 r = self .client .get (url )
434404 self .assertEqual (r .status_code , 200 )
@@ -447,7 +417,6 @@ def tearDown(self):
447417 shutil .rmtree (self .charter_dir )
448418
449419 def test_create (self ):
450- make_test_data ()
451420
452421 url = urlreverse ('ietf.group.views.edit' , kwargs = dict (group_type = "wg" , action = "charter" ))
453422 login_testing_unauthorized (self , "secretary" , url )
@@ -506,8 +475,6 @@ def test_create(self):
506475
507476 def test_create_rg (self ):
508477
509- make_test_data ()
510-
511478 url = urlreverse ('ietf.group.views.edit' , kwargs = dict (group_type = "rg" , action = "charter" ))
512479 login_testing_unauthorized (self , "secretary" , url )
513480
@@ -531,12 +498,11 @@ def test_create_rg(self):
531498 self .assertEqual (charter_name_for_group (group ), "charter-irtf-testrg" )
532499
533500 def test_create_based_on_existing_bof (self ):
534- make_test_data ()
535501
536502 url = urlreverse ('ietf.group.views.edit' , kwargs = dict (group_type = "wg" , action = "charter" ))
537503 login_testing_unauthorized (self , "secretary" , url )
538504
539- group = Group . objects . get (acronym = "mars" )
505+ group = GroupFactory (acronym = "mars" , parent = GroupFactory ( type_id = 'area' ) )
540506
541507 # try hijacking area - faulty
542508 r = self .client .post (url , dict (name = "Test" , acronym = group .parent .acronym ))
@@ -565,8 +531,10 @@ def test_create_based_on_existing_bof(self):
565531 self .assertEqual (Group .objects .get (acronym = group .acronym ).name , "Test" )
566532
567533 def test_edit_info (self ):
568- make_test_data ()
569- group = Group .objects .get (acronym = "mars" )
534+ group = GroupFactory (acronym = 'mars' ,parent = GroupFactory (type_id = 'area' ))
535+ CharterFactory (group = group )
536+ RoleFactory (group = group ,name_id = 'chair' ,person__user__email = 'marschairman@ietf.org' )
537+ RoleFactory (group = group ,name_id = 'delegate' ,person__user__email = 'marsdelegate@ietf.org' )
570538
571539 url = urlreverse ('ietf.group.views.edit' , kwargs = dict (group_type = group .type_id , acronym = group .acronym , action = "edit" ))
572540 login_testing_unauthorized (self , "secretary" , url )
@@ -642,8 +610,7 @@ def test_edit_info(self):
642610
643611
644612 def test_edit_field (self ):
645- make_test_data ()
646- group = Group .objects .get (acronym = "mars" )
613+ group = GroupFactory (acronym = "mars" )
647614
648615 # Edit name
649616 url = urlreverse ('ietf.group.views.edit' , kwargs = dict (acronym = group .acronym , action = "edit" , field = "name" ))
@@ -679,9 +646,8 @@ def test_edit_field(self):
679646
680647
681648 def test_edit_reviewers (self ):
682- doc = make_test_data ()
683- review_req = make_review_data (doc )
684- group = review_req .team
649+ group = GroupFactory (type_id = 'review' ,parent = GroupFactory (type_id = 'area' ))
650+ ReviewRequestFactory (team = group )
685651
686652 url = urlreverse ('ietf.group.views.edit' , kwargs = dict (group_type = group .type_id , acronym = group .acronym , action = "edit" ))
687653 login_testing_unauthorized (self , "secretary" , url )
@@ -713,9 +679,7 @@ def test_edit_reviewers(self):
713679 self .assertTrue ('Personnel change' in outbox [0 ]['Subject' ])
714680
715681 def test_conclude (self ):
716- make_test_data ()
717-
718- group = Group .objects .get (acronym = "mars" )
682+ group = GroupFactory (acronym = "mars" )
719683
720684 url = urlreverse ('ietf.group.views.conclude' , kwargs = dict (group_type = group .type_id , acronym = group .acronym ))
721685 login_testing_unauthorized (self , "secretary" , url )
@@ -743,8 +707,11 @@ def test_conclude(self):
743707 self .assertEqual (group .state_id , "active" )
744708
745709 def test_add_comment (self ):
746- make_test_data ()
747- group = Group .objects .get (acronym = "mars" )
710+ group = GroupFactory (acronym = "mars" ,parent = GroupFactory (type_id = 'area' ))
711+ RoleFactory (group = group ,person = Person .objects .get (user__username = 'ad' ),name_id = 'ad' )
712+ RoleFactory (group = group ,person__user__username = 'marschairman' ,name_id = 'chair' )
713+ RoleFactory (group = group ,person__user__username = 'marssecretary' ,name_id = 'secr' )
714+ RoleFactory (group = group ,person__user__username = 'marsdelegate' ,name_id = 'delegate' )
748715 url = urlreverse ('ietf.group.views.add_comment' , kwargs = dict (acronym = group .acronym ))
749716 empty_outbox ()
750717 for username in ['secretary' ,'ad' ,'marschairman' ,'marssecretary' ,'marsdelegate' ]:
@@ -768,9 +735,11 @@ def test_add_comment(self):
768735
769736class MilestoneTests (TestCase ):
770737 def create_test_milestones (self ):
771- draft = make_test_data ()
772-
773- group = Group .objects .get (acronym = "mars" )
738+ group = GroupFactory (acronym = 'mars' ,parent = GroupFactory (type_id = 'area' ),list_email = 'mars-wg@ietf.org' )
739+ CharterFactory (group = group )
740+ RoleFactory (group = group ,name_id = 'ad' ,person = Person .objects .get (user__username = 'ad' ))
741+ RoleFactory (group = group ,name_id = 'chair' ,person = PersonFactory (user__username = 'marschairman' ))
742+ draft = WgDraftFactory (group = group )
774743
775744 m1 = GroupMilestone .objects .create (id = 1 ,
776745 group = group ,
@@ -1046,9 +1015,8 @@ def test_reset_charter_milestones(self):
10461015
10471016class CustomizeWorkflowTests (TestCase ):
10481017 def test_customize_workflow (self ):
1049- make_test_data ()
10501018
1051- group = Group . objects . get ( acronym = "mars" )
1019+ group = GroupFactory ( )
10521020
10531021 url = urlreverse ('ietf.group.views.customize_workflow' , kwargs = dict (group_type = group .type_id , acronym = group .acronym ))
10541022 login_testing_unauthorized (self , "secretary" , url )
@@ -1117,7 +1085,9 @@ def test_customize_workflow(self):
11171085class EmailAliasesTests (TestCase ):
11181086
11191087 def setUp (self ):
1120- make_test_data ()
1088+ PersonFactory (user__username = 'plain' )
1089+ GroupFactory (acronym = 'mars' ,parent = GroupFactory (type_id = 'area' ))
1090+ GroupFactory (acronym = 'ames' ,parent = GroupFactory (type_id = 'area' ))
11211091 self .group_alias_file = NamedTemporaryFile (delete = False )
11221092 self .group_alias_file .write ("""# Generated by hand at 2015-02-12_16:30:52
11231093virtual.ietf.org anything
@@ -1177,7 +1147,8 @@ def testExpansions(self):
11771147
11781148class AjaxTests (TestCase ):
11791149 def test_group_menu_data (self ):
1180- make_test_data ()
1150+
1151+ GroupFactory (acronym = 'mars' ,parent = Group .objects .get (acronym = 'farfut' ))
11811152
11821153 r = self .client .get (urlreverse ('ietf.group.views.group_menu_data' ))
11831154 self .assertEqual (r .status_code , 200 )
@@ -1333,8 +1304,7 @@ def test_view_status_update_for_meeting(self):
13331304class GroupParentLoopTests (TestCase ):
13341305
13351306 def test_group_parent_loop (self ):
1336- make_test_data ()
1337- mars = Group .objects .get (acronym = "mars" )
1307+ mars = GroupFactory (acronym = "mars" ,parent = Group .objects .get (acronym = 'farfut' ))
13381308 test1 = Group .objects .create (
13391309 type_id = "team" ,
13401310 acronym = "testteam1" ,
0 commit comments