Merged in [11656] from rjsparks@nostrum.com:
Enhanced factories to simplify test writing.
- Legacy-Id: 11682
Note: SVN reference [11656] has been migrated to Git commit 030ea1c939
This commit is contained in:
commit
34370c6e16
|
@ -1,7 +1,15 @@
|
|||
import factory
|
||||
|
||||
from ietf.doc.models import Document, DocEvent, NewRevisionDocEvent
|
||||
from ietf.person.factories import PersonFactory
|
||||
from ietf.doc.models import Document, DocEvent, NewRevisionDocEvent, DocAlias, State
|
||||
|
||||
def draft_name_generator(type_id,group,n):
|
||||
return '%s-%s-%s-%s%d'%(
|
||||
type_id,
|
||||
'bogusperson',
|
||||
group.acronym if group else 'netherwhere',
|
||||
'musings',
|
||||
n,
|
||||
)
|
||||
|
||||
class DocumentFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
|
@ -10,26 +18,47 @@ class DocumentFactory(factory.DjangoModelFactory):
|
|||
type_id = 'draft'
|
||||
title = factory.Faker('sentence',nb_words=6)
|
||||
rev = '00'
|
||||
group = None
|
||||
group = factory.SubFactory('ietf.group.factories.GroupFactory',type_id='individ')
|
||||
std_level_id = None
|
||||
intended_std_level_id = None
|
||||
|
||||
@factory.lazy_attribute_sequence
|
||||
def name(self, n):
|
||||
return '%s-%s-%s-%s%d'%(
|
||||
self.type_id,
|
||||
'bogusperson',
|
||||
self.group.acronym if self.group else 'netherwhere',
|
||||
'musings',
|
||||
n,
|
||||
)
|
||||
return draft_name_generator(self.type_id,self.group,n)
|
||||
|
||||
newrevisiondocevent = factory.RelatedFactory('ietf.doc.factories.NewRevisionDocEventFactory','doc')
|
||||
|
||||
alias = factory.RelatedFactory('ietf.doc.factories.DocAliasFactory','document')
|
||||
|
||||
@factory.post_generation
|
||||
def other_aliases(self, create, extracted, **kwargs):
|
||||
if create and extracted:
|
||||
for alias in extracted:
|
||||
self.docalias_set.create(name=alias)
|
||||
|
||||
@factory.post_generation
|
||||
def states(self, create, extracted, **kwargs):
|
||||
if create and extracted:
|
||||
for (state_type_id,state_slug) in extracted:
|
||||
self.set_state(State.objects.get(type_id=state_type_id,slug=state_slug))
|
||||
|
||||
class DocAliasFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = DocAlias
|
||||
|
||||
document = factory.SubFactory('ietf.doc.factories.DocumentFactory')
|
||||
|
||||
@factory.lazy_attribute
|
||||
def name(self):
|
||||
return self.document.name
|
||||
|
||||
|
||||
class DocEventFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = DocEvent
|
||||
|
||||
type = 'added_comment'
|
||||
by = factory.SubFactory(PersonFactory)
|
||||
by = factory.SubFactory('ietf.person.factories.PersonFactory')
|
||||
doc = factory.SubFactory(DocumentFactory)
|
||||
desc = factory.Faker('sentence',nb_words=6)
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ from django.core.urlresolvers import reverse as urlreverse
|
|||
from ietf.doc.models import ( Document, State, DocEvent, BallotDocEvent,
|
||||
BallotPositionDocEvent, LastCallDocEvent, WriteupDocEvent, TelechatDocEvent )
|
||||
from ietf.doc.factories import DocumentFactory
|
||||
from ietf.group.factories import GroupFactory
|
||||
from ietf.group.models import Group, Role
|
||||
from ietf.name.models import BallotPositionName
|
||||
from ietf.iesg.models import TelechatDate
|
||||
|
@ -719,13 +718,11 @@ class DeferUndeferTestCase(TestCase):
|
|||
class RegenerateLastCallTestCase(TestCase):
|
||||
|
||||
def test_regenerate_last_call(self):
|
||||
group = GroupFactory(type_id='individ')
|
||||
draft = DocumentFactory.create(stream_id='ietf',group=group)
|
||||
draft.docalias_set.create(name=draft.name) # factory should do this
|
||||
draft.set_state(State.objects.get(type='draft',slug='active'))
|
||||
draft.set_state(State.objects.get(type='draft-iesg',slug='pub-req'))
|
||||
draft.intended_std_level_id='ps'
|
||||
draft.save()
|
||||
draft = DocumentFactory.create(
|
||||
stream_id='ietf',
|
||||
states=[('draft','active'),('draft-iesg','pub-req')],
|
||||
intended_std_level_id='ps',
|
||||
)
|
||||
|
||||
url = urlreverse('doc_ballot_lastcall', kwargs=dict(name=draft.name))
|
||||
login_testing_unauthorized(self, "secretary", url)
|
||||
|
@ -739,15 +736,14 @@ class RegenerateLastCallTestCase(TestCase):
|
|||
self.assertTrue("Subject: Last Call" in lc_text)
|
||||
self.assertFalse("contains normative down" in lc_text)
|
||||
|
||||
rfc = DocumentFactory.create(stream_id='ise')
|
||||
rfc.docalias_set.create(name=rfc.name)
|
||||
rfc_alias = rfc.docalias_set.create(name='rfc6666')
|
||||
rfc.set_state(State.objects.get(type='draft',slug='rfc'))
|
||||
rfc.set_state(State.objects.get(type='draft-iesg',slug='pub'))
|
||||
rfc.std_level_id='inf'
|
||||
rfc.save()
|
||||
rfc = DocumentFactory.create(
|
||||
stream_id='ise',
|
||||
other_aliases=['rfc6666',],
|
||||
states=[('draft','rfc'),('draft-iesg','pub')],
|
||||
std_level_id='inf',
|
||||
)
|
||||
|
||||
draft.relateddocument_set.create(target=rfc_alias,relationship_id='refnorm')
|
||||
draft.relateddocument_set.create(target=rfc.docalias_set.get(name='rfc6666'),relationship_id='refnorm')
|
||||
|
||||
r = self.client.post(url, dict(regenerate_last_call_text="1"))
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
|
|
@ -14,7 +14,7 @@ class RoleFactory(factory.DjangoModelFactory):
|
|||
model = Role
|
||||
|
||||
group = factory.SubFactory(GroupFactory)
|
||||
person = factory.SubFactory('ietf.doc.factories.PersonFactory')
|
||||
person = factory.SubFactory('ietf.person.factories.PersonFactory')
|
||||
email = factory.LazyAttribute(lambda obj: obj.person.email())
|
||||
|
||||
class GroupEventFactory(factory.DjangoModelFactory):
|
||||
|
@ -22,6 +22,6 @@ class GroupEventFactory(factory.DjangoModelFactory):
|
|||
model = GroupEvent
|
||||
|
||||
group = factory.SubFactory(GroupFactory)
|
||||
by = factory.SubFactory('ietf.doc.factories.PersonFactory')
|
||||
by = factory.SubFactory('ietf.person.factories.PersonFactory')
|
||||
type = 'comment'
|
||||
desc = factory.Faker('paragraph')
|
||||
|
|
Loading…
Reference in a new issue