|
36 | 36 | from ietf.doc.models import ( Document, DocAlias, DocRelationshipName, RelatedDocument, State, |
37 | 37 | DocEvent, BallotPositionDocEvent, LastCallDocEvent, WriteupDocEvent, NewRevisionDocEvent, BallotType, |
38 | 38 | EditedAuthorsDocEvent ) |
39 | | -from ietf.doc.factories import ( DocumentFactory, DocEventFactory, CharterFactory, |
| 39 | +from ietf.doc.factories import ( DocumentFactory, DocEventFactory, CharterFactory, |
40 | 40 | ConflictReviewFactory, WgDraftFactory, IndividualDraftFactory, WgRfcFactory, |
41 | 41 | IndividualRfcFactory, StateDocEventFactory, BallotPositionDocEventFactory, |
42 | 42 | BallotDocEventFactory, DocumentAuthorFactory, NewRevisionDocEventFactory, |
43 | | - StatusChangeFactory, BofreqFactory, DocExtResourceFactory, RgDraftFactory) |
| 43 | + StatusChangeFactory, DocExtResourceFactory, RgDraftFactory) |
44 | 44 | from ietf.doc.forms import NotifyForm |
45 | 45 | from ietf.doc.fields import SearchableDocumentsField |
46 | 46 | from ietf.doc.utils import create_ballot_if_not_open, uppercase_std_abbreviated_name |
47 | | -from ietf.doc.views_search import ad_dashboard_group, ad_dashboard_group_type, shorten_group_name # TODO: red flag that we're importing from views in tests. Move these to utils. |
48 | 47 | from ietf.group.models import Group, Role |
49 | 48 | from ietf.group.factories import GroupFactory, RoleFactory |
50 | 49 | from ietf.ipr.factories import HolderIprDisclosureFactory |
|
60 | 59 | from ietf.utils.test_utils import TestCase |
61 | 60 | from ietf.utils.text import normalize_text |
62 | 61 | from ietf.utils.timezone import date_today, datetime_today, DEADLINE_TZINFO, RPC_TZINFO |
| 62 | +from ietf.doc.utils_search import AD_WORKLOAD |
63 | 63 |
|
64 | 64 |
|
65 | 65 | class SearchTests(TestCase): |
@@ -279,43 +279,61 @@ def test_frontpage(self): |
279 | 279 | self.assertContains(r, "Document Search") |
280 | 280 |
|
281 | 281 | def test_ad_workload(self): |
282 | | - Role.objects.filter(name_id='ad').delete() |
283 | | - ad = RoleFactory(name_id='ad',group__type_id='area',group__state_id='active',person__name='Example Areadirector').person |
284 | | - doc_type_names = ['bofreq', 'charter', 'conflrev', 'draft', 'statchg'] |
285 | | - expected = defaultdict(lambda :0) |
286 | | - for doc_type_name in doc_type_names: |
287 | | - if doc_type_name=='draft': |
288 | | - states = State.objects.filter(type='draft-iesg', used=True).values_list('slug', flat=True) |
289 | | - else: |
290 | | - states = State.objects.filter(type=doc_type_name, used=True).values_list('slug', flat=True) |
291 | | - |
292 | | - for state in states: |
293 | | - target_num = random.randint(0,2) |
| 282 | + Role.objects.filter(name_id="ad").delete() |
| 283 | + ad = RoleFactory( |
| 284 | + name_id="ad", |
| 285 | + group__type_id="area", |
| 286 | + group__state_id="active", |
| 287 | + person__name="Example Areadirector", |
| 288 | + ).person |
| 289 | + expected = defaultdict(lambda: 0) |
| 290 | + for doc_type_slug in AD_WORKLOAD: |
| 291 | + for state in AD_WORKLOAD[doc_type_slug]: |
| 292 | + target_num = random.randint(0, 2) |
294 | 293 | for _ in range(target_num): |
295 | | - if doc_type_name == 'draft': |
296 | | - doc = IndividualDraftFactory(ad=ad,states=[('draft-iesg', state),('draft','rfc' if state=='pub' else 'active')]) |
297 | | - elif doc_type_name == 'charter': |
298 | | - doc = CharterFactory(ad=ad, states=[(doc_type_name, state)]) |
299 | | - elif doc_type_name == 'bofreq': |
300 | | - # Note that the view currently doesn't handle bofreqs |
301 | | - doc = BofreqFactory(states=[(doc_type_name, state)], bofreqresponsibledocevent__responsible=[ad]) |
302 | | - elif doc_type_name == 'conflrev': |
303 | | - doc = ConflictReviewFactory(ad=ad, states=State.objects.filter(type_id=doc_type_name, slug=state)) |
304 | | - elif doc_type_name == 'statchg': |
305 | | - doc = StatusChangeFactory(ad=ad, states=State.objects.filter(type_id=doc_type_name, slug=state)) |
306 | | - else: |
307 | | - # Currently unreachable |
308 | | - doc = DocumentFactory(type_id=doc_type_name, ad=ad, states=[(doc_type_name, state)]) |
309 | | - |
310 | | - if not slugify(ad_dashboard_group_type(doc)) in ('document', 'none'): |
311 | | - expected[(slugify(ad_dashboard_group_type(doc)), slugify(ad.full_name_as_key()), slugify(shorten_group_name(ad_dashboard_group(doc))))] += 1 |
312 | | - |
313 | | - url = urlreverse('ietf.doc.views_search.ad_workload') |
| 294 | + if ( |
| 295 | + doc_type_slug == "draft" |
| 296 | + or doc_type_slug == "rfc" |
| 297 | + and state == "rfcqueue" |
| 298 | + ): |
| 299 | + IndividualDraftFactory( |
| 300 | + ad=ad, |
| 301 | + states=[ |
| 302 | + ("draft-iesg", state), |
| 303 | + ("draft", "rfc" if state == "pub" else "active"), |
| 304 | + ], |
| 305 | + ) |
| 306 | + elif doc_type_slug == "rfc": |
| 307 | + WgRfcFactory.create( |
| 308 | + states=[("draft", "rfc"), ("draft-iesg", "pub")] |
| 309 | + ) |
| 310 | + |
| 311 | + elif doc_type_slug == "charter": |
| 312 | + CharterFactory(ad=ad, states=[(doc_type_slug, state)]) |
| 313 | + elif doc_type_slug == "conflrev": |
| 314 | + ConflictReviewFactory( |
| 315 | + ad=ad, |
| 316 | + states=State.objects.filter( |
| 317 | + type_id=doc_type_slug, slug=state |
| 318 | + ), |
| 319 | + ) |
| 320 | + elif doc_type_slug == "statchg": |
| 321 | + StatusChangeFactory( |
| 322 | + ad=ad, |
| 323 | + states=State.objects.filter( |
| 324 | + type_id=doc_type_slug, slug=state |
| 325 | + ), |
| 326 | + ) |
| 327 | + self.client.login(username="ad", password="ad+password") |
| 328 | + url = urlreverse("ietf.doc.views_search.ad_workload") |
314 | 329 | r = self.client.get(url) |
315 | 330 | self.assertEqual(r.status_code, 200) |
316 | 331 | q = PyQuery(r.content) |
317 | 332 | for group_type, ad, group in expected: |
318 | | - self.assertEqual(int(q(f'#{group_type}-{ad}-{group}').text()),expected[(group_type, ad, group)]) |
| 333 | + self.assertEqual( |
| 334 | + int(q(f"#{group_type}-{ad}-{group}").text()), |
| 335 | + expected[(group_type, ad, group)], |
| 336 | + ) |
319 | 337 |
|
320 | 338 | def test_docs_for_ad(self): |
321 | 339 | ad = RoleFactory(name_id='ad',group__type_id='area',group__state_id='active').person |
|
0 commit comments