forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests_rsab_ballot.py
More file actions
574 lines (480 loc) · 20.9 KB
/
Copy pathtests_rsab_ballot.py
File metadata and controls
574 lines (480 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# Copyright The IETF Trust 2022, All Rights Reserved
# -*- coding: utf-8 -*-
# import datetime
# from pyquery import PyQuery
import debug # pyflakes:ignore
from django.urls import reverse as urlreverse
from ietf.utils.mail import outbox, empty_outbox, get_payload_text
from ietf.utils.test_utils import TestCase, unicontent, login_testing_unauthorized
from ietf.doc.factories import (
EditorialDraftFactory,
EditorialRfcFactory,
IndividualDraftFactory,
WgDraftFactory,
RgDraftFactory,
BallotDocEventFactory,
IRSGBallotDocEventFactory,
BallotPositionDocEventFactory,
)
from ietf.doc.models import BallotPositionDocEvent
from ietf.doc.utils import create_ballot_if_not_open, close_ballot
from ietf.person.utils import get_active_rsab, get_active_ads, get_active_irsg
from ietf.group.factories import RoleFactory
from ietf.group.models import Group, Role
from ietf.person.models import Person
class IssueRSABBallotTests(TestCase):
def test_issue_ballot_button_presence(self):
individual_draft = IndividualDraftFactory()
wg_draft = WgDraftFactory()
rg_draft = RgDraftFactory()
ed_draft = EditorialDraftFactory()
ed_rfc = EditorialRfcFactory()
# login as an RSAB chair
self.client.login(username="rsab-chair", password="rsab-chair+password")
for name in [
doc.name
for doc in (individual_draft, wg_draft, rg_draft, ed_rfc)
]:
url = urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=name))
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertNotIn("Issue RSAB ballot", unicontent(r))
url = urlreverse(
"ietf.doc.views_doc.document_main", kwargs=dict(name=ed_draft.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertIn("Issue RSAB ballot", unicontent(r))
self.client.logout()
url = urlreverse(
"ietf.doc.views_doc.document_main", kwargs=dict(name=ed_draft.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertNotIn("Issue RSAB ballot", unicontent(r))
def test_close_ballot_button_presence(self):
individual_draft = IndividualDraftFactory()
wg_draft = WgDraftFactory()
rg_draft = RgDraftFactory()
ed_draft = EditorialDraftFactory()
ed_rfc = EditorialRfcFactory()
iesgmember = get_active_ads()[0]
irsgmember = get_active_irsg()[0]
BallotDocEventFactory(doc=ed_draft, ballot_type__slug="rsab-approve")
url = urlreverse(
"ietf.doc.views_doc.document_main", kwargs=dict(name=ed_draft.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertNotIn("Close RSAB ballot", unicontent(r))
# Login as other body balloters to see if the ballot close button appears
for member in (iesgmember, irsgmember):
url = urlreverse(
"ietf.doc.views_doc.document_main", kwargs=dict(name=ed_draft.name)
)
self.client.login(
username=member.user.username,
password=member.user.username + "+password",
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertNotIn("Close RSAB ballot", unicontent(r))
# Try to get the ballot closing page directly
url = urlreverse(
"ietf.doc.views_ballot.close_rsab_ballot",
kwargs=dict(name=ed_draft.name),
)
r = self.client.get(url)
self.assertNotEqual(r.status_code, 200)
self.client.logout()
# Login as the RSAB chair
self.client.login(username="rsab-chair", password="rsab-chair+password")
# The close button should now be available
url = urlreverse(
"ietf.doc.views_doc.document_main", kwargs=dict(name=ed_draft.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertIn("Close RSAB ballot", unicontent(r))
# Get the page with the Close RSAB Ballot Yes/No buttons
url = urlreverse(
"ietf.doc.views_ballot.close_rsab_ballot", kwargs=dict(name=ed_draft.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
# Login as the Secretariat
self.client.logout()
self.client.login(username="secretary", password="secretary+password")
# The close button should be available
url = urlreverse(
"ietf.doc.views_doc.document_main", kwargs=dict(name=ed_draft.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertIn("Close RSAB ballot", unicontent(r))
# Individual, IETF, and RFC docs should not show the Close button.
for draft in (individual_draft, wg_draft, rg_draft, ed_rfc):
url = urlreverse(
"ietf.doc.views_doc.document_main", kwargs=dict(name=draft.name)
)
r = self.client.get(url, follow=True)
self.assertEqual(r.status_code, 200)
self.assertNotIn("Close RSAB ballot", unicontent(r))
# TODO: This has a lot of redundancy with the BaseManipulation tests that should be refactored to speed tests up.
def test_issue_ballot(self):
ed_draft1 = EditorialDraftFactory()
ed_draft2 = EditorialDraftFactory()
iesgmember = get_active_ads()[0]
self.assertFalse(ed_draft1.ballot_open("rsab-approve"))
self.client.login(username="rsab-chair", password="rsab-chair+password")
url = urlreverse(
"ietf.doc.views_ballot.issue_rsab_ballot", kwargs=dict(name=ed_draft1.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
# Buttons present?
self.assertIn("rsab_button", unicontent(r))
# Press the No button - expect nothing but a redirect back to the draft's main page
r = self.client.post(url, dict(rsab_button="No"))
self.assertEqual(r.status_code, 302)
# Press the Yes button
r = self.client.post(url, dict(rsab_button="Yes"))
self.assertEqual(r.status_code, 302)
self.assertTrue(ed_draft1.ballot_open("rsab-approve"))
# Having issued a ballot, the Issue RSAB ballot button should be gone
url = urlreverse(
"ietf.doc.views_doc.document_main", kwargs=dict(name=ed_draft1.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertNotIn("Issue RSAB ballot", unicontent(r))
# The RSAB evaluation record tab should exist
self.assertIn("RSAB evaluation record", unicontent(r))
# The RSAB evaluation record tab should not indicate unavailability
self.assertNotIn(
"RSAB Evaluation Ballot has not been created yet", unicontent(r)
) # TODO: why is this a thing? We don't ever show the tab unless there's a ballot. May need to reconsider how we treat the IESG.
# We should find an RSAB member's name on the RSAB evaluation tab regardless of any positions taken or not
url = urlreverse(
"ietf.doc.views_doc.document_rsab_ballot", kwargs=dict(name=ed_draft1.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
rsabmembers = get_active_rsab()
self.assertNotEqual(len(rsabmembers), 0)
for member in rsabmembers:
self.assertIn(member.name, unicontent(r))
# Having issued a ballot, it should appear on the RSAB Ballot Status page
url = urlreverse("ietf.doc.views_ballot.rsab_ballot_status")
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
# Does the draft name appear on the page?
self.assertIn(ed_draft1.name, unicontent(r))
self.client.logout()
# Test that an IESG member cannot issue an RSAB ballot
self.client.login(
username=iesgmember.user.username,
password=iesgmember.user.username + "password",
)
url = urlreverse(
"ietf.doc.views_ballot.issue_rsab_ballot", kwargs=dict(name=ed_draft2.name)
)
r = self.client.get(url)
self.assertNotEqual(r.status_code, 200)
# Buttons present?
self.assertNotIn("rsab_button", unicontent(r))
# Attempt to press the Yes button anyway
r = self.client.post(url, dict(rsab_button="Yes"))
self.assertTrue(r.status_code == 302 and "/accounts/login" in r["Location"])
def test_edit_ballot_position_permissions(self):
ed_draft = EditorialDraftFactory()
ad = RoleFactory(group__type_id="area", name_id="ad")
pre_ad = RoleFactory(group__type_id="area", name_id="pre-ad")
irsgmember = get_active_irsg()[0]
rsab_chair = Role.objects.get(group__acronym="rsab", name="chair")
ballot = create_ballot_if_not_open(
None, ed_draft, rsab_chair.person, "rsab-approve"
)
url = urlreverse(
"ietf.doc.views_ballot.edit_position",
kwargs=dict(name=ed_draft.name, ballot_id=ballot.pk),
)
for person in (ad.person, pre_ad.person, irsgmember):
self.client.login(
username=person.user.username,
password=f"{person.user.username}+password",
)
r = self.client.post(
url, dict(position="concern", discuss="Test discuss text")
)
self.assertEqual(r.status_code, 403)
self.client.logout()
def test_iesg_ballot_no_rsab_actions(self):
ad = Person.objects.get(user__username="ad")
wg_draft = IndividualDraftFactory(ad=ad)
RoleFactory.create_batch(
2, name_id="member", group=Group.objects.get(acronym="rsab")
)
rsabmember = get_active_rsab()[0]
url = urlreverse(
"ietf.doc.views_ballot.ballot_writeupnotes", kwargs=dict(name=wg_draft.name)
)
# RSAB members should not be able to issue IESG ballots
login_testing_unauthorized(self, rsabmember.user.username, url)
r = self.client.post(
url, dict(ballot_writeup="This is a test.", issue_ballot="1")
)
self.assertNotEqual(r.status_code, 200)
self.client.logout()
login_testing_unauthorized(self, "ad", url)
BallotDocEventFactory(doc=wg_draft)
# rsab members (who are not also IESG members) can't take positions
ballot = wg_draft.active_ballot()
url = urlreverse(
"ietf.doc.views_ballot.edit_position",
kwargs=dict(name=wg_draft.name, ballot_id=ballot.pk),
)
self.client.logout()
login_testing_unauthorized(self, rsabmember.user.username, url)
r = self.client.post(url, dict(position="discuss", discuss="Test discuss text"))
self.assertEqual(r.status_code, 403)
class BaseManipulationTests:
def test_issue_ballot(self):
draft = EditorialDraftFactory()
url = urlreverse(
"ietf.doc.views_ballot.issue_rsab_ballot", kwargs=dict(name=draft.name)
)
empty_outbox()
login_testing_unauthorized(self, self.username, url)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
r = self.client.post(url, {"rsab_button": "No"})
self.assertEqual(r.status_code, 302)
self.assertIsNone(draft.ballot_open("rsab-approve"))
# No notifications should have been generated yet
self.assertEqual(len(outbox), 0)
r = self.client.post(url, {"rsab_button": "Yes"})
self.assertEqual(r.status_code, 302)
self.assertIsNotNone(draft.ballot_open("rsab-approve"))
# Should have sent a notification about the new ballot
self.assertEqual(len(outbox), 1)
msg = outbox[0]
self.assertIn("RSAB ballot issued", msg["Subject"])
self.assertIn("iesg-secretary@ietf.org", msg["From"])
self.assertIn(draft.name, msg["Cc"])
self.assertIn("rsab@rfc-editor.org", msg["To"])
def test_take_and_email_position(self):
draft = EditorialDraftFactory()
ballot = BallotDocEventFactory(doc=draft, ballot_type__slug="rsab-approve")
url = (
urlreverse(
"ietf.doc.views_ballot.edit_position",
kwargs=dict(name=draft.name, ballot_id=ballot.pk),
)
+ self.balloter
)
empty_outbox()
login_testing_unauthorized(self, self.username, url)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
r = self.client.post(
url,
dict(
position="yes",
comment="oib239sb",
send_mail="Save and send email",
cc_choices=["doc_authors", "doc_group_chairs", "doc_group_mail_list"],
),
)
self.assertEqual(r.status_code, 302)
e = draft.latest_event(BallotPositionDocEvent)
self.assertEqual(e.pos.slug, "yes")
self.assertEqual(e.comment, "oib239sb")
self.assertEqual(len(outbox), 1)
self.assertNotIn("discuss-criteria", get_payload_text(outbox[0]))
def test_close_ballot(self):
draft = EditorialDraftFactory()
BallotDocEventFactory(doc=draft, ballot_type__slug="rsab-approve")
url = urlreverse(
"ietf.doc.views_ballot.close_rsab_ballot", kwargs=dict(name=draft.name)
)
empty_outbox()
login_testing_unauthorized(self, self.username, url)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
r = self.client.post(url, dict(rsab_button="No"))
self.assertEqual(r.status_code, 302)
self.assertIsNotNone(draft.ballot_open("rsab-approve"))
# Should not have generated a notification yet
self.assertEqual(len(outbox), 0)
r = self.client.post(url, dict(rsab_button="Yes"))
self.assertEqual(r.status_code, 302)
self.assertIsNone(draft.ballot_open("rsab-approve"))
# Closing the ballot should have generated a notification
self.assertEqual(len(outbox), 1)
msg = outbox[0]
self.assertIn("RSAB ballot closed", msg["Subject"])
self.assertIn("iesg-secretary@ietf.org", msg["From"])
self.assertIn("rsab@rfc-editor.org", msg["To"])
self.assertIn(f"{draft.name}@ietf.org", msg["Cc"])
def test_view_outstanding_ballots(self):
draft = EditorialDraftFactory()
BallotDocEventFactory(doc=draft, ballot_type__slug="rsab-approve")
url = urlreverse("ietf.doc.views_ballot.rsab_ballot_status")
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertIn(draft.name, unicontent(r))
close_ballot(
draft, Person.objects.get(user__username=self.username), "rsab-approve"
)
r = self.client.get(url)
self.assertNotIn(draft.name, unicontent(r))
class RSABChairTests(BaseManipulationTests, TestCase):
def setUp(self):
super().setUp()
self.username = "rsab-chair"
self.balloter = ""
class SecretariatTests(BaseManipulationTests, TestCase):
def setUp(self):
super().setUp()
self.username = "secretary"
self.balloter = "?balloter={}".format(
Person.objects.get(user__username="rsab-chair").pk
)
class RSABMemberTests(TestCase):
def setUp(self):
super().setUp()
self.username = RoleFactory(
group__acronym="rsab", name_id="member"
).person.user.username
def test_cant_issue_rsab_ballot(self):
draft = EditorialDraftFactory()
url = urlreverse(
"ietf.doc.views_ballot.issue_rsab_ballot", kwargs=dict(name=draft.name)
)
self.client.login(username=self.username, password=self.username + "+password")
r = self.client.get(url)
self.assertEqual(r.status_code, 403)
r = self.client.post(url, {"rsab_button": "Yes"})
self.assertEqual(r.status_code, 403)
def test_cant_close_rsab_ballot(self):
draft = EditorialDraftFactory()
BallotDocEventFactory(doc=draft, ballot_type__slug="rsab-approve")
url = urlreverse(
"ietf.doc.views_ballot.close_rsab_ballot", kwargs=dict(name=draft.name)
)
self.client.login(username=self.username, password=self.username + "+password")
r = self.client.get(url)
self.assertEqual(r.status_code, 403)
r = self.client.post(url, dict(rsab_button="Yes"))
self.assertEqual(r.status_code, 403)
def test_cant_act_on_other_bodies_ballots(self):
ietf_doc = WgDraftFactory()
irtf_doc = RgDraftFactory()
self.client.login(username=self.username, password=f"{self.username}+password")
url = urlreverse(
"ietf.doc.views_ballot.ballot_writeupnotes", kwargs=dict(name=ietf_doc.name)
)
self.assertEqual(self.client.get(url).status_code, 403)
self.assertEqual(
self.client.post(
url,
dict(ballot_writeup="This is a simple test.", save_ballot_writeup="1"),
).status_code,
403,
)
url = urlreverse(
"ietf.doc.views_ballot.issue_irsg_ballot", kwargs=dict(name=irtf_doc.name)
)
self.assertEqual(self.client.get(url).status_code, 403)
self.assertEqual(
self.client.post(
url, dict(irsg_button="Yes", duedate="2038-01-19")
).status_code,
403,
)
for name, ballot_id in [
(ietf_doc.name, BallotDocEventFactory(doc=ietf_doc).pk),
(irtf_doc.name, IRSGBallotDocEventFactory(doc=irtf_doc).pk),
]:
url = urlreverse(
"ietf.doc.views_ballot.edit_position",
kwargs=dict(name=name, ballot_id=ballot_id),
)
self.assertEqual(
self.client.get(url).status_code, 200
) # TODO : WHAT?! : This is strange, and probably tied up badly with pre-ad, and it should change.
self.assertEqual(
self.client.post(
url,
dict(position="yes"),
).status_code,
403,
)
url = urlreverse(
"ietf.doc.views_ballot.close_irsg_ballot", kwargs=dict(name=irtf_doc.name)
)
self.assertEqual(self.client.get(url).status_code, 403)
self.assertEqual(
self.client.post(url, dict(irsg_button="Yes")).status_code, 403
)
# Closing iesg ballots happens as a side-effect of secretariat actions with access testing done elsewhere
def test_take_and_email_position(self):
draft = EditorialDraftFactory()
ballot = BallotDocEventFactory(doc=draft, ballot_type__slug="rsab-approve")
url = urlreverse(
"ietf.doc.views_ballot.edit_position",
kwargs=dict(name=draft.name, ballot_id=ballot.pk),
)
empty_outbox()
login_testing_unauthorized(self, self.username, url)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
r = self.client.post(
url,
dict(
position="yes",
comment="oib239sb",
send_mail="Save and send email",
cc_choices=["doc_authors", "doc_group_chairs", "doc_group_mail_list"],
),
)
self.assertEqual(r.status_code, 302)
e = draft.latest_event(BallotPositionDocEvent)
self.assertEqual(e.pos.slug, "yes")
self.assertEqual(e.comment, "oib239sb")
self.assertEqual(len(outbox), 1)
class NobodyTests(TestCase):
def setUp(self):
super().setUp()
self.draft = EditorialDraftFactory()
self.ballot = BallotDocEventFactory(
doc=self.draft, ballot_type__slug="rsab-approve"
)
BallotPositionDocEventFactory(
ballot=self.ballot,
by=get_active_rsab()[0],
pos_id="yes",
comment="b2390sn3",
)
def can_see_RSAB_tab(self):
url = urlreverse(
"ietf.doc.views_doc.document_rsab_ballot", kwargs=dict(name=self.draft.name)
)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertIn("b2390sn3", unicontent(r))
def test_cant_take_position_on_irtf_ballot(self):
url = urlreverse(
"ietf.doc.views_ballot.edit_position",
kwargs=dict(name=self.draft.name, ballot_id=self.ballot.pk),
)
r = self.client.get(url)
self.assertEqual(r.status_code, 302)
self.assertIn("/accounts/login", r["Location"])
r = self.client.post(
url,
dict(position="yes", comment="oib239sb", send_mail="Save and send email"),
)
self.assertEqual(r.status_code, 302)
self.assertIn("/accounts/login", r["Location"])