Merge pull request #5944 from rjsparks/fixups5

fix: more adjustments to match new rfc document type
This commit is contained in:
Jennifer Richards 2023-07-09 09:34:30 -03:00 committed by GitHub
commit a1d776c2f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 62 additions and 58 deletions

View file

@ -122,7 +122,7 @@ class DocumentFactory(BaseDocumentFactory):
class RfcFactory(BaseDocumentFactory):
type_id = "rfc"
rfc_number = factory.Sequence(lambda n: n + 1000)
name = factory.LazyAttribute(lambda o: f"rfc{o.rfc_number:04d}")
name = factory.LazyAttribute(lambda o: f"rfc{o.rfc_number:d}")
expires = None
@factory.post_generation

View file

@ -148,7 +148,7 @@ class AddDownrefForm(forms.Form):
raise forms.ValidationError("Please provide a referenced RFC and a referencing Internet-Draft")
rfc = self.cleaned_data['rfc']
if rfc.type_id != "rfc":
if rfc.document.type_id != "rfc":
raise forms.ValidationError("Cannot find the RFC: " + rfc.name)
return rfc

View file

@ -686,7 +686,7 @@ class RelatedDocument(models.Model):
if source_lvl not in ['bcp','ps','ds','std']:
return None
if self.target.document.get_state().slug == 'rfc':
if self.target.document.type_id == 'rfc':
if not self.target.document.std_level:
target_lvl = 'unkn'
else:
@ -709,8 +709,8 @@ class RelatedDocument(models.Model):
def is_approved_downref(self):
if self.target.document.get_state().slug == 'rfc':
if RelatedDocument.objects.filter(relationship_id='downref-approval', target=self.target):
if self.target.document.type_id == "rfc":
if RelatedDocument.objects.filter(relationship_id='downref-approval', target=self.target).exists():
return "Approved Downref"
return False

View file

@ -1121,8 +1121,8 @@ class RegenerateLastCallTestCase(TestCase):
self.assertFalse("contains these normative down" in lc_text)
rfc = IndividualRfcFactory.create(
rfc_number=6666,
stream_id='ise',
other_aliases=['rfc6666',],
states=[('draft','rfc'),('draft-iesg','pub')],
std_level_id='inf',
)

View file

@ -22,7 +22,7 @@ class Downref(TestCase):
self.draftalias = self.draft.docalias.get(name='draft-ietf-mars-test')
self.doc = WgDraftFactory(name='draft-ietf-mars-approved-document',states=[('draft-iesg','rfcqueue')])
self.docalias = self.doc.docalias.get(name='draft-ietf-mars-approved-document')
self.rfc = WgRfcFactory(alias2__name='rfc9998')
self.rfc = WgRfcFactory(rfc_number=9998)
self.rfcalias = self.rfc.docalias.get(name='rfc9998')
RelatedDocument.objects.create(source=self.doc, target=self.rfcalias, relationship_id='downref-approval')
@ -100,7 +100,7 @@ class Downref(TestCase):
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.docalias.get(name='rfc9999'), relationship_id='refnorm')
url = urlreverse('ietf.doc.views_ballot.lastcalltext', kwargs=dict(name=draft.name))
login_testing_unauthorized(self, "secretary", url)

View file

@ -137,10 +137,18 @@ class ReviewTests(TestCase):
url = urlreverse('ietf.doc.views_review.request_review', kwargs={ "name": doc.name })
login_testing_unauthorized(self, "ad", url)
# get should fail
# get should fail - all non draft types 404
r = self.client.get(url)
self.assertEqual(r.status_code, 404)
# Can only request reviews on active draft documents
doc = WgDraftFactory(states=[("draft","rfc")])
url = urlreverse('ietf.doc.views_review.request_review', kwargs={ "name": doc.name })
r = self.client.get(url)
self.assertEqual(r.status_code, 403)
def test_doc_page(self):
doc = WgDraftFactory(group__acronym='mars',rev='01')

View file

@ -14,7 +14,7 @@ from textwrap import wrap
from django.conf import settings
from django.urls import reverse as urlreverse
from ietf.doc.factories import DocumentFactory, IndividualRfcFactory, WgRfcFactory
from ietf.doc.factories import DocumentFactory, IndividualRfcFactory, WgRfcFactory, WgDraftFactory
from ietf.doc.models import ( Document, DocAlias, State, DocEvent,
BallotPositionDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent )
from ietf.doc.utils import create_ballot_if_not_open
@ -74,7 +74,7 @@ class StatusChangeTests(TestCase):
self.assertEqual(status_change.rev,'00')
self.assertEqual(status_change.ad.name,'Areað Irector')
self.assertEqual(status_change.notify,'ipu@ietf.org')
self.assertTrue(status_change.relateddocument_set.filter(relationship__slug='tois',target__docs__name='draft-ietf-random-thing'))
self.assertTrue(status_change.relateddocument_set.filter(relationship__slug='tois',target__docs__name='rfc9999'))
# Verify that it's possible to start a status change without a responsible ad.
r = self.client.post(url,dict(
@ -449,9 +449,16 @@ class StatusChangeTests(TestCase):
def setUp(self):
super().setUp()
IndividualRfcFactory(alias2__name='rfc14',name='draft-was-never-issued',std_level_id='unkn')
WgRfcFactory(alias2__name='rfc9999',name='draft-ietf-random-thing',std_level_id='ps')
WgRfcFactory(alias2__name='rfc9998',name='draft-ietf-random-other-thing',std_level_id='inf')
IndividualRfcFactory(rfc_number=14,std_level_id='unkn') # draft was never issued
rfc = WgRfcFactory(rfc_number=9999,std_level_id='ps')
draft = WgDraftFactory(name='draft-ietf-random-thing')
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
rfc = WgRfcFactory(rfc_number=9998,std_level_id='inf')
draft = WgDraftFactory(name='draft-ietf-random-other-thing')
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
DocumentFactory(type_id='statchg',name='status-change-imaginary-mid-review',notify='notify@example.org')
class StatusChangeSubmitTests(TestCase):

View file

@ -11,7 +11,7 @@ from django.utils import timezone
from ietf.group.factories import GroupFactory, RoleFactory
from ietf.name.models import DocTagName
from ietf.person.factories import PersonFactory
from ietf.utils.test_utils import TestCase, name_of_file_containing
from ietf.utils.test_utils import TestCase, name_of_file_containing, reload_db_objects
from ietf.person.models import Person
from ietf.doc.factories import DocumentFactory, WgRfcFactory, WgDraftFactory
from ietf.doc.models import State, DocumentActionHolder, DocumentAuthor, Document
@ -251,40 +251,42 @@ class MiscTests(TestCase):
self.assertEqual(docauth.country, '')
def do_fuzzy_find_documents_rfc_test(self, name):
rfc = WgRfcFactory(name=name, create_revisions=(0, 1, 2))
rfc = Document.objects.get(pk=rfc.pk) # clear out any cached values
draft = WgDraftFactory(name=name, create_revisions=(0, 1, 2))
rfc = WgRfcFactory()
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft, rfc = reload_db_objects(draft, rfc)
# by canonical name
found = fuzzy_find_documents(rfc.canonical_name(), None)
self.assertCountEqual(found.documents, [rfc])
self.assertEqual(found.matched_rev, None)
self.assertEqual(found.matched_name, rfc.canonical_name())
# by draft name, no rev
found = fuzzy_find_documents(rfc.name, None)
self.assertCountEqual(found.documents, [rfc])
self.assertEqual(found.matched_rev, None)
self.assertEqual(found.matched_name, rfc.name)
# by draft name, no rev
found = fuzzy_find_documents(draft.name, None)
self.assertCountEqual(found.documents, [draft])
self.assertEqual(found.matched_rev, None)
self.assertEqual(found.matched_name, draft.name)
# by draft name, latest rev
found = fuzzy_find_documents(rfc.name, '02')
self.assertCountEqual(found.documents, [rfc])
found = fuzzy_find_documents(draft.name, '02')
self.assertCountEqual(found.documents, [draft])
self.assertEqual(found.matched_rev, '02')
self.assertEqual(found.matched_name, rfc.name)
self.assertEqual(found.matched_name, draft.name)
# by draft name, earlier rev
found = fuzzy_find_documents(rfc.name, '01')
self.assertCountEqual(found.documents, [rfc])
found = fuzzy_find_documents(draft.name, '01')
self.assertCountEqual(found.documents, [draft])
self.assertEqual(found.matched_rev, '01')
self.assertEqual(found.matched_name, rfc.name)
self.assertEqual(found.matched_name, draft.name)
# wrong name or revision
found = fuzzy_find_documents(rfc.name + '-incorrect')
found = fuzzy_find_documents(draft.name + '-incorrect')
self.assertCountEqual(found.documents, [], 'Should not find document that does not match')
found = fuzzy_find_documents(rfc.name + '-incorrect', '02')
found = fuzzy_find_documents(draft.name + '-incorrect', '02')
self.assertCountEqual(found.documents, [], 'Still should not find document, even with a version')
found = fuzzy_find_documents(rfc.name, '22')
self.assertCountEqual(found.documents, [rfc],
found = fuzzy_find_documents(draft.name, '22')
self.assertCountEqual(found.documents, [draft],
'Should find document even if rev does not exist')

View file

@ -117,7 +117,7 @@ class RequestReviewForm(forms.ModelForm):
@login_required
def request_review(request, name):
doc = get_object_or_404(Document, name=name)
doc = get_object_or_404(Document, type_id="draft", name=name)
if not can_request_review_of_doc(request.user, doc):
permission_denied(request, "You do not have permission to perform this action")

View file

@ -107,7 +107,7 @@ class IESGAgendaTests(TestCase):
super().setUp()
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', other_aliases=['rfc6666',], states=[('draft','rfc'),('draft-iesg','pub')], std_level_id='inf', )
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')
ise_draft = IndividualDraftFactory(name='draft-imaginary-independent-submission')
ise_draft.stream = StreamName.objects.get(slug="ise")

View file

@ -50,6 +50,8 @@ def can_request_review_of_doc(user, doc):
if not user.is_authenticated:
return False
# This is in a strange place as it has nothing to do with the user
# but this utility is used in too many places to move this quickly.
if doc.type_id == 'draft' and doc.get_state_slug() != 'active':
return False

View file

@ -67,8 +67,7 @@ class SecrTelechatTestCase(TestCase):
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', other_aliases=['rfc6666',],
states=[('draft','rfc'),('draft-iesg','pub')], std_level_id='inf', )
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')
create_ballot_if_not_open(None, draft, ad, 'approve')

View file

@ -707,7 +707,7 @@ class SubmissionAutoUploadForm(SubmissionBaseUploadForm):
elif alias.document.get_state_slug() == "rfc":
self.add_error(
'replaces',
forms.ValidationError("An Internet-Draft cannot replace an RFC"),
forms.ValidationError("An Internet-Draft cannot replace another Internet-Draft that has become an RFC"),
)
elif alias.document.get_state_slug('draft-iesg') in ('approved', 'ann', 'rfcqueue'):
self.add_error(

View file

@ -3099,13 +3099,15 @@ class SubmissionUploadFormTests(BaseSubmitTestCase):
# can't replace RFC
rfc = WgRfcFactory()
draft = WgDraftFactory(states=[("draft", "rfc")])
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
form = SubmissionAutoUploadForm(
request_factory.get('/some/url'),
data={'user': auth.user.username, 'replaces': rfc.name},
data={'user': auth.user.username, 'replaces': draft.name},
files=files_dict,
)
self.assertFalse(form.is_valid())
self.assertIn('An Internet-Draft cannot replace 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'))
@ -3697,25 +3699,9 @@ class RefsTests(BaseSubmitTestCase):
class PostSubmissionTests(BaseSubmitTestCase):
@override_settings(RFC_FILE_TYPES=('txt', 'xml'), IDSUBMIT_FILE_TYPES=('pdf', 'md'))
def test_find_submission_filenames_rfc(self):
"""Posting an RFC submission should use RFC_FILE_TYPES"""
rfc = IndividualRfcFactory()
path = Path(self.staging_dir)
for ext in ['txt', 'xml', 'pdf', 'md']:
(path / f'{rfc.name}-{rfc.rev}.{ext}').touch()
files = find_submission_filenames(rfc)
self.assertCountEqual(
files,
{
'txt': f'{path}/{rfc.name}-{rfc.rev}.txt',
'xml': f'{path}/{rfc.name}-{rfc.rev}.xml',
# should NOT find the pdf or md
}
)
@override_settings(RFC_FILE_TYPES=('txt', 'xml'), IDSUBMIT_FILE_TYPES=('pdf', 'md'))
def test_find_submission_filenames_draft(self):
def test_find_submission_filenames(self):
"""Posting an I-D submission should use IDSUBMIT_FILE_TYPES"""
draft = WgDraftFactory()
path = Path(self.staging_dir)

View file

@ -287,7 +287,7 @@ def find_submission_filenames(draft):
"""
path = pathlib.Path(settings.IDSUBMIT_STAGING_PATH)
stem = f'{draft.name}-{draft.rev}'
allowed_types = settings.RFC_FILE_TYPES if draft.get_state_slug() == 'rfc' else settings.IDSUBMIT_FILE_TYPES
allowed_types = settings.IDSUBMIT_FILE_TYPES
candidates = {ext: path / f'{stem}.{ext}' for ext in allowed_types}
return {ext: str(filename) for ext, filename in candidates.items() if filename.exists()}