Skip to content

Commit dcf9e6b

Browse files
committed
Use factories for ietf.doc.tests_ballots. Fixed a long-hidden bug in test_edit_verify_permissions where non-existing usernames were used and passed the tests accidently. Added list_email to the GroupFactory. Commit ready for merge.
- Legacy-Id: 15219
1 parent a064e28 commit dcf9e6b

3 files changed

Lines changed: 42 additions & 29 deletions

File tree

ietf/doc/tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from ietf.person.models import Person
3333
from ietf.person.factories import PersonFactory
3434
from ietf.utils.mail import outbox
35-
#from ietf.utils.test_data import make_test_data
3635
from ietf.utils.test_utils import login_testing_unauthorized, unicontent
3736
from ietf.utils.test_utils import TestCase
3837

ietf/doc/tests_ballot.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@
88

99
from ietf.doc.models import ( Document, State, DocEvent,
1010
BallotPositionDocEvent, LastCallDocEvent, WriteupDocEvent, TelechatDocEvent )
11-
from ietf.doc.factories import DocumentFactory
11+
from ietf.doc.factories import DocumentFactory, IndividualDraftFactory, IndividualRfcFactory, WgDraftFactory
1212
from ietf.doc.utils import create_ballot_if_not_open
1313
from ietf.group.models import Group, Role
14+
from ietf.group.factories import GroupFactory, RoleFactory
1415
from ietf.name.models import BallotPositionName
1516
from ietf.iesg.models import TelechatDate
1617
from ietf.person.models import Person, PersonalApiKey
18+
from ietf.person.factories import PersonFactory
1719
from ietf.utils.test_utils import TestCase, unicontent
1820
from ietf.utils.mail import outbox, empty_outbox
19-
from ietf.utils.test_data import make_test_data
2021
from ietf.utils.test_utils import login_testing_unauthorized
2122

2223

2324
class EditPositionTests(TestCase):
2425
def test_edit_position(self):
25-
draft = make_test_data()
2626
ad = Person.objects.get(user__username="ad")
27+
draft = IndividualDraftFactory(ad=ad)
2728
ballot = create_ballot_if_not_open(None, draft, ad, 'approve')
2829
url = urlreverse('ietf.doc.views_ballot.edit_position', kwargs=dict(name=draft.name,
2930
ballot_id=ballot.pk))
@@ -89,9 +90,9 @@ def test_edit_position(self):
8990
self.assertTrue("Ballot comment text updated" in pos.desc)
9091

9192
def test_api_set_position(self):
92-
draft = make_test_data()
93-
url = urlreverse('ietf.doc.views_ballot.api_set_position')
9493
ad = Person.objects.get(name="Areað Irector")
94+
draft = WgDraftFactory(ad=ad)
95+
url = urlreverse('ietf.doc.views_ballot.api_set_position')
9596
create_ballot_if_not_open(None, draft, ad, 'approve')
9697
ad.user.last_login = datetime.datetime.now()
9798
ad.user.save()
@@ -172,7 +173,7 @@ def test_api_set_position(self):
172173

173174

174175
def test_edit_position_as_secretary(self):
175-
draft = make_test_data()
176+
draft = IndividualDraftFactory()
176177
ad = Person.objects.get(user__username="ad")
177178
ballot = create_ballot_if_not_open(None, draft, ad, 'approve')
178179
url = urlreverse('ietf.doc.views_ballot.edit_position', kwargs=dict(name=draft.name, ballot_id=ballot.pk))
@@ -198,7 +199,7 @@ def test_edit_position_as_secretary(self):
198199
self.assertTrue("by Sec" in pos.desc)
199200

200201
def test_cannot_edit_position_as_pre_ad(self):
201-
draft = make_test_data()
202+
draft = IndividualDraftFactory()
202203
ad = Person.objects.get(user__username="ad")
203204
ballot = create_ballot_if_not_open(None, draft, ad, 'approve')
204205
url = urlreverse('ietf.doc.views_ballot.edit_position', kwargs=dict(name=draft.name, ballot_id=ballot.pk))
@@ -216,11 +217,11 @@ def test_cannot_edit_position_as_pre_ad(self):
216217
self.assertEqual(r.status_code, 403)
217218

218219
def test_send_ballot_comment(self):
219-
draft = make_test_data()
220+
ad = Person.objects.get(user__username="ad")
221+
draft = WgDraftFactory(ad=ad,group__acronym='mars')
220222
draft.notify = "somebody@example.com"
221223
draft.save_with_history([DocEvent.objects.create(doc=draft, rev=draft.rev, type="changed_document", by=Person.objects.get(user__username="secretary"), desc="Test")])
222224

223-
ad = Person.objects.get(user__username="ad")
224225
ballot = create_ballot_if_not_open(None, draft, ad, 'approve')
225226

226227
BallotPositionDocEvent.objects.create(
@@ -274,7 +275,7 @@ def test_send_ballot_comment(self):
274275

275276
class BallotWriteupsTests(TestCase):
276277
def test_edit_last_call_text(self):
277-
draft = make_test_data()
278+
draft = IndividualDraftFactory(ad=Person.objects.get(user__username='ad'),states=[('draft','active'),('draft-iesg','ad-eval')])
278279
url = urlreverse('ietf.doc.views_ballot.lastcalltext', kwargs=dict(name=draft.name))
279280
login_testing_unauthorized(self, "secretary", url)
280281

@@ -314,7 +315,8 @@ def test_edit_last_call_text(self):
314315

315316

316317
def test_request_last_call(self):
317-
draft = make_test_data()
318+
ad = Person.objects.get(user__username="ad")
319+
draft = IndividualDraftFactory(ad=ad,states=[('draft-iesg','iesg-eva')])
318320
url = urlreverse('ietf.doc.views_ballot.lastcalltext', kwargs=dict(name=draft.name))
319321
login_testing_unauthorized(self, "secretary", url)
320322

@@ -339,7 +341,7 @@ def test_request_last_call(self):
339341
self.assertTrue('aread@' in outbox[-1]['Cc'])
340342

341343
def test_edit_ballot_writeup(self):
342-
draft = make_test_data()
344+
draft = IndividualDraftFactory()
343345
url = urlreverse('ietf.doc.views_ballot.ballot_writeupnotes', kwargs=dict(name=draft.name))
344346
login_testing_unauthorized(self, "secretary", url)
345347

@@ -369,7 +371,7 @@ def test_edit_ballot_writeup(self):
369371
self.assertTrue("This is a simple test" in draft.latest_event(WriteupDocEvent, type="changed_ballot_writeup_text").text)
370372

371373
def test_edit_ballot_rfceditornote(self):
372-
draft = make_test_data()
374+
draft = IndividualDraftFactory()
373375
url = urlreverse('ietf.doc.views_ballot.ballot_rfceditornote', kwargs=dict(name=draft.name))
374376
login_testing_unauthorized(self, "secretary", url)
375377

@@ -409,7 +411,8 @@ def test_edit_ballot_rfceditornote(self):
409411
self.assertFalse(draft.has_rfc_editor_note())
410412

411413
def test_issue_ballot(self):
412-
draft = make_test_data()
414+
ad = Person.objects.get(user__username="ad")
415+
draft = IndividualDraftFactory(ad=ad)
413416
url = urlreverse('ietf.doc.views_ballot.ballot_writeupnotes', kwargs=dict(name=draft.name))
414417
login_testing_unauthorized(self, "ad", url)
415418

@@ -431,7 +434,8 @@ def test_issue_ballot(self):
431434
self.assertTrue('X-IETF-Draft-string' in outbox[-1])
432435

433436
def test_edit_approval_text(self):
434-
draft = make_test_data()
437+
ad = Person.objects.get(user__username="ad")
438+
draft = WgDraftFactory(ad=ad,states=[('draft','active'),('draft-iesg','iesg-eva')],intended_std_level_id='ps')
435439
url = urlreverse('ietf.doc.views_ballot.ballot_approvaltext', kwargs=dict(name=draft.name))
436440
login_testing_unauthorized(self, "secretary", url)
437441

@@ -489,7 +493,12 @@ def verify_can_see(username, url):
489493
q = PyQuery(r.content)
490494
self.assertEqual(len(q("<textarea class=\"form-control\"")),1)
491495

492-
draft = make_test_data()
496+
for username in ['plain','marschairman']:
497+
PersonFactory(user__username=username)
498+
mars = GroupFactory(acronym='mars',type_id='wg')
499+
RoleFactory(group=mars,person=Person.objects.get(user__username='marschairman'),name_id='chair')
500+
ad = Person.objects.get(user__username="ad")
501+
draft = WgDraftFactory(group=mars,ad=ad,states=[('draft','active'),('draft-iesg','ad-eval')])
493502

494503
events = []
495504

@@ -527,7 +536,7 @@ def verify_can_see(username, url):
527536
for p in ['ietf.doc.views_ballot.ballot_approvaltext','ietf.doc.views_ballot.ballot_writeupnotes','ietf.doc.views_ballot.ballot_rfceditornote']:
528537
url = urlreverse(p, kwargs=dict(name=draft.name))
529538

530-
for username in ['plain','marschairman','iab chair','irtf chair','ise','iana']:
539+
for username in ['plain','marschairman','iab-chair','irtf-chair','ise','iana']:
531540
verify_fail(username, url)
532541

533542
for username in ['secretary','ad']:
@@ -538,10 +547,10 @@ def verify_can_see(username, url):
538547
draft.save_with_history(events)
539548
url = urlreverse('ietf.doc.views_ballot.ballot_rfceditornote', kwargs=dict(name=draft.name))
540549

541-
for username in ['plain','marschairman','ad','irtf chair','ise','iana']:
550+
for username in ['plain','marschairman','ad','irtf-chair','ise','iana']:
542551
verify_fail(username, url)
543552

544-
for username in ['secretary','iab chair']:
553+
for username in ['secretary','iab-chair']:
545554
verify_can_see(username, url)
546555

547556
# RFC Editor Notes for documents in the IRTF Stream
@@ -553,7 +562,7 @@ def verify_can_see(username, url):
553562
draft.save_with_history([e])
554563
url = urlreverse('ietf.doc.views_ballot.ballot_rfceditornote', kwargs=dict(name=draft.name))
555564

556-
for username in ['plain','marschairman','ad','iab chair','ise','iana']:
565+
for username in ['plain','marschairman','ad','iab-chair','ise','iana']:
557566
verify_fail(username, url)
558567

559568
for username in ['secretary','irtf chair']:
@@ -568,15 +577,16 @@ def verify_can_see(username, url):
568577
draft.save_with_history([e])
569578
url = urlreverse('ietf.doc.views_ballot.ballot_rfceditornote', kwargs=dict(name=draft.name))
570579

571-
for username in ['plain','marschairman','ad','iab chair','irtf chair','iana']:
580+
for username in ['plain','marschairman','ad','iab-chair','irtf-chair','iana']:
572581
verify_fail(username, url)
573582

574583
for username in ['secretary','ise']:
575584
verify_can_see(username, url)
576585

577586
class ApproveBallotTests(TestCase):
578587
def test_approve_ballot(self):
579-
draft = make_test_data()
588+
ad = Person.objects.get(name="Areað Irector")
589+
draft = IndividualDraftFactory(ad=ad, intended_std_level_id='ps')
580590
draft.set_state(State.objects.get(used=True, type="draft-iesg", slug="iesg-eva")) # make sure it's approvable
581591

582592
url = urlreverse('ietf.doc.views_ballot.approve_ballot', kwargs=dict(name=draft.name))
@@ -627,7 +637,7 @@ def test_disapprove_ballot(self):
627637
# This tests a codepath that is not used in production
628638
# and that has already had some drift from usefulness (it results in a
629639
# older-style conflict review response).
630-
draft = make_test_data()
640+
draft = IndividualDraftFactory()
631641
draft.set_state(State.objects.get(used=True, type="draft-iesg", slug="nopubadw"))
632642

633643
url = urlreverse('ietf.doc.views_ballot.approve_ballot', kwargs=dict(name=draft.name))
@@ -645,7 +655,7 @@ def test_disapprove_ballot(self):
645655
self.assertTrue("NOT be published" in str(outbox[-1]))
646656

647657
def test_clear_ballot(self):
648-
draft = make_test_data()
658+
draft = IndividualDraftFactory()
649659
ad = Person.objects.get(user__username="ad")
650660
ballot = create_ballot_if_not_open(None, draft, ad, 'approve')
651661
old_ballot_id = ballot.id
@@ -663,7 +673,8 @@ def test_clear_ballot(self):
663673

664674
class MakeLastCallTests(TestCase):
665675
def test_make_last_call(self):
666-
draft = make_test_data()
676+
ad = Person.objects.get(user__username="ad")
677+
draft = WgDraftFactory(name='draft-ietf-mars-test',group__acronym='mars',ad=ad)
667678
draft.set_state(State.objects.get(used=True, type="draft-iesg", slug="lc-req"))
668679

669680
url = urlreverse('ietf.doc.views_ballot.make_last_call', kwargs=dict(name=draft.name))
@@ -841,12 +852,14 @@ def test_undefer_status_change(self):
841852
# when charters support being deferred, be sure to test them here
842853

843854
def setUp(self):
844-
make_test_data()
855+
IndividualDraftFactory(name='draft-ietf-mars-test',states=[('draft','active'),('draft-iesg','iesg-eva')])
856+
DocumentFactory(type_id='statchg',name='status-change-imaginary-mid-review',states=[('statchg','iesgeval')])
857+
DocumentFactory(type_id='conflrev',name='conflict-review-imaginary-irtf-submission',states=[('conflrev','iesgeval')])
845858

846859
class RegenerateLastCallTestCase(TestCase):
847860

848861
def test_regenerate_last_call(self):
849-
draft = DocumentFactory.create(
862+
draft = WgDraftFactory.create(
850863
stream_id='ietf',
851864
states=[('draft','active'),('draft-iesg','pub-req')],
852865
intended_std_level_id='ps',
@@ -864,7 +877,7 @@ def test_regenerate_last_call(self):
864877
self.assertTrue("Subject: Last Call" in lc_text)
865878
self.assertFalse("contains these normative down" in lc_text)
866879

867-
rfc = DocumentFactory.create(
880+
rfc = IndividualRfcFactory.create(
868881
stream_id='ise',
869882
other_aliases=['rfc6666',],
870883
states=[('draft','rfc'),('draft-iesg','pub')],

ietf/group/factories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Meta:
1313
acronym = factory.Sequence(lambda n: 'acronym%d' %n)
1414
state_id = 'active'
1515
type_id = 'wg'
16+
list_email = factory.LazyAttribute(lambda a: '%s@ietf.org'% a.acronym)
1617

1718
class ReviewTeamFactory(factory.DjangoModelFactory):
1819
class Meta:

0 commit comments

Comments
 (0)