Skip to content

Commit

Permalink
fix: continued repair of code/tests re: RelatedDocument model change
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks committed Jul 20, 2023
1 parent 59c0a1f commit 8173444
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 54 deletions.
6 changes: 3 additions & 3 deletions ietf/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def test_draft_with_broken_history(self):
def do_rfc_test(self, draft_name):
draft = WgDraftFactory(name=draft_name, create_revisions=range(0,2))
rfc = WgRfcFactory(group=draft.group, rfc_number=self.next_rfc_number())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)
draft.set_state(State.objects.get(type_id='draft',slug='rfc'))
draft.set_state(State.objects.get(type_id='draft-iesg', slug='pub'))
draft, rfc = reload_db_objects(draft, rfc)
Expand Down Expand Up @@ -1017,7 +1017,7 @@ def test_rfc(self):
def test_rfc_with_tombstone(self):
draft = WgDraftFactory(create_revisions=range(0,2))
rfc = WgRfcFactory(rfc_number=3261,group=draft.group)# See views_doc.HAS_TOMBSTONE
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)
draft.set_state(State.objects.get(type_id='draft',slug='rfc'))
draft.set_state(State.objects.get(type_id='draft-iesg', slug='pub'))
draft = reload_db_objects(draft)
Expand All @@ -1029,7 +1029,7 @@ def test_rfc_with_tombstone(self):
def do_rfc_with_broken_history_test(self, draft_name):
draft = WgDraftFactory(rev='10', name=draft_name)
rfc = WgRfcFactory(group=draft.group, rfc_number=self.next_rfc_number())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)
draft.set_state(State.objects.get(type_id='draft',slug='rfc'))
draft.set_state(State.objects.get(type_id='draft-iesg', slug='pub'))
draft = reload_db_objects(draft)
Expand Down
2 changes: 1 addition & 1 deletion ietf/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def rfcdiff_latest_json(request, name, rev=None):
response['previous'] = f'{draft.name}-{prev_rev}'
response['previous_url'] = get_previous_url(draft.name, prev_rev)
elif doc.type_id == "draft" and not found_rev and doc.relateddocument_set.filter(relationship_id="became_rfc").exists():
rfc = doc.related_that_doc("became_rfc")[0].document
rfc = doc.related_that_doc("became_rfc")[0]
response['content_url'] = rfc.get_href()
response['name']=rfc.name
prev_rev = doc.rev
Expand Down
3 changes: 1 addition & 2 deletions ietf/doc/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def clean_rfc(self):
raise forms.ValidationError("Please provide a referenced RFC and a referencing Internet-Draft")

rfc = self.cleaned_data['rfc']
if rfc.document.type_id != "rfc":
if rfc.type_id != "rfc":
raise forms.ValidationError("Cannot find the RFC: " + rfc.name)
return rfc

Expand Down Expand Up @@ -190,7 +190,6 @@ def clean(self):
v_err_refnorm = d.name
if v_err_refnorm:
v_err_refnorm_prefix = f"There does not seem to be a normative reference to RFC {rfc.rfc_number} by "
v_err_refnorm_prefix = f"There does not seem to be a normative reference to RFC {rfc.document.rfc_number} by "
raise forms.ValidationError(v_err_refnorm_prefix + v_err_refnorm)


Expand Down
5 changes: 2 additions & 3 deletions ietf/doc/management/commands/generate_draft_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ def handle(self, *args, **options):
for draft in interesting_drafts.distinct().iterator():
# Omit drafts that became RFCs, unless they were published in the last DEFAULT_YEARS
if draft.get_state_slug()=="rfc":
rfc_alias = next(iter(draft.related_that_doc("became_rfc")), None)
log.assertion("rfc_alias is not None")
rfc = rfc_alias.document
rfc = next(iter(draft.related_that_doc("became_rfc")), None)
log.assertion("rfc is not None")
if rfc.latest_event(type='published_rfc').time < show_since:
continue

Expand Down
22 changes: 11 additions & 11 deletions ietf/doc/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,16 +771,16 @@ def test_document_draft(self):
rfc = WgRfcFactory(group=draft.group, name="rfc123456")
rfc.save_with_history([DocEvent.objects.create(doc=rfc, rev=None, type="published_rfc", by=Person.objects.get(name="(System)"))])

draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)

obsoleted = IndividualRfcFactory()
rfc.relateddocument_set.create(relationship_id='obs',target=obsoleted.docalias.first())
rfc.relateddocument_set.create(relationship_id='obs',target=obsoleted)
obsoleted_by = IndividualRfcFactory()
obsoleted_by.relateddocument_set.create(relationship_id='obs',target=rfc.docalias.first())
obsoleted_by.relateddocument_set.create(relationship_id='obs',target=rfc)
updated = IndividualRfcFactory()
rfc.relateddocument_set.create(relationship_id='updates',target=updated.docalias.first())
rfc.relateddocument_set.create(relationship_id='updates',target=updated)
updated_by = IndividualRfcFactory()
updated_by.relateddocument_set.create(relationship_id='updates',target=rfc.docalias.first())
updated_by.relateddocument_set.create(relationship_id='updates',target=rfc)

r = self.client.get(urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=draft.name)))
self.assertEqual(r.status_code, 302)
Expand Down Expand Up @@ -1430,7 +1430,7 @@ def test_draft_group_link(self):

rfc = WgRfcFactory(group=group)
draft = WgDraftFactory(group=group)
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)
DocEventFactory.create(doc=rfc, type='published_rfc', time=event_datetime)
r = self.client.get(urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=rfc.name)))
self.assertEqual(r.status_code, 200)
Expand All @@ -1445,7 +1445,7 @@ def test_draft_group_link(self):

rfc = WgRfcFactory(group=group)
draft = WgDraftFactory(name='draft-rfc-document-%s'% group_type_id, group=group)
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)
DocEventFactory.create(doc=rfc, type='published_rfc', time=event_datetime)
r = self.client.get(urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=rfc.name)))
self.assertEqual(r.status_code, 200)
Expand Down Expand Up @@ -2111,7 +2111,7 @@ def testManagementCommand(self):
rfc3 = WgRfcFactory()
DocEventFactory.create(doc=rfc3, type="published_rfc", time=a_month_ago)
doc3.relateddocument_set.create(
relationship_id="became_rfc", target=rfc3.docalias.first()
relationship_id="became_rfc", target=rfc3
)
doc4 = WgDraftFactory.create(
authors=[author4, author5],
Expand All @@ -2127,7 +2127,7 @@ def testManagementCommand(self):
time=datetime.datetime(2010, 10, 10, tzinfo=RPC_TZINFO),
)
doc4.relateddocument_set.create(
relationship_id="became_rfc", target=rfc4.docalias.first()
relationship_id="became_rfc", target=rfc4
)
doc5 = IndividualDraftFactory(authors=[author6])

Expand Down Expand Up @@ -2680,7 +2680,7 @@ def test_rfc_status(self):
def test_idnits2_state(self):
rfc = WgRfcFactory()
draft = WgDraftFactory()
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)
url = urlreverse('ietf.doc.views_doc.idnits2_state', kwargs=dict(name=rfc.canonical_name()))
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
Expand Down Expand Up @@ -2767,7 +2767,7 @@ def should_404(self, argdict):
def test_pdfized(self):
rfc = WgRfcFactory()
draft = WgDraftFactory(create_revisions=range(0,2))
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)

dir = settings.RFC_PATH
with (Path(dir) / f'{rfc.name}.txt').open('w') as f:
Expand Down
2 changes: 1 addition & 1 deletion ietf/doc/tests_downref.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_downref_registry_add(self):
def test_downref_last_call(self):
draft = WgDraftFactory(name='draft-ietf-mars-ready-for-lc-document',intended_std_level_id='ps',states=[('draft-iesg','iesg-eva')])
WgDraftFactory(name='draft-ietf-mars-another-approved-document',states=[('draft-iesg','rfcqueue')])
rfc9999 = WgRfcFactory(alias2__name='rfc9999', std_level_id=None)
rfc9999 = WgRfcFactory(rfc_number=9999, std_level_id=None)
RelatedDocument.objects.create(source=draft, target=rfc9999, relationship_id='refnorm')
url = urlreverse('ietf.doc.views_ballot.lastcalltext', kwargs=dict(name=draft.name))
login_testing_unauthorized(self, "secretary", url)
Expand Down
6 changes: 3 additions & 3 deletions ietf/doc/tests_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_update_documentauthors_with_nulls(self):
def do_fuzzy_find_documents_rfc_test(self, name):
draft = WgDraftFactory(name=name, create_revisions=(0, 1, 2))
rfc = WgRfcFactory()
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)
draft, rfc = reload_db_objects(draft, rfc)

# by canonical name
Expand Down Expand Up @@ -380,7 +380,7 @@ def test_xml(self, mock_init, mock_get_refs):
self.assertEqual(
result,
{
'warnings': ['There were 1 references with no matching DocAlias'],
'warnings': ['There were 1 references with no matching Document'],
'unfound': ['draft-not-found'],
}
)
Expand Down Expand Up @@ -443,7 +443,7 @@ def test_xml_and_plaintext(self, mock_init, mock_get_refs, mock_plaintext_init):
self.assertEqual(
result,
{
'warnings': ['There were 1 references with no matching DocAlias'],
'warnings': ['There were 1 references with no matching Document'],
'unfound': ['draft-not-found'],
}
)
Expand Down
4 changes: 2 additions & 2 deletions ietf/doc/views_ballot.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,12 +974,12 @@ def approve_downrefs(request, name):
c = DocEvent(type="downref_approved", doc=rel.source,
rev=rel.source.rev, by=login)
c.desc = "Downref to RFC %s approved by Last Call for %s-%s" % (
rel.target.document.rfc_number, rel.source, rel.source.rev)
rel.target.rfc_number, rel.source, rel.source.rev)
c.save()
c = DocEvent(type="downref_approved", doc=rel.target,
rev=rel.target.rev, by=login)
c.desc = "Downref to RFC %s approved by Last Call for %s-%s" % (
rel.target.document.rfc_number, rel.source, rel.source.rev)
rel.target.rfc_number, rel.source, rel.source.rev)
c.save()

return HttpResponseRedirect(doc.get_absolute_url())
Expand Down
9 changes: 4 additions & 5 deletions ietf/submit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ def submit_new_wg(self, formats):

# supply submitter info, then draft should be in and ready for approval
mailbox_before = len(outbox)
replaced_alias = draft.docalias.first()
r = self.supply_extra_metadata(name, status_url, author.ascii, author.email().address.lower(),
replaces=[str(draft.pk), str(sug_replaced_draft.pk)])

Expand Down Expand Up @@ -1253,7 +1252,7 @@ def submit_new_individual_replacing_wg(self, logged_in=False, group_state_id='ac
status_url,
"Submitter Name",
"[email protected]",
replaces=[str(replaced_draft.docalias.first().pk)],
replaces=[str(replaced_draft.pk)],
)

submission = Submission.objects.get(name=name, rev=rev)
Expand Down Expand Up @@ -1403,7 +1402,7 @@ def test_edit_submission_and_force_post(self):
"edit-pages": "123",
"submitter-name": "Some Random Test Person",
"submitter-email": "[email protected]",
"replaces": [str(draft.docalias.first().pk)],
"replaces": [str(draft.pk)],
"edit-note": "no comments",
"authors-0-name": "Person 1",
"authors-0-email": "[email protected]",
Expand All @@ -1422,7 +1421,7 @@ def test_edit_submission_and_force_post(self):
self.assertEqual(submission.pages, 123)
self.assertEqual(submission.note, "no comments")
self.assertEqual(submission.submitter, "Some Random Test Person <[email protected]>")
self.assertEqual(submission.replaces, draft.docalias.first().name)
self.assertEqual(submission.replaces, draft.name)
self.assertEqual(submission.state_id, "manual")

authors = submission.authors
Expand Down Expand Up @@ -3091,7 +3090,7 @@ def test_replaces_field(self):
# can't replace RFC
rfc = WgRfcFactory()
draft = WgDraftFactory(states=[("draft", "rfc")])
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc)
form = SubmissionAutoUploadForm(
request_factory.get('/some/url'),
data={'user': auth.user.username, 'replaces': draft.name},
Expand Down
37 changes: 14 additions & 23 deletions ietf/utils/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import debug # pyflakes:ignore

from ietf.doc.models import Document, DocAlias, State, DocumentAuthor, DocEvent, RelatedDocument, NewRevisionDocEvent
from ietf.doc.factories import IndividualDraftFactory, ConflictReviewFactory, StatusChangeFactory, WgDraftFactory, WgRfcFactory
from ietf.group.models import Group, GroupHistory, Role, RoleHistory
from ietf.iesg.models import TelechatDate
from ietf.ipr.models import HolderIprDisclosure, IprDocRel, IprDisclosureStateName, IprLicenseTypeName
Expand Down Expand Up @@ -391,37 +392,27 @@ def make_test_data():
)

# an independent submission before review
doc = Document.objects.create(name='draft-imaginary-independent-submission',type_id='draft',rev='00',
title="Some Independent Notes on Imagination")
doc.set_state(State.objects.get(used=True, type="draft", slug="active"))
DocAlias.objects.create(name=doc.name).docs.add(doc)
IndividualDraftFactory(title="Some Independent Notes on Imagination")

# an irtf submission mid review
doc = Document.objects.create(name='draft-imaginary-irtf-submission', type_id='draft',rev='00',
stream=StreamName.objects.get(slug='irtf'), title="The Importance of Research Imagination")
docalias = DocAlias.objects.create(name=doc.name)
docalias.docs.add(doc)
doc.set_state(State.objects.get(type="draft", slug="active"))
crdoc = Document.objects.create(name='conflict-review-imaginary-irtf-submission', type_id='conflrev',
rev='00', notify="[email protected]", title="Conflict Review of IRTF Imagination Document")
DocAlias.objects.create(name=crdoc.name).docs.add(crdoc)
crdoc.set_state(State.objects.get(name='Needs Shepherd', type__slug='conflrev'))
crdoc.relateddocument_set.create(target=docalias,relationship_id='conflrev')
doc = IndividualDraftFactory(name="draft-imaginary-irtf-submission", stream_id="irtf", title="The Importance of Research Imagination")
ConflictReviewFactory(name="conflict-review-imaginary-irtf-submission", review_of=doc, notify="[email protected]", title="Conflict Review of IRTF Imagination Document")

# A status change mid review
iesg = Group.objects.get(acronym='iesg')
doc = Document.objects.create(name='status-change-imaginary-mid-review',type_id='statchg', rev='00',
notify="[email protected]", group=iesg, title="Status Change Review without Imagination")
doc.set_state(State.objects.get(slug='needshep',type__slug='statchg'))
docalias = DocAlias.objects.create(name='status-change-imaginary-mid-review')
docalias.docs.add(doc)
doc = StatusChangeFactory(
name='status-change-imaginary-mid-review',
notify="[email protected]",
group=iesg,
title="Status Change Review without Imagination",
states= [State.objects.get(type_id="statchg",slug="needshep")]
)

# Some things for a status change to affect
def rfc_for_status_change_test_factory(name,rfc_num,std_level_id):
target_rfc = Document.objects.create(name=name, type_id='draft', std_level_id=std_level_id, notify="%[email protected]"%name)
target_rfc.set_state(State.objects.get(slug='rfc',type__slug='draft'))
DocAlias.objects.create(name=name).docs.add(target_rfc)
DocAlias.objects.create(name='rfc%d'%rfc_num).docs.add(target_rfc)
target_rfc = WgRfcFactory(rfc_number=rfc_num, std_level_id=std_level_id)
source_draft = WgDraftFactory(name=name, states=[("draft","rfc")], notify=f"{name}@ietf.org")
source_draft.relateddocument_set.create(relationship_id="became_rfc", target=target_rfc)
return target_rfc
rfc_for_status_change_test_factory('draft-ietf-random-thing',9999,'ps')
rfc_for_status_change_test_factory('draft-ietf-random-otherthing',9998,'inf')
Expand Down

0 comments on commit 8173444

Please sign in to comment.