def setUp(self): school = School(name='testschool') school.save() # country = Country(name='testcountry') # country.save() child = Child(first_name='mary', surname='jones', sex='f', school=school) child.save() contributor1 = Contributor(first_name='john', surname='doe', aard_van_de_schenker='np', street='some street', street_number=4, zip_code=2010, city='city', payment_frequency='every month', language='nl') contributor1.save() contributor2 = Contributor(first_name='marie', surname='evers', aard_van_de_schenker='np', street='some street', street_number=4, zip_code=2010, city='city', payment_frequency='every 3 months', language='nl') contributor2.save() contributor3 = Contributor(first_name='havent', surname='peeyd', aard_van_de_schenker='np', street='some street', street_number=4, zip_code=2010, city='city', payment_frequency='every 3 months', language='nl') contributor3.save() payments = [ {'amount': 42.4, 'contributor': contributor1, 'child': child, 'date': date(2014, 2, 20), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 42.4, 'contributor': contributor1, 'child': child, 'date': date(2014, 3, 20), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 42.4, 'contributor': contributor1, 'child': child, 'date': date(2014, 1, 20), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 42.4, 'contributor': contributor2, 'child': child, 'date': date(2014, 1, 14), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 42.4, 'contributor': contributor2, 'child': child, 'date': date(2014, 4, 15), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 42.4, 'contributor': contributor2, 'child': child, 'date': date(2014, 7, 16), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 42.4, 'contributor': contributor2, 'child': child, 'date': date(2014, 10, 17), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 42.4, 'contributor': contributor3, 'child': child, 'date': date(2014, 10, 17), 'entitled': 'entitled', 'ptype': 'recurrent'}, ] for p in payments: payment = Payment(**p) payment.save()
def setUp(self): """ This fixture data set includes: contributor1: pays every month and therefor, should not be included in reminders report, although his next expected payment is in the near future. contributor2: pays every 3 months, and hence should show up in the overdue report. contributor3: pays every year and hence should show up in the reminders report. contributor4: pays sporadic, and hence should not be included in one of the reports """ print 'installing fixture data' self.reference_date = date(2015, 11, 7) country = Country(name='Belgium', code=150) country.save() school = School(name='testschool') school.save() child = Child(first_name='mary', surname='jones', sex='f', school=school) child.save() self.contributor1 = Contributor(first_name='john', surname='doe', aard_van_de_schenker='np', street='some street', street_number=4, zip_code=2010, city='city', country=country, payment_frequency='every month', language='nl') self.contributor1.save() self.contributor2 = Contributor(first_name='marie', surname='evers', aard_van_de_schenker='np', street='some street', street_number=4, zip_code=2010, city='city', country=country, payment_frequency='every 3 months', language='nl') self.contributor2.save() self.contributor3 = Contributor(first_name='harvey', surname='jones', aard_van_de_schenker='np', street='some street', street_number=4, zip_code=2010, city='city', country=country, payment_frequency='every year', language='nl') self.contributor3.save() self.contributor4 = Contributor(first_name='jeff', surname='buckley', aard_van_de_schenker='np', street='some street', street_number=4, zip_code=2010, city='city', country=country, payment_frequency='sporadic', language='nl') self.contributor4.save() payments = [ {'amount': 45, 'contributor': self.contributor1, 'child': child, 'date': date(2015, 10, 1), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 45, 'contributor': self.contributor1, 'child': child, 'date': date(2015, 12, 4), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 45, 'contributor': self.contributor2, 'child': child, 'date': date(2015, 8, 15), 'expected_date': date(2015, 8, 1), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 42.4, 'contributor': self.contributor3, 'child': child, 'date': date(2014, 12, 10), 'expected_date': date(2014, 11, 21), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 30, 'contributor': self.contributor4, 'child': child, 'date': date(2014, 12, 1), 'entitled': 'entitled', 'ptype': 'recurrent'}, ] for p in payments: payment = Payment(**p) payment.save()
def _load_children(self): """ LOAD CHILDREN :return: Nothing. Happens in place """ self.stdout.write('\nloading children') self.children_data['sex'] = self.children_data['sex'].str.lower() self.children_data['sex'].fillna('m', inplace=True) # set them all to 'male'. This can be cleaned up later self.children_lookup = {} failing_children = {} for child_data in self.children_data.to_dict(orient='records'): self.stdout.write('.', ending="") self.stdout.flush() child = Child(**child_data) try: child.full_clean() child.save() self.children_lookup[child.id] = child except ValidationError as e: failing_children[str(child)] = e if failing_children: raise CommandError('Children failed validation:\n{0}'.format(pprint.pformat(failing_children, indent=4)))
def create_fixture(): country = Country(name='Belgium', code=150) country.save() school = School(name='testschool') school.save() child = Child(first_name='mary', surname='jones', sex='f', school=school) child.save() contributor = Contributor(first_name='john', surname='doe', aard_van_de_schenker='np', street='some street', street_number=4, zip_code=2010, city='city', country=country, payment_frequency='every month', language='nl') contributor.save() payments = [ {'amount': 48, 'contributor': contributor, 'child': child, 'date': date(2015, 10, 1), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 49, 'contributor': contributor, 'child': child, 'date': date(2015, 12, 4), 'entitled': 'entitled', 'ptype': 'recurrent'}, {'amount': 49.5, 'contributor': contributor, 'child': child, 'date': date(2015, 12, 16), 'entitled': 'entitled', 'ptype': 'single'} ] for p in payments: payment = Payment(**p) payment.save()