From 84d3c922985e6816006b04041e3b9222a46a4601 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Sat, 2 Jun 2018 13:39:39 +0000 Subject: [PATCH] more factoryization of ietf.doc.tests. Commit ready for merge. - Legacy-Id: 15205 --- ietf/doc/factories.py | 3 ++- ietf/doc/tests.py | 24 ++++++++++++++++++------ ietf/doc/tests_charter.py | 4 ++-- ietf/group/factories.py | 1 + 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ietf/doc/factories.py b/ietf/doc/factories.py index 0e51bbe42..07c0f5028 100644 --- a/ietf/doc/factories.py +++ b/ietf/doc/factories.py @@ -63,7 +63,8 @@ class DocumentFactory(BaseDocumentFactory): # TODO : If more than one document is created in a test with this factory, # and group isn't explicitly specified, this will violate the assumption # that there is only one group of type 'individ' - group = factory.SubFactory('ietf.group.factories.GroupFactory',type_id='individ') + # Update : this, along with the django_get_or_create in GroupFactory is better, but replace this with traits and a post_generation hoook. + group = factory.SubFactory('ietf.group.factories.GroupFactory',type_id='individ',acronym='none') class CharterFactory(BaseDocumentFactory): diff --git a/ietf/doc/tests.py b/ietf/doc/tests.py index 54064ce2f..73efaa969 100644 --- a/ietf/doc/tests.py +++ b/ietf/doc/tests.py @@ -28,7 +28,7 @@ from ietf.group.models import Group from ietf.group.factories import GroupFactory from ietf.meeting.models import Meeting, Session, SessionPresentation from ietf.meeting.factories import MeetingFactory, SessionFactory -from ietf.meeting.test_data import make_meeting_test_data +#from ietf.meeting.test_data import make_meeting_test_data from ietf.name.models import SessionStatusName from ietf.person.models import Person from ietf.person.factories import PersonFactory @@ -610,8 +610,16 @@ Man Expires September 22, 2015 [Page 3] self.assertEqual(r.status_code, 404) def test_document_primary_and_history_views(self): - make_test_data() - make_meeting_test_data() + #make_test_data() + #make_meeting_test_data() + DocumentFactory(name='draft-imaginary-independent-submission') + ConflictReviewFactory(name='conflict-review-imaginary-irtf-submission') + CharterFactory(name='charter-ietf-mars') + DocumentFactory(type_id='agenda',name='agenda-42-mars') + DocumentFactory(type_id='minutes',name='minutes-42-mars') + DocumentFactory(type_id='slides',name='slides-42-mars-1-active') + statchg = DocumentFactory(type_id='statchg',name='status-change-imaginary-mid-review') + statchg.set_state(State.objects.get(type_id='statchg',slug='adrev')) # Ensure primary views of both current and historic versions of documents works for docname in ["draft-imaginary-independent-submission", @@ -684,7 +692,7 @@ class DocTestCase(TestCase): self.assertEqual(r.status_code, 200) def test_document_ballot(self): - doc = make_test_data() + doc = DocumentFactory() ad = Person.objects.get(user__username="ad") ballot = create_ballot_if_not_open(None, doc, ad, 'approve') assert ballot == doc.active_ballot() @@ -728,7 +736,9 @@ class DocTestCase(TestCase): def test_document_ballot_needed_positions(self): # draft - doc = make_test_data() + doc = DocumentFactory(intended_std_level_id='ps') + doc.set_state(State.objects.get(type_id='draft-iesg',slug='iesg-eva')) + doc.set_state(State.objects.get(type_id='draft',slug='active')) ad = Person.objects.get(user__username="ad") create_ballot_if_not_open(None, doc, ad, 'approve') @@ -739,7 +749,9 @@ class DocTestCase(TestCase): self.assertFalse('more YES or NO' in unicontent(r)) # status change - doc = Document.objects.get(name='status-change-imaginary-mid-review') + DocumentFactory().docalias_set.create(name='rfc9998') + DocumentFactory().docalias_set.create(name='rfc9999') + doc = DocumentFactory(type_id='statchg',name='status-change-imaginary-mid-review') iesgeval_pk = str(State.objects.get(slug='iesgeval',type__slug='statchg').pk) self.client.login(username='ad', password='ad+password') r = self.client.post(urlreverse('ietf.doc.views_status_change.change_state',kwargs=dict(name=doc.name)),dict(new_state=iesgeval_pk)) diff --git a/ietf/doc/tests_charter.py b/ietf/doc/tests_charter.py index 444912d92..2e8e2fb5b 100644 --- a/ietf/doc/tests_charter.py +++ b/ietf/doc/tests_charter.py @@ -10,7 +10,7 @@ from django.urls import reverse as urlreverse import debug # pyflakes:ignore -from ietf.doc.factories import DocumentFactory, CharterFactory +from ietf.doc.factories import CharterFactory from ietf.doc.models import ( Document, State, BallotDocEvent, BallotType, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent ) from ietf.doc.utils_charter import ( next_revision, default_review_text, default_action_text, @@ -697,6 +697,6 @@ class EditCharterTests(TestCase): def test_chartering_from_bof(self): ad_role = RoleFactory(group__type_id='area',name_id='ad') - charter = DocumentFactory(type_id='charter',group__type_id='wg',group__state_id='bof',group__parent=ad_role.group) + charter = CharterFactory(group__type_id='wg',group__state_id='bof',group__parent=ad_role.group) e1,_ = default_review_text(charter.group, charter, Person.objects.get(name="(System)")) self.assertTrue('A new IETF WG has been proposed' in e1.text) diff --git a/ietf/group/factories.py b/ietf/group/factories.py index 24bf2581e..27338e50d 100644 --- a/ietf/group/factories.py +++ b/ietf/group/factories.py @@ -7,6 +7,7 @@ from ietf.review.factories import ReviewTeamSettingsFactory class GroupFactory(factory.DjangoModelFactory): class Meta: model = Group + django_get_or_create = ('acronym',) name = factory.Faker('sentence',nb_words=6) acronym = factory.Sequence(lambda n: 'acronym%d' %n)