|
7 | 7 | import datetime |
8 | 8 |
|
9 | 9 | from django.core.files.base import ContentFile |
| 10 | +from django.db.models import Q |
10 | 11 |
|
11 | | -from ietf.meeting.models import Meeting, Session, SchedulingEvent, Schedule, TimeSlot, SessionPresentation, FloorPlan, Room, SlideSubmission |
12 | | -from ietf.name.models import ConstraintName, SessionStatusName |
| 12 | +from ietf.meeting.models import ( Meeting, Session, SchedulingEvent, Schedule, |
| 13 | + TimeSlot, SessionPresentation, FloorPlan, Room, SlideSubmission, Constraint) |
| 14 | +from ietf.name.models import ConstraintName, SessionStatusName, TimerangeName |
13 | 15 | from ietf.group.factories import GroupFactory |
14 | 16 | from ietf.person.factories import PersonFactory |
15 | 17 |
|
@@ -100,6 +102,7 @@ class Meta: |
100 | 102 | meeting = factory.SubFactory(MeetingFactory) |
101 | 103 | type_id='regular' |
102 | 104 | group = factory.SubFactory(GroupFactory) |
| 105 | + requested_duration = datetime.timedelta(hours=1) |
103 | 106 |
|
104 | 107 | @factory.post_generation |
105 | 108 | def status_id(obj, create, extracted, **kwargs): |
@@ -220,3 +223,28 @@ class Meta: |
220 | 223 | make_file = factory.PostGeneration( |
221 | 224 | lambda obj, create, extracted, **kwargs: open(obj.staged_filepath(),'a').close() |
222 | 225 | ) |
| 226 | + |
| 227 | +class ConstraintFactory(factory.django.DjangoModelFactory): |
| 228 | + class Meta: |
| 229 | + model = Constraint |
| 230 | + |
| 231 | + meeting = factory.SubFactory(MeetingFactory) |
| 232 | + source = factory.SubFactory(GroupFactory) |
| 233 | + target = factory.SubFactory(GroupFactory) |
| 234 | + person = factory.SubFactory(PersonFactory) |
| 235 | + time_relation = factory.Iterator(Constraint.TIME_RELATION_CHOICES) |
| 236 | + |
| 237 | + @factory.lazy_attribute |
| 238 | + def name(obj): |
| 239 | + constraint_list = list(ConstraintName.objects.filter( |
| 240 | + Q(slug__in=['bethere','timerange','time_relation','wg_adjacent']) |
| 241 | + | Q(meeting=obj.meeting) |
| 242 | + )) |
| 243 | + return random.choice(constraint_list) |
| 244 | + |
| 245 | + @factory.post_generation |
| 246 | + def timeranges(self, create, extracted, **kwargs): |
| 247 | + if create: |
| 248 | + if extracted: |
| 249 | + for tr in TimerangeName.objects.filter(slug__in=extracted): |
| 250 | + self.timeranges.add(tr) |
0 commit comments