Skip to content

Commit

Permalink
fix: repairs reflecting removal of DocAlias from the RelatedDocument …
Browse files Browse the repository at this point in the history
…models
  • Loading branch information
rjsparks committed Jul 20, 2023
1 parent 1ad19e0 commit 51c22d8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
17 changes: 13 additions & 4 deletions ietf/idindex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ def test_all_id_txt(self):

RelatedDocument.objects.create(
relationship=DocRelationshipName.objects.get(slug="replaces"),
source=Document.objects.create(type_id="draft", rev="00", name="draft-test-replacement"),
target=draft.docalias.get(name__startswith="draft"))
source=Document.objects.create(
type_id="draft",
rev="00",
name="draft-test-replacement"
),
target=draft
)

txt = all_id_txt()
self.assertTrue(draft.name + "-" + draft.rev in txt)
Expand Down Expand Up @@ -111,8 +116,12 @@ def get_fields(content):
draft.set_state(State.objects.get(type="draft", slug="repl"))
RelatedDocument.objects.create(
relationship=DocRelationshipName.objects.get(slug="replaces"),
source=Document.objects.create(type_id="draft", rev="00", name="draft-test-replacement"),
target=draft.docalias.get(name__startswith="draft"))
source=Document.objects.create(
type_id="draft",
rev="00",
name="draft-test-replacement"
),
target=draft)

t = get_fields(all_id2_txt())
self.assertEqual(t[5], "draft-test-replacement")
Expand Down
6 changes: 3 additions & 3 deletions ietf/iesg/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def setUp(self):
mars = GroupFactory(acronym='mars',parent=Group.objects.get(acronym='farfut'))
wgdraft = WgDraftFactory(name='draft-ietf-mars-test', group=mars, intended_std_level_id='ps')
rfc = IndividualRfcFactory.create(stream_id='irtf', rfc_number=6666, std_level_id='inf', )
wgdraft.relateddocument_set.create(target=rfc.docalias.get(name='rfc6666'), relationship_id='refnorm')
wgdraft.relateddocument_set.create(target=rfc, relationship_id='refnorm')
ise_draft = IndividualDraftFactory(name='draft-imaginary-independent-submission')
ise_draft.stream = StreamName.objects.get(slug="ise")
ise_draft.save_with_history([DocEvent(doc=ise_draft, rev=ise_draft.rev, type="changed_stream", by=Person.objects.get(user__username="secretary"), desc="Test")])
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_fill_in_agenda_docs(self):

relation = RelatedDocument.objects.create(
source=statchg,
target=DocAlias.objects.filter(name__startswith='rfc', docs__std_level="ps")[0],
target=Document.objects.filter(type_id="rfc", std_level="ps").first(),
relationship_id="tohist")

statchg.group = Group.objects.get(acronym="mars")
Expand All @@ -256,7 +256,7 @@ def test_fill_in_agenda_docs(self):
self.assertTrue(statchg in agenda_data(date_str)["sections"]["2.3.3"]["docs"])

# 3.3 document status changes
relation.target = DocAlias.objects.filter(name__startswith='rfc', docs__std_level="inf")[0]
relation.target = Document.objects.filter(type_id="rfc", std_level="inf").first()
relation.save()

statchg.group = Group.objects.get(acronym="mars")
Expand Down
3 changes: 1 addition & 2 deletions ietf/secr/telechat/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def test_doc_detail_draft_with_downref(self):
ad = Person.objects.get(user__username="ad")
draft = WgDraftFactory(ad=ad, intended_std_level_id='ps', states=[('draft-iesg','pub-req'),])
rfc = IndividualRfcFactory.create(stream_id='irtf', rfc_number=6666, std_level_id='inf')
draft.relateddocument_set.create(target=rfc.docalias.get(name='rfc6666'),
relationship_id='refnorm')
draft.relateddocument_set.create(target=rfc, relationship_id='refnorm')
create_ballot_if_not_open(None, draft, ad, 'approve')
d = get_next_telechat_date()
date = d.strftime('%Y-%m-%d')
Expand Down
8 changes: 4 additions & 4 deletions ietf/stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,11 @@ def generate_canonical_names(values):
bins = defaultdict(set)

cite_relationships = list(DocRelationshipName.objects.filter(slug__in=['refnorm', 'refinfo', 'refunk', 'refold']))
person_filters &= Q(documentauthor__document__docalias__relateddocument__relationship__in=cite_relationships)
person_filters &= Q(documentauthor__document__relateddocument__relationship__in=cite_relationships)

person_qs = Person.objects.filter(person_filters)

for name, citations in person_qs.values_list("name").annotate(Count("documentauthor__document__docalias__relateddocument")):
for name, citations in person_qs.values_list("name").annotate(Count("documentauthor__document__relateddocument")):
bins[citations or 0].add(name)

total_persons = count_bins(bins)
Expand All @@ -587,11 +587,11 @@ def generate_canonical_names(values):
bins = defaultdict(set)

cite_relationships = list(DocRelationshipName.objects.filter(slug__in=['refnorm', 'refinfo', 'refunk', 'refold']))
person_filters &= Q(documentauthor__document__docalias__relateddocument__relationship__in=cite_relationships)
person_filters &= Q(documentauthor__document__relateddocument__relationship__in=cite_relationships)

person_qs = Person.objects.filter(person_filters)

values = person_qs.values_list("name", "documentauthor__document").annotate(Count("documentauthor__document__docalias__relateddocument"))
values = person_qs.values_list("name", "documentauthor__document").annotate(Count("documentauthor__document__relateddocument"))
for name, ts in itertools.groupby(values.order_by("name"), key=lambda t: t[0]):
h_index = compute_hirsch_index([citations for _, document, citations in ts])
bins[h_index or 0].add(name)
Expand Down
6 changes: 3 additions & 3 deletions ietf/submit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def supply_extra_metadata(self, name, status_url, submitter_name, submitter_emai
submission = Submission.objects.get(name=name)
self.assertEqual(submission.submitter, email.utils.formataddr((submitter_name, submitter_email)))
self.assertEqual([] if submission.replaces == "" else submission.replaces.split(','),
[ d.name for d in DocAlias.objects.filter(pk__in=replaces) ])
[ d.name for d in Document.objects.filter(pk__in=replaces) ])
self.assertCountEqual(
[str(r) for r in submission.external_resources.all()],
[str(r) for r in extresources] if extresources else [],
Expand Down Expand Up @@ -418,7 +418,7 @@ def submit_new_wg(self, formats):
self.assertEqual(authors[0].person, author)
self.assertEqual(set(draft.formal_languages.all()), set(FormalLanguageName.objects.filter(slug="json")))
self.assertEqual(draft.relations_that_doc("replaces").count(), 1)
self.assertTrue(draft.relations_that_doc("replaces").first().target, replaced_alias)
self.assertTrue(draft.relations_that_doc("replaces").first().target, draft)
self.assertEqual(draft.relations_that_doc("possibly-replaces").count(), 1)
self.assertTrue(draft.relations_that_doc("possibly-replaces").first().target, sug_replaced_alias)
self.assertEqual(len(outbox), mailbox_before + 5)
Expand Down Expand Up @@ -3097,7 +3097,7 @@ def test_replaces_field(self):
files=files_dict,
)
self.assertFalse(form.is_valid())
self.assertIn('An Internet-Draft can only replace another Internet-Draft that has become an RFC', form.errors['replaces'])
self.assertIn('An Internet-Draft cannot replace another Internet-Draft that has become an RFC', form.errors['replaces'])

# can't replace draft approved by iesg
existing_drafts[0].set_state(State.objects.get(type='draft-iesg', slug='approved'))
Expand Down
4 changes: 2 additions & 2 deletions ietf/sync/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def test_rfc_index(self):
self.assertTrue(DocAlias.objects.filter(name="bcp1", docs=doc))
self.assertTrue(DocAlias.objects.filter(name="fyi1", docs=doc))
self.assertTrue(DocAlias.objects.filter(name="std1", docs=doc))
self.assertTrue(RelatedDocument.objects.filter(source=doc, target__name="rfc123", relationship="updates"))
self.assertTrue(RelatedDocument.objects.filter(source=doc, target__name="rfc123", relationship="updates").exists())
self.assertEqual(doc.title, "A Testing RFC")
self.assertEqual(doc.abstract, "This is some interesting text.")
self.assertEqual(doc.get_state_slug(), "rfc")
Expand Down Expand Up @@ -602,4 +602,4 @@ def test_rfceditor_undo(self):
e = DeletedEvent.objects.all().order_by("-time", "-id")[0]

e.content_type.model_class().objects.create(**json.loads(e.json))
self.assertTrue(StateDocEvent.objects.filter(desc="First", doc=draft))
self.assertTrue(StateDocEvent.objects.filter(desc="First", doc=draft))

0 comments on commit 51c22d8

Please sign in to comment.