def setUpBeforeMigration(self, apps): User = apps.get_model('users', 'User') Group = apps.get_model('groups', 'Group') Place = apps.get_model('places', 'Place') PickupDateSeries = apps.get_model('places', 'PickupDateSeries') PickupDate = apps.get_model('places', 'PickupDate') Feedback = apps.get_model('places', 'Feedback') self.email = faker.email() self.now = datetime.datetime.now(tz=pytz.utc) self.date = faker.date_time_between(start_date='now', end_date='+24h', tzinfo=pytz.utc) self.group_name = 'Group ' + faker.name() self.place_name = 'Place ' + faker.name() user = User.objects.create(email=self.email, display_name='Peter') group = Group.objects.create(name=self.group_name) place = Place.objects.create(name=self.place_name, group=group) pickup_date_series = PickupDateSeries.objects.create( place=place, start_date=self.now) pickup_date = PickupDate.objects.create(series=pickup_date_series, place=place, date=self.date) pickup_date.collectors.add(user) Feedback.objects.create(given_by=user, about=pickup_date)
def create_done_pickup(place, user_id): pickup = PickupDate.objects.create( date=to_range(faker.date_time_between(start_date='-9d', end_date='-1d', tzinfo=pytz.utc), minutes=30), place_id=place, max_collectors=10, ) pickup.add_collector(User.objects.get(pk=user_id)) print('created done pickup: ', pickup) return pickup
def create_done_activity(place, user_id, activity_type): activity = Activity.objects.create( activity_type=activity_type, date=to_range(faker.date_time_between(start_date='-9d', end_date='-1d', tzinfo=pytz.utc), minutes=30), place_id=place, max_participants=10, ) activity.add_participant(User.objects.get(pk=user_id)) print('created done activity: ', activity) return activity
def setUpBeforeMigration(self, apps): Group = apps.get_model('groups', 'Group') Place = apps.get_model('places', 'Place') PickupDateSeries = apps.get_model('pickups', 'PickupDateSeries') PickupDate = apps.get_model('pickups', 'PickupDate') History = apps.get_model('history', 'History') # upcoming pickup is moved to a later date date1 = faker.date_time_between(start_date='+1h', end_date='+24h', tzinfo=pytz.utc) date2 = faker.date_time_between(start_date='+24h', end_date='+48h', tzinfo=pytz.utc) group = Group.objects.create(name=faker.name()) place = Place.objects.create(name=faker.name(), group=group) pickup_date_series = PickupDateSeries.objects.create( place=place, start_date=timezone.now()) pickup_date = PickupDate.objects.create(series=pickup_date_series, place=place, date=date2, is_date_changed=True) # PICKUP_MODIFY history entry History.objects.create(typus=8, group=group, before={ 'id': pickup_date.id, 'is_date_changed': False, 'date': date1.isoformat() }, after={'is_date_changed': True}) # past moved pickup PickupDate.objects.create(series=pickup_date_series, place=place, date=timezone.now() - relativedelta(days=1), is_date_changed=True)
def make_series(place): response = c.post( '/api/pickup-date-series/', { 'start_date': faker.date_time_between( start_date='now', end_date='+24h', tzinfo=pytz.utc), 'rule': 'FREQ=WEEKLY;BYDAY=MO,TU,SA', 'max_collectors': 10, 'place': place }) if response.status_code != 201: raise Exception('could not make series', place, response.data) data = response.data print('created series: ', data) return data
def make_pickup(place): date = to_range( faker.date_time_between(start_date='+2d', end_date='+7d', tzinfo=pytz.utc)) response = c.post( '/api/pickup-dates/', { 'date': date.as_list(), 'place': place, 'max_collectors': 10 }, format='json', ) if response.status_code != 201: raise Exception('could not make pickup', response.data) data = response.data p = PickupDate.objects.get(pk=data['id']) print('created pickup: ', data, p.date) return data
def make_activity(place, activity_type): date = to_range( faker.date_time_between(start_date='+2d', end_date='+7d', tzinfo=pytz.utc)) response = c.post( '/api/activities/', { 'activity_type': activity_type.id, 'date': date.as_list(), 'place': place, 'max_participants': 10 }, format='json', ) if response.status_code != 201: raise Exception('could not make activity', response.data) data = response.data p = Activity.objects.get(pk=data['id']) print('created activity: ', data, p.date) return data