Skip to content

Commit

Permalink
chore: continued refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks committed Jun 16, 2023
1 parent d6f58b3 commit 8ff1441
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 41 deletions.
2 changes: 1 addition & 1 deletion ietf/doc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ def related_ipr(self):
iprs = (
IprDocRel.objects.filter(
document__in=list(self.docalias.all())
+ [x.docalias.first() for x in self.all_related_that_doc(("obs", "replaces"))]
+ [x.docalias.first() for x in self.all_related_that_doc(("obs", "replaces"))] # this really is docalias until IprDocRel changes
)
.filter(disclosure__state__in=("posted", "removed"))
.values_list("disclosure", flat=True)
Expand Down
4 changes: 2 additions & 2 deletions ietf/doc/tests_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ def test_change_replaces(self):
# Post that says replaceboth replaces both base a and base b
url = urlreverse('ietf.doc.views_draft.replaces', kwargs=dict(name=self.replaceboth.name))
self.assertEqual(self.baseb.get_state().slug,'expired')
r = self.client.post(url, dict(replaces=[self.basea.docalias.first().pk, self.baseb.docalias.first().pk]))
r = self.client.post(url, dict(replaces=[self.basea.pk, self.baseb.pk]))
self.assertEqual(r.status_code, 302)
self.assertEqual(Document.objects.get(name='draft-test-base-a').get_state().slug,'repl')
self.assertEqual(Document.objects.get(name='draft-test-base-b').get_state().slug,'repl')
Expand Down Expand Up @@ -2093,7 +2093,7 @@ def test_stream_state_changes_when_replaced(self):
new_doc = IndividualDraftFactory(stream_id=stream)

url = urlreverse('ietf.doc.views_draft.replaces', kwargs=dict(name=new_doc.name))
r = self.client.post(url, dict(replaces=old_doc.docalias.first().pk))
r = self.client.post(url, dict(replaces=old_doc.pk))
self.assertEqual(r.status_code,302)
old_doc = Document.objects.get(name=old_doc.name)
self.assertEqual(old_doc.get_state_slug('draft'),'repl')
Expand Down
4 changes: 2 additions & 2 deletions ietf/doc/tests_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def test_doc_page(self):
# check we can fish it out
old_doc = WgDraftFactory(name="draft-foo-mars-test")
older_doc = WgDraftFactory(name="draft-older")
RelatedDocument.objects.create(source=old_doc, target=older_doc.docalias.first(), relationship_id='replaces')
RelatedDocument.objects.create(source=doc, target=old_doc.docalias.first(), relationship_id='replaces')
RelatedDocument.objects.create(source=old_doc, target=older_doc, relationship_id='replaces')
RelatedDocument.objects.create(source=doc, target=old_doc, relationship_id='replaces')
review_req.doc = older_doc
review_req.save()

Expand Down
38 changes: 19 additions & 19 deletions ietf/doc/tests_status_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from django.urls import reverse as urlreverse

from ietf.doc.factories import DocumentFactory, IndividualRfcFactory, WgRfcFactory
from ietf.doc.models import ( Document, DocAlias, State, DocEvent,
from ietf.doc.models import ( Document, State, DocEvent,
BallotPositionDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent )
from ietf.doc.utils import create_ballot_if_not_open
from ietf.doc.views_status_change import default_approval_text
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_start_review(self):
self.assertEqual(status_change.rev,'00')
self.assertEqual(status_change.ad.name,'Areað Irector')
self.assertEqual(status_change.notify,'[email protected]')
self.assertTrue(status_change.relateddocument_set.filter(relationship__slug='tois',target__name='draft-ietf-random-thing'))
self.assertTrue(status_change.relateddocument_set.filter(relationship__slug='tois',target__name='rfc9999'))

# Verify that it's possible to start a status change without a responsible ad.
r = self.client.post(url,dict(
Expand Down Expand Up @@ -159,8 +159,8 @@ def test_edit_notices(self):
self.assertTrue(doc.latest_event(DocEvent,type="added_comment").desc.startswith('Notification list changed'))

# Some additional setup so there's something to put in a generated notify list
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')

# Ask the form to regenerate the list
r = self.client.post(url,dict(regenerate_addresses="1"))
Expand Down Expand Up @@ -263,8 +263,8 @@ def test_edit_lc(self):
login_testing_unauthorized(self, "ad", url)

# additional setup
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')
doc.ad = Person.objects.get(name='Ad No2')
doc.save_with_history([DocEvent.objects.create(doc=doc, rev=doc.rev, type="changed_document", by=Person.objects.get(user__username="secretary"), desc="Test")])

Expand Down Expand Up @@ -307,8 +307,8 @@ def test_approve(self):
login_testing_unauthorized(self, "secretary", url)

# Some additional setup
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')
create_ballot_if_not_open(None, doc, Person.objects.get(user__username="secretary"), "statchg")
doc.set_state(State.objects.get(slug='appr-pend',type='statchg'))

Expand Down Expand Up @@ -348,10 +348,10 @@ def approval_pend_notice_test_helper(self, role):
url = urlreverse('ietf.doc.views_status_change.change_state',kwargs=dict(name=doc.name))

# Add some status change related documents
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')
# And a non-status change related document
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc14'),relationship_id='updates')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc14'),relationship_id='updates')

login_testing_unauthorized(self, role, url)
empty_outbox()
Expand All @@ -373,9 +373,9 @@ def approval_pend_notice_test_helper(self, role):
self.assertTrue(notification['Subject'].startswith('Approved:'))
notification_text = get_payload_text(notification)
self.assertIn('The AD has approved changing the status', notification_text)
self.assertIn(DocAlias.objects.get(name='rfc9999').document.canonical_name(), notification_text)
self.assertIn(DocAlias.objects.get(name='rfc9998').document.canonical_name(), notification_text)
self.assertNotIn(DocAlias.objects.get(name='rfc14').document.canonical_name(), notification_text)
self.assertIn(Document.objects.get(name='rfc9999').canonical_name(), notification_text)
self.assertIn(Document.objects.get(name='rfc9998').canonical_name(), notification_text)
self.assertNotIn(Document.objects.get(name='rfc14').canonical_name(), notification_text)
self.assertNotIn('No value found for', notification_text) # make sure all interpolation values were set
else:
self.assertEqual(len(outbox), 0)
Expand All @@ -395,8 +395,8 @@ def test_edit_relations(self):
login_testing_unauthorized(self, "secretary", url)

# Some additional setup
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')

# get
r = self.client.get(url)
Expand Down Expand Up @@ -449,9 +449,9 @@ def verify_relations(doc,target_name,status):

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(name='rfc14',std_level_id='unkn')
WgRfcFactory(name='rfc9999',std_level_id='ps')
WgRfcFactory(name='rfc9998',std_level_id='inf')
DocumentFactory(type_id='statchg',name='status-change-imaginary-mid-review',notify='[email protected]')

class StatusChangeSubmitTests(TestCase):
Expand Down
10 changes: 5 additions & 5 deletions ietf/doc/tests_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ def setUp(self):
self.normative, self.informative, self.unknown = WgRfcFactory.create_batch(3)
for relationship in ['refnorm', 'refinfo', 'refunk', 'refold']:
self.doc.relateddocument_set.create(
target=WgRfcFactory().docalias.first(),
target=WgRfcFactory(),
relationship_id=relationship,
)
self.updated = WgRfcFactory() # related document that should be left alone
self.doc.relateddocument_set.create(target=self.updated.docalias.first(), relationship_id='updates')
self.doc.relateddocument_set.create(target=self.updated, relationship_id='updates')
self.assertCountEqual(self.doc.relateddocument_set.values_list('relationship__slug', flat=True),
['refnorm', 'refinfo', 'refold', 'refunk', 'updates'],
'Test conditions set up incorrectly: wrong prior document relationships')
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_xml(self, mock_init, mock_get_refs):
(self.normative.canonical_name(), 'refnorm'),
(self.informative.canonical_name(), 'refinfo'),
(self.unknown.canonical_name(), 'refunk'),
(self.updated.docalias.first().name, 'updates'),
(self.updated.name, 'updates'),
]
)

Expand Down Expand Up @@ -420,7 +420,7 @@ def test_plaintext(self, mock_init, mock_get_refs):
(self.normative.canonical_name(), 'refnorm'),
(self.informative.canonical_name(), 'refinfo'),
(self.unknown.canonical_name(), 'refunk'),
(self.updated.docalias.first().name, 'updates'),
(self.updated.name, 'updates'),
]
)

Expand Down Expand Up @@ -452,6 +452,6 @@ def test_xml_and_plaintext(self, mock_init, mock_get_refs, mock_plaintext_init):
(self.normative.canonical_name(), 'refnorm'),
(self.informative.canonical_name(), 'refinfo'),
(self.unknown.canonical_name(), 'refunk'),
(self.updated.docalias.first().name, 'updates'),
(self.updated.name, 'updates'),
]
)
6 changes: 3 additions & 3 deletions ietf/doc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ietf.community.utils import docs_tracked_by_community_list

from ietf.doc.models import Document, DocHistory, State, DocumentAuthor, DocHistoryAuthor
from ietf.doc.models import DocAlias, RelatedDocument, RelatedDocHistory, BallotType, DocReminder
from ietf.doc.models import RelatedDocument, RelatedDocHistory, BallotType, DocReminder
from ietf.doc.models import DocEvent, ConsensusDocEvent, BallotDocEvent, IRSGBallotDocEvent, NewRevisionDocEvent, StateDocEvent
from ietf.doc.models import TelechatDocEvent, DocumentActionHolder, EditedAuthorsDocEvent
from ietf.name.models import DocReminderTypeName, DocRelationshipName
Expand Down Expand Up @@ -771,9 +771,9 @@ def rebuild_reference_relations(doc, filenames):
errors = []
unfound = set()
for ( ref, refType ) in refs.items():
refdoc = DocAlias.objects.filter(name=ref)
refdoc = Document.objects.filter(name=ref)
if not refdoc and re.match(r"^draft-.*-\d{2}$", ref):
refdoc = DocAlias.objects.filter(name=ref[:-3])
refdoc = Document.objects.filter(name=ref[:-3])
count = refdoc.count()
# As of Dec 2021, DocAlias has a unique constraint on the name field, so count > 1 should not occur
if count == 0:
Expand Down
2 changes: 1 addition & 1 deletion ietf/doc/views_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import debug # pyflakes:ignore

from ietf.doc.models import ( Document, DocAlias, RelatedDocument, State,
from ietf.doc.models import ( Document, RelatedDocument, State,
StateType, DocEvent, ConsensusDocEvent, TelechatDocEvent, WriteupDocEvent, StateDocEvent,
IanaExpertDocEvent, IESG_SUBSTATE_TAGS)
from ietf.doc.mails import ( email_pulled_from_rfc_queue, email_resurrect_requested,
Expand Down
7 changes: 3 additions & 4 deletions ietf/doc/views_status_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def clean_helper(form, formtype):

if not re.match(r'(?i)rfc\d{1,4}',key):
errors.append(key+" is not a valid RFC - please use the form RFCn\n")
elif not DocAlias.objects.filter(name=key):
elif not Document.objects.filter(name=key):
errors.append(key+" does not exist\n")

if new_relations[key] not in STATUSCHANGE_RELATIONS:
Expand Down Expand Up @@ -564,10 +564,9 @@ def start_rfc_status_change(request, name=None):
DocAlias.objects.create( name= 'status-change-'+form.cleaned_data['document_name']).docs.add(status_change)

for key in form.cleaned_data['relations']:
status_change.relateddocument_set.create(target=DocAlias.objects.get(name=key),
status_change.relateddocument_set.create(target=Document.objects.get(name=key),
relationship_id=form.cleaned_data['relations'][key])


tc_date = form.cleaned_data['telechat_date']
if tc_date:
update_telechat(request, status_change, login, tc_date)
Expand Down Expand Up @@ -609,7 +608,7 @@ def edit_relations(request, name):
new_relations=form.cleaned_data['relations']
status_change.relateddocument_set.filter(relationship__slug__in=STATUSCHANGE_RELATIONS).delete()
for key in new_relations:
status_change.relateddocument_set.create(target=DocAlias.objects.get(name=key),
status_change.relateddocument_set.create(target=Document.objects.get(name=key),
relationship_id=new_relations[key])
c = DocEvent(type="added_comment", doc=status_change, rev=status_change.rev, by=login)
c.desc = "Affected RFC list changed.\nOLD:"
Expand Down
4 changes: 2 additions & 2 deletions ietf/group/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def setUp(self):
a = WgDraftFactory()
b = WgDraftFactory()
RelatedDocument.objects.create(
source=a, target=b.docalias.first(), relationship_id="refnorm"
source=a, target=b, relationship_id="refnorm"
)

def test_group_stats(self):
Expand All @@ -95,7 +95,7 @@ def setUp(self):
a = WgDraftFactory()
b = WgDraftFactory()
RelatedDocument.objects.create(
source=a, target=b.docalias.first(), relationship_id="refnorm"
source=a, target=b, relationship_id="refnorm"
)

def test_group_document_dependencies(self):
Expand Down
2 changes: 1 addition & 1 deletion ietf/stats/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_document_stats(self):
DocAlias.objects.create(name=referencing_draft.name).docs.add(referencing_draft)
RelatedDocument.objects.create(
source=referencing_draft,
target=draft.docalias.first(),
target=draft,
relationship=DocRelationshipName.objects.get(slug="refinfo")
)
NewRevisionDocEvent.objects.create(
Expand Down
2 changes: 1 addition & 1 deletion ietf/submit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def submit_new_wg(self, formats):
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(replaced_alias.pk), str(sug_replaced_alias.pk)])
replaces=[str(draft.pk), str(sug_replaced_draft.pk)])

self.assertEqual(r.status_code, 302)
status_url = r["Location"]
Expand Down

0 comments on commit 8ff1441

Please sign in to comment.