|
| 1 | +import factory |
| 2 | +import random |
| 3 | +import datetime |
| 4 | + |
| 5 | +from django.db.models import Max |
| 6 | + |
| 7 | +from ietf.meeting.models import Meeting, Session, Schedule, TimeSlot |
| 8 | +from ietf.group.factories import GroupFactory |
| 9 | +from ietf.person.factories import PersonFactory |
| 10 | + |
| 11 | +class MeetingFactory(factory.DjangoModelFactory): |
| 12 | + class Meta: |
| 13 | + model = Meeting |
| 14 | + |
| 15 | + type_id = factory.Iterator(['ietf','interim']) |
| 16 | + date = datetime.date(2010,1,1)+datetime.timedelta(days=random.randint(0,3652)) |
| 17 | + city = factory.Faker('city') |
| 18 | + country = factory.Faker('country_code') |
| 19 | + time_zone = factory.Faker('timezone') |
| 20 | + idsubmit_cutoff_day_offset_00 = 13 |
| 21 | + idsubmit_cutoff_day_offset_01 = 13 |
| 22 | + idsubmit_cutoff_time_utc = datetime.timedelta(0, 86399) |
| 23 | + idsubmit_cutoff_warning_days = 21 |
| 24 | + venue_name = factory.Faker('sentence') |
| 25 | + venue_addr = factory.Faker('address') |
| 26 | + break_area = factory.Faker('sentence') |
| 27 | + reg_area = factory.Faker('sentence') |
| 28 | + |
| 29 | + @factory.lazy_attribute_sequence |
| 30 | + def number(self,n): |
| 31 | + if self.type_id == 'ietf': |
| 32 | + if Meeting.objects.filter(type='ietf').exists(): |
| 33 | + return '%02d'%(int(Meeting.objects.filter(type='ietf').aggregate(Max('number'))['number__max'])+1) |
| 34 | + else: |
| 35 | + return '%02d'%(n+80) |
| 36 | + else: |
| 37 | + return 'interim-%d-%s-%d'%(self.date.year,GroupFactory().acronym,n) |
| 38 | + |
| 39 | + @factory.post_generation |
| 40 | + def populate_agenda(self, create, extracted, **kwargs): |
| 41 | + ''' |
| 42 | + Create a default agenda, unless the factory is called |
| 43 | + with populate_agenda=False |
| 44 | + ''' |
| 45 | + if extracted is None: |
| 46 | + extracted = True |
| 47 | + if create and extracted: |
| 48 | + for x in range(3): |
| 49 | + TimeSlotFactory(meeting=self) |
| 50 | + self.agenda = ScheduleFactory(meeting=self) |
| 51 | + self.save() |
| 52 | + |
| 53 | + |
| 54 | +class SessionFactory(factory.DjangoModelFactory): |
| 55 | + class Meta: |
| 56 | + model = Session |
| 57 | + |
| 58 | + meeting = factory.SubFactory(MeetingFactory) |
| 59 | + type_id='session' |
| 60 | + group = factory.SubFactory(GroupFactory) |
| 61 | + requested_by = factory.SubFactory(PersonFactory) |
| 62 | + status_id='sched' |
| 63 | + |
| 64 | + @factory.post_generation |
| 65 | + def add_to_schedule(self, create, extracted, **kwargs): |
| 66 | + ''' |
| 67 | + Put this session in a timeslot unless the factory is called |
| 68 | + with add_to_schedule=False |
| 69 | + ''' |
| 70 | + if extracted is None: |
| 71 | + extracted = True |
| 72 | + if create and extracted: |
| 73 | + ts = self.meeting.timeslot_set.all() |
| 74 | + self.timeslotassignments.create(timeslot=ts[random.randrange(len(ts))],schedule=self.meeting.agenda) |
| 75 | + |
| 76 | +class ScheduleFactory(factory.DjangoModelFactory): |
| 77 | + class Meta: |
| 78 | + model = Schedule |
| 79 | + |
| 80 | + meeting = factory.SubFactory(MeetingFactory) |
| 81 | + name = factory.Faker('text',max_nb_chars=16) |
| 82 | + owner = factory.SubFactory(PersonFactory) |
| 83 | + |
| 84 | +class TimeSlotFactory(factory.DjangoModelFactory): |
| 85 | + class Meta: |
| 86 | + model = TimeSlot |
| 87 | + |
| 88 | + meeting = factory.SubFactory(MeetingFactory) |
| 89 | + type_id = 'session' |
| 90 | + |
| 91 | + @factory.lazy_attribute |
| 92 | + def time(self): |
| 93 | + return datetime.datetime.combine(self.meeting.date,datetime.time(11,0)) |
| 94 | + |
| 95 | + @factory.lazy_attribute |
| 96 | + def duration(self): |
| 97 | + return datetime.timedelta(minutes=30+random.randrange(9)*15) |
| 98 | + |
| 99 | + |
0 commit comments