Skip to content

Commit a064e28

Browse files
committed
Factoryalized the rest of ietf.doc.tests. Created draft type specific factories. Commit ready for merge.
- Legacy-Id: 15217
1 parent 984806d commit a064e28

2 files changed

Lines changed: 120 additions & 70 deletions

File tree

ietf/doc/factories.py

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import debug # pyflakes:ignore
12
import factory
23

34
from ietf.doc.models import Document, DocEvent, NewRevisionDocEvent, DocAlias, State, DocumentAuthor
@@ -57,14 +58,71 @@ def _after_postgeneration(cls, obj, create, results=None):
5758
obj._has_an_event_so_saving_is_allowed = True
5859
obj.save()
5960

61+
#TODO remove this - rename BaseDocumentFactory to DocumentFactory
6062
class DocumentFactory(BaseDocumentFactory):
6163

6264
type_id = 'draft'
63-
# TODO : If more than one document is created in a test with this factory,
64-
# and group isn't explicitly specified, this will violate the assumption
65-
# that there is only one group of type 'individ'
66-
# Update : this, along with the django_get_or_create in GroupFactory is better, but replace this with traits and a post_generation hoook.
67-
group = factory.SubFactory('ietf.group.factories.GroupFactory',type_id='individ',acronym='none')
65+
group = factory.SubFactory('ietf.group.factories.GroupFactory',acronym='none')
66+
67+
68+
class IndividualDraftFactory(BaseDocumentFactory):
69+
70+
type_id = 'draft'
71+
group = factory.SubFactory('ietf.group.factories.GroupFactory',acronym='none')
72+
73+
@factory.post_generation
74+
def states(obj, create, extracted, **kwargs):
75+
if not create:
76+
return
77+
if extracted:
78+
for (state_type_id,state_slug) in extracted:
79+
obj.set_state(State.objects.get(type_id=state_type_id,slug=state_slug))
80+
else:
81+
obj.set_state(State.objects.get(type_id='draft',slug='active'))
82+
83+
class IndividualRfcFactory(IndividualDraftFactory):
84+
85+
alias2 = factory.RelatedFactory('ietf.doc.factories.DocAliasFactory','document',name=factory.Sequence(lambda n: 'rfc%04d'%(n+1000)))
86+
87+
@factory.post_generation
88+
def states(obj, create, extracted, **kwargs):
89+
if not create:
90+
return
91+
if extracted:
92+
for (state_type_id,state_slug) in extracted:
93+
obj.set_state(State.objects.get(type_id=state_type_id,slug=state_slug))
94+
else:
95+
obj.set_state(State.objects.get(type_id='draft',slug='rfc'))
96+
97+
class WgDraftFactory(BaseDocumentFactory):
98+
99+
type_id = 'draft'
100+
group = factory.SubFactory('ietf.group.factories.GroupFactory',type_id='wg')
101+
102+
@factory.post_generation
103+
def states(obj, create, extracted, **kwargs):
104+
if not create:
105+
return
106+
if extracted:
107+
for (state_type_id,state_slug) in extracted:
108+
obj.set_state(State.objects.get(type_id=state_type_id,slug=state_slug))
109+
else:
110+
obj.set_state(State.objects.get(type_id='draft',slug='active'))
111+
obj.set_state(State.objects.get(type_id='draft-stream-ietf',slug='wg-doc'))
112+
113+
class WgRfcFactory(WgDraftFactory):
114+
115+
alias2 = factory.RelatedFactory('ietf.doc.factories.DocAliasFactory','document',name=factory.Sequence(lambda n: 'rfc%04d'%(n+1000)))
116+
117+
@factory.post_generation
118+
def states(obj, create, extracted, **kwargs):
119+
if not create:
120+
return
121+
if extracted:
122+
for (state_type_id,state_slug) in extracted:
123+
obj.set_state(State.objects.get(type_id=state_type_id,slug=state_slug))
124+
else:
125+
obj.set_state(State.objects.get(type_id='draft',slug='rfc'))
68126

69127
class CharterFactory(BaseDocumentFactory):
70128

0 commit comments

Comments
 (0)