|
| 1 | +import debug # pyflakes:ignore |
1 | 2 | import factory |
2 | 3 |
|
3 | 4 | from ietf.doc.models import Document, DocEvent, NewRevisionDocEvent, DocAlias, State, DocumentAuthor |
@@ -57,14 +58,71 @@ def _after_postgeneration(cls, obj, create, results=None): |
57 | 58 | obj._has_an_event_so_saving_is_allowed = True |
58 | 59 | obj.save() |
59 | 60 |
|
| 61 | +#TODO remove this - rename BaseDocumentFactory to DocumentFactory |
60 | 62 | class DocumentFactory(BaseDocumentFactory): |
61 | 63 |
|
62 | 64 | 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')) |
68 | 126 |
|
69 | 127 | class CharterFactory(BaseDocumentFactory): |
70 | 128 |
|
|
0 commit comments