From db12f2b948cf0d5d53c822716977ba6d65082e99 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Wed, 19 Jun 2019 12:57:52 +0000 Subject: [PATCH] Fixed some name versus pk issues lingering after the Document/DocAlias primary key refactoring. Fixes issue #2729. - Legacy-Id: 16288 --- ietf/community/tests.py | 2 +- ietf/doc/fields.py | 13 +++++++------ ietf/doc/tests_downref.py | 37 +++++++++++++++++++------------------ ietf/doc/tests_draft.py | 6 +++--- ietf/group/tests_info.py | 23 +++++++++++++---------- ietf/ietfauth/tests.py | 2 +- ietf/ipr/fields.py | 11 ++++++++++- ietf/ipr/tests.py | 18 +++++++++--------- ietf/liaisons/fields.py | 11 ++++++++++- ietf/meeting/tests_views.py | 4 ++-- ietf/submit/tests.py | 13 ++++++------- 11 files changed, 81 insertions(+), 59 deletions(-) diff --git a/ietf/community/tests.py b/ietf/community/tests.py index afc9e5122..b730697c3 100644 --- a/ietf/community/tests.py +++ b/ietf/community/tests.py @@ -110,7 +110,7 @@ class CommunityListTests(TestCase): self.assertEqual(r.status_code, 200) # add document - r = self.client.post(url, { "action": "add_documents", "documents": draft.name }) + r = self.client.post(url, { "action": "add_documents", "documents": draft.pk }) self.assertEqual(r.status_code, 302) clist = CommunityList.objects.get(user__username="plain") self.assertTrue(clist.added_docs.filter(pk=draft.pk)) diff --git a/ietf/doc/fields.py b/ietf/doc/fields.py index 57d4af654..a797917dc 100644 --- a/ietf/doc/fields.py +++ b/ietf/doc/fields.py @@ -57,6 +57,7 @@ class SearchableDocumentsField(forms.CharField): value = str(value) if isinstance(value, basestring): items = self.parse_select2_value(value) + # accept both names and pks here names = [ i for i in items if not i.isdigit() ] ids = [ i for i in items if i.isdigit() ] value = self.model.objects.filter(Q(name__in=names)|Q(id__in=ids)) @@ -82,14 +83,14 @@ class SearchableDocumentsField(forms.CharField): def clean(self, value): value = super(SearchableDocumentsField, self).clean(value) - names = self.parse_select2_value(value) + pks = self.parse_select2_value(value) - objs = self.model.objects.filter(name__in=names) + objs = self.model.objects.filter(pk__in=pks) - found_names = [str(o.name) for o in objs] - failed_names = [x for x in names if x not in found_names] - if failed_names: - raise forms.ValidationError(u"Could not recognize the following documents: {names}. You can only input documents already registered in the Datatracker.".format(names=", ".join(failed_names))) + found_pks = [ str(o.pk) for o in objs ] + failed_pks = [ x for x in pks if x not in found_pks ] + if failed_pks: + raise forms.ValidationError(u"Could not recognize the following documents: {names}. You can only input documents already registered in the Datatracker.".format(names=", ".join(failed_pks))) if self.max_entries != None and len(objs) > self.max_entries: raise forms.ValidationError(u"You can select at most %s entries." % self.max_entries) diff --git a/ietf/doc/tests_downref.py b/ietf/doc/tests_downref.py index a567f90e5..d0f4b43fc 100644 --- a/ietf/doc/tests_downref.py +++ b/ietf/doc/tests_downref.py @@ -9,7 +9,7 @@ from pyquery import PyQuery import debug # pyflakes:ignore from ietf.doc.factories import WgDraftFactory, WgRfcFactory -from ietf.doc.models import Document, DocAlias, RelatedDocument, State +from ietf.doc.models import RelatedDocument, State from ietf.person.factories import PersonFactory from ietf.utils.test_utils import TestCase from ietf.utils.test_utils import login_testing_unauthorized, unicontent @@ -18,10 +18,13 @@ class Downref(TestCase): def setUp(self): PersonFactory(name='Plain Man',user__username='plain') - WgDraftFactory(name='draft-ietf-mars-test') - doc = WgDraftFactory(name='draft-ietf-mars-approved-document',states=[('draft-iesg','rfcqueue')]) - rfc = WgRfcFactory(alias2__name='rfc9998') - RelatedDocument.objects.create(source=doc, target=rfc.docalias.get(name='rfc9998'),relationship_id='downref-approval') + self.draft = WgDraftFactory(name='draft-ietf-mars-test') + 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.rfcalias = self.rfc.docalias.get(name='rfc9998') + RelatedDocument.objects.create(source=self.doc, target=self.rfcalias, relationship_id='downref-approval') def test_downref_registry(self): url = urlreverse('ietf.doc.views_downref.downref_registry') @@ -71,7 +74,7 @@ class Downref(TestCase): self.assertTrue('Save downref' in content) # error - already in the downref registry - r = self.client.post(url, dict(rfc='rfc9998', drafts=('draft-ietf-mars-approved-document', ))) + r = self.client.post(url, dict(rfc=self.rfcalias.pk, drafts=(self.doc.pk, ))) self.assertEqual(r.status_code, 200) content = unicontent(r) self.assertTrue('Downref is already in the registry' in content) @@ -79,40 +82,38 @@ class Downref(TestCase): # error - source is not in an approved state r = self.client.get(url) self.assertEqual(r.status_code, 200) - r = self.client.post(url, dict(rfc='rfc9998', drafts=('draft-ietf-mars-test', ))) + r = self.client.post(url, dict(rfc=self.rfcalias.pk, drafts=(self.draft.pk, ))) self.assertEqual(r.status_code, 200) content = unicontent(r) self.assertTrue('Draft is not yet approved' in content) # error - the target is not a normative reference of the source - draft = Document.objects.get(name="draft-ietf-mars-test") - draft.set_state(State.objects.get(used=True, type="draft-iesg", slug="pub")) + self.draft.set_state(State.objects.get(used=True, type="draft-iesg", slug="pub")) r = self.client.get(url) self.assertEqual(r.status_code, 200) - r = self.client.post(url, dict(rfc='rfc9998', drafts=('draft-ietf-mars-test', ))) + r = self.client.post(url, dict(rfc=self.rfcalias.pk, drafts=(self.draft.pk, ))) self.assertEqual(r.status_code, 200) content = unicontent(r) self.assertTrue('There does not seem to be a normative reference to RFC' in content) self.assertTrue('Save downref anyway' in content) # normal - approve the document so the downref is now okay - rfc = DocAlias.objects.get(name="rfc9998") - RelatedDocument.objects.create(source=draft, target=rfc, relationship_id='refnorm') - draft_de_count_before = draft.docevent_set.count() - rfc_de_count_before = rfc.document.docevent_set.count() + RelatedDocument.objects.create(source=self.draft, target=self.rfcalias, relationship_id='refnorm') + draft_de_count_before = self.draft.docevent_set.count() + rfc_de_count_before = self.rfc.docevent_set.count() r = self.client.get(url) self.assertEqual(r.status_code, 200) - r = self.client.post(url, dict(rfc='rfc9998', drafts=('draft-ietf-mars-test', ))) + r = self.client.post(url, dict(rfc=self.rfcalias.pk, drafts=(self.draft.pk, ))) self.assertEqual(r.status_code, 302) newurl = urlreverse('ietf.doc.views_downref.downref_registry') r = self.client.get(newurl) self.assertEqual(r.status_code, 200) content = unicontent(r) self.assertTrue('