def test_update_fees(self): '''Fees should be calculated when a School is created/updated.''' b, i, a = 3, 5, 7 school = TestSchools.new_school( beginner_delegates=b, intermediate_delegates=i, advanced_delegates=a, ) conference = Conference.get_current() registration_fee = conference.registration_fee delegate_fee = conference.delegate_fee self.assertEquals( school.fees_owed, registration_fee + delegate_fee * (b + i + a), ) b2, i2, a2 = 5, 10, 15 school.beginner_delegates = b2 school.intermediate_delegates = i2 school.advanced_delegates = a2 school.save() self.assertEquals( school.fees_owed, registration_fee + delegate_fee * (b2 + i2 + a2), )
def test_update_fees(self): '''Fees should be calculated when a Registration is created/updated.''' b, i, a = 3, 5, 7 registration = models.new_registration( num_beginner_delegates=b, num_intermediate_delegates=i, num_advanced_delegates=a, ) conference = Conference.get_current() delegate_fee = conference.delegate_fee self.assertEquals( registration.delegate_fees_owed, delegate_fee * (b + i + a), ) b2, i2, a2 = 5, 10, 15 registration.num_beginner_delegates = b2 registration.num_intermediate_delegates = i2 registration.num_advanced_delegates = a2 registration.save() self.assertEquals( registration.delegate_fees_owed, delegate_fee * (b2 + i2 + a2), )
def test_uniqueness(self): '''Is defined uniquely by its school and conference.''' s = models.new_school() c = Conference.get_current() r1 = models.new_registration(school=s, conference=c) with self.assertRaises(IntegrityError): r2 = models.new_registration(school=s, conference=c)
def test_update_fees(self): '''Fees should be calculated when a School is created/updated.''' b, i, a = 3, 5, 7 school = models.new_school( beginner_delegates=b, intermediate_delegates=i, advanced_delegates=a, ) conference = Conference.get_current() registration_fee = conference.registration_fee delegate_fee = conference.delegate_fee self.assertEquals( school.fees_owed, registration_fee + delegate_fee * (b + i + a), ) b2, i2, a2 = 5, 10, 15 school.beginner_delegates = b2 school.intermediate_delegates = i2 school.advanced_delegates = a2 school.save() self.assertEquals( school.fees_owed, registration_fee + delegate_fee * (b2 + i2 + a2), )
def get_context_data(self, **kwargs): conference = Conference.get_current() school = School.objects.get(pk=kwargs['pk']) due_date = school.registered + datetime.timedelta(days=21) delegate_total = sum(( school.beginner_delegates, school.intermediate_delegates, school.advanced_delegates, )) delegate_fee = conference.delegate_fee delegate_fees = delegate_total * delegate_fee fees_owed = school.fees_owed fees_paid = school.fees_paid amount_due = fees_owed - fees_paid return super(SchoolInvoice, self).get_context_data( name=school.name, date_registered=school.registered.strftime("%m/%d/%y"), due_date=due_date.strftime("%m/%d/%y"), delegate_total=delegate_total, delegate_fee=delegate_fee, delegate_fees=delegate_fees, registration_fee=conference.registration_fee, fees_owed=fees_owed, fees_paid=fees_paid, amount_due=amount_due, **kwargs)
def get(self, request, *args, **kwargs): template_name = "invoice.html" conference = Conference.get_current() school = School.objects.get(pk=kwargs['pk']) due_date = school.registered + datetime.timedelta(days=21) delegate_total = sum(( school.beginner_delegates, school.intermediate_delegates, school.advanced_delegates, )) delegate_fee = conference.delegate_fee delegate_fees = delegate_total*delegate_fee fees_owed = school.fees_owed fees_paid = school.fees_paid amount_due = fees_owed - fees_paid context = Context({ "name": school.name, "date_registered": school.registered.strftime("%m/%d/%y"), "due_date": due_date.strftime("%m/%d/%y"), "delegate_total": delegate_total, "delegate_fee": delegate_fee, "delegate_fees": delegate_fees, "registration_fee": conference.registration_fee, "fees_owed": fees_owed, "fees_paid": fees_paid, "amount_due": amount_due}) return render_to_pdf_response(request, template_name, context, **kwargs)
def get_context_data(self, **kwargs): conference = Conference.get_current() school = School.objects.get(pk=kwargs['pk']) due_date = school.registered + datetime.timedelta(days=21) delegate_total = sum((school.beginner_delegates, school.intermediate_delegates, school.advanced_delegates, )) delegate_fee = conference.delegate_fee delegate_fees = delegate_total * delegate_fee fees_owed = school.fees_owed fees_paid = school.fees_paid amount_due = fees_owed - fees_paid return super(SchoolInvoice, self).get_context_data( name=school.name, date_registered=school.registered.strftime("%m/%d/%y"), due_date=due_date.strftime("%m/%d/%y"), delegate_total=delegate_total, delegate_fee=delegate_fee, delegate_fees=delegate_fees, registration_fee=conference.registration_fee, fees_owed=fees_owed, fees_paid=fees_paid, amount_due=amount_due, **kwargs)
def test_anonymous_user(self): response = self.get_response({'school_id': self.school.id, 'conference_session': Conference.get_current()}) self.assertNotAuthenticated(response) response = self.get_response() self.assertNotAuthenticated(response)
def test_valid(self): school = models.new_school() conference = Conference.get_current() params = self.get_params() params['school'] = school.id params['conference'] = conference.session response = self.get_response(params=params) registration_query = Registration.objects.filter( id=response.data['id']) self.assertTrue(registration_query.exists()) registration = Registration.objects.get(id=response.data['id']) self.assertEqual( response.data, { 'id': registration.id, 'registered_at': registration.registered_at.isoformat(), 'school': registration.school.id, 'conference': registration.conference.session, 'is_waitlisted': registration.is_waitlisted, 'num_beginner_delegates': registration.num_beginner_delegates, 'num_intermediate_delegates': registration.num_intermediate_delegates, 'num_advanced_delegates': registration.num_advanced_delegates, 'num_spanish_speaking_delegates': registration.num_spanish_speaking_delegates, 'num_chinese_speaking_delegates': registration.num_chinese_speaking_delegates, 'waivers_completed': registration.waivers_completed, 'country_preferences': registration.country_preference_ids, 'registration_comments': registration.registration_comments, 'committee_preferences': list(registration.committee_preferences.all()), 'delegate_fees_owed': float(registration.delegate_fees_owed), 'delegate_fees_paid': float(registration.delegate_fees_paid), 'registration_fee_paid': registration.registration_fee_paid, 'assignments_finalized': registration.assignments_finalized, 'modified_at': registration.modified_at.isoformat(), })
def test_anonymous_user(self): response = self.get_response({ 'school_id': self.school.id, 'conference_session': Conference.get_current() }) self.assertNotAuthenticated(response) response = self.get_response() self.assertNotAuthenticated(response)
def test_other_user(self): other_user = models.new_user(username='******', password='******') other_school = models.new_school(user=other_user) self.client.login(username='******', password='******') response = self.get_response(params={'school_id': self.school.id, 'conference_session': Conference.get_current()}) self.assertPermissionDenied(response) response = self.get_response() self.assertPermissionDenied(response)
def test_invalid(self): conf = Conference.get_current() conf.open_reg = False conf.save() params = self.get_params() response = self.get_response(params) self.assertEqual(response.data, {'detail': 'Conference registration is closed.'}) conf.open_reg = True conf.save()
def test_invalid(self): conf = Conference.get_current() conf.open_reg = False conf.save() params = self.get_params() response = self.get_response(params) self.assertEqual(response.data, { 'detail': 'Conference registration is closed.'}) conf.open_reg = True conf.save()
def test_update_waitlist(self): '''New schools should be waitlisted based on the conference waitlist field.''' s1 = TestSchools.new_school() self.assertFalse(s1.waitlist) conference = Conference.get_current() conference.waitlist_reg = True conference.save() s1.save() self.assertFalse(s1.waitlist) s2 = TestSchools.new_school() self.assertTrue(s2.waitlist)
def test_update_waitlist(self): '''New registrations should be waitlisted based on the conference waitlist field.''' r1 = models.new_registration() self.assertFalse(r1.is_waitlisted) conference = Conference.get_current() conference.waitlist_reg = True conference.save() r1.save() self.assertFalse(r1.is_waitlisted) r2 = models.new_registration() self.assertTrue(r2.is_waitlisted)
def test_update_waitlist(self): '''New schools should be waitlisted based on the conference waitlist field.''' s1 = models.new_school() self.assertFalse(s1.waitlist) conference = Conference.get_current() conference.waitlist_reg = True conference.save() s1.save() self.assertFalse(s1.waitlist) s2 = models.new_school() self.assertTrue(s2.waitlist)
def test_other_user(self): other_user = models.new_user(username='******', password='******') other_school = models.new_school(user=other_user) self.client.login(username='******', password='******') response = self.get_response( params={ 'school_id': self.school.id, 'conference_session': Conference.get_current() }) self.assertPermissionDenied(response) response = self.get_response() self.assertPermissionDenied(response)
def test_superuser(self): models.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response( params={ 'school_id': self.school.id, 'conference_session': Conference.get_current() }) self.assertEqual(len(response.data), 1) self.assertEqual( dict(response.data[0]), { 'id': self.registration.id, 'school': self.registration.school_id, 'conference': self.registration.conference_id, 'registered_at': self.registration.registered_at.isoformat(), 'is_waitlisted': self.registration.is_waitlisted, 'num_beginner_delegates': self.registration.num_beginner_delegates, 'num_intermediate_delegates': self.registration.num_intermediate_delegates, 'num_advanced_delegates': self.registration.num_advanced_delegates, 'num_spanish_speaking_delegates': self.registration.num_spanish_speaking_delegates, 'num_chinese_speaking_delegates': self.registration.num_chinese_speaking_delegates, 'waivers_completed': self.registration.waivers_completed, 'country_preferences': self.registration.country_preference_ids, 'committee_preferences': list(self.registration.committee_preferences.all()), 'registration_comments': self.registration.registration_comments, 'delegate_fees_owed': float(self.registration.delegate_fees_owed), 'delegate_fees_paid': float(self.registration.delegate_fees_paid), 'registration_fee_paid': self.registration.registration_fee_paid, 'assignments_finalized': self.registration.assignments_finalized, 'modified_at': self.registration.modified_at.isoformat() })
def test_country_preferences(self): '''It should save country preferences.''' c1 = models.new_country().id c2 = models.new_country().id school = models.new_school() conference = Conference.get_current() params = self.get_params(school=school.id, conference=conference.session, countrypreferences=[0, c1, c2, 0, c1]) response = self.get_response(params=params) self.assertEqual(response.data['country_preferences'], [c1, c2]) registration_id = response.data['id'] registration = Registration.objects.get(id=registration_id) self.assertEqual([c1, c2], registration.country_preference_ids)
def test_country_preferences(self): '''It should save country preferences.''' c1 = models.new_country().id c2 = models.new_country().id school = models.new_school() conference = Conference.get_current() params = self.get_params( school=school.id, conference=conference.session, countrypreferences=[0, c1, c2, 0, c1]) response = self.get_response(params=params) self.assertEqual(response.data['country_preferences'], [c1, c2]) registration_id = response.data['id'] registration = Registration.objects.get(id=registration_id) self.assertEqual([c1, c2], registration.country_preference_ids)
def new_registration(**kwargs): test_school = kwargs.pop('school', None) or new_school() test_conference = kwargs.pop('conference', None) or Conference.get_current() r = Registration( school=test_school, conference=test_conference, num_beginner_delegates=kwargs.pop('num_beginner_delegates', 0), num_intermediate_delegates=kwargs.pop('num_intermediate_delegates', 0), num_advanced_delegates=kwargs.pop('num_advanced_delegates', 0), num_spanish_speaking_delegates=kwargs.pop( 'num_spanish_speaking_delegates', 0), num_chinese_speaking_delegates=kwargs.pop( 'num_chinese_speaking_delegates', 0)) r.save() return r
def test_fees(self): '''Fees should be read-only fields.''' school = models.new_school() conference = Conference.get_current() params = self.get_params(school=school.id, conference=conference.session, fees_owed=2000.0, fees_paid=2000.0) response = self.get_response(params=params) registration = Registration.objects.get(id=response.data['id']) delegate_fees_owed = response.data['delegate_fees_owed'] delegate_fees_paid = response.data['delegate_fees_paid'] self.assertEqual(delegate_fees_owed, float(registration.delegate_fees_owed)) self.assertEqual(delegate_fees_paid, float(registration.delegate_fees_paid)) self.assertNotEqual(delegate_fees_owed, 2000.0) self.assertNotEqual(delegate_fees_paid, 2000.0)
def test_superuser(self): models.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(params={'school_id': self.school.id, 'conference_session': Conference.get_current()}) self.assertEqual(len(response.data), 1) self.assertEqual( dict(response.data[0]), { 'id': self.registration.id, 'school': self.registration.school_id, 'conference': self.registration.conference_id, 'registered_at': self.registration.registered_at.isoformat(), 'is_waitlisted': self.registration.is_waitlisted, 'num_beginner_delegates': self.registration.num_beginner_delegates, 'num_intermediate_delegates': self.registration.num_intermediate_delegates, 'num_advanced_delegates': self.registration.num_advanced_delegates, 'num_spanish_speaking_delegates': self.registration.num_spanish_speaking_delegates, 'num_chinese_speaking_delegates': self.registration.num_chinese_speaking_delegates, 'waivers_completed': self.registration.waivers_completed, 'country_preferences': self.registration.country_preference_ids, 'committee_preferences': list(self.registration.committee_preferences.all()), 'registration_comments': self.registration.registration_comments, 'delegate_fees_owed': float(self.registration.delegate_fees_owed), 'delegate_fees_paid': float(self.registration.delegate_fees_paid), 'registration_fee_paid': self.registration.registration_fee_paid, 'assignments_finalized': self.registration.assignments_finalized, 'modified_at': self.registration.modified_at.isoformat() })
def test_fees(self): '''Fees should be read-only fields.''' school = models.new_school() conference = Conference.get_current() params = self.get_params( school=school.id, conference=conference.session, fees_owed=2000.0, fees_paid=2000.0) response = self.get_response(params=params) registration = Registration.objects.get(id=response.data['id']) delegate_fees_owed = response.data['delegate_fees_owed'] delegate_fees_paid = response.data['delegate_fees_paid'] self.assertEqual(delegate_fees_owed, float(registration.delegate_fees_owed)) self.assertEqual(delegate_fees_paid, float(registration.delegate_fees_paid)) self.assertNotEqual(delegate_fees_owed, 2000.0) self.assertNotEqual(delegate_fees_paid, 2000.0)
def index(request): if request.user.is_superuser: return redirect(reverse('admin:index')) user_dict = {} if request.user.is_authenticated(): user_dict = UserSerializer(request.user).data conference = Conference.get_current() conference_dict = { 'session': conference.session, 'start_date': { 'month': conference.start_date.strftime('%B'), 'day': conference.start_date.strftime('%d'), 'year': conference.start_date.strftime('%Y') }, 'end_date': { 'month': conference.end_date.strftime('%B'), 'day': conference.end_date.strftime('%d'), 'year': conference.end_date.strftime('%Y') }, 'external': conference.external, 'registration_fee': int(conference.registration_fee), 'delegate_fee': int(conference.delegate_fee), 'registration_open': conference.open_reg, 'registration_waitlist': conference.waitlist_reg, 'position_papers_accepted': conference.position_papers_accepted, } context = { 'user_json': json.dumps(user_dict).replace('</', '<\\/'), 'conference_json': json.dumps(conference_dict), 'gender_constants': ContactGender.to_json(), 'contact_types': ContactType.to_json(), 'program_types': ProgramTypes.to_json(), } return render(request, 'www.html', context)
def index(request): if request.user.is_superuser: return redirect(reverse('admin:index')) user_dict = {} if request.user.is_authenticated: user_dict = UserSerializer(request.user).data conference = Conference.get_current() conference_dict = { 'session': conference.session, 'start_date': { 'month': conference.start_date.strftime('%B'), 'day': conference.start_date.strftime('%d'), 'year': conference.start_date.strftime('%Y') }, 'end_date': { 'month': conference.end_date.strftime('%B'), 'day': conference.end_date.strftime('%d'), 'year': conference.end_date.strftime('%Y') }, 'external': conference.external, 'registration_fee': int(conference.registration_fee), 'delegate_fee': int(conference.delegate_fee), 'registration_open': conference.open_reg, 'registration_waitlist': conference.waitlist_reg, 'position_papers_accepted': conference.position_papers_accepted, } context = { 'user_json': json.dumps(user_dict).replace('</', '<\\/'), 'conference_json': json.dumps(conference_dict), 'gender_constants': ContactGender.to_json(), 'contact_types': ContactType.to_json(), 'program_types': ProgramTypes.to_json(), } return render(request, 'www.html', context)
def test_valid(self): school = models.new_school() conference = Conference.get_current() params = self.get_params() params['school'] = school.id params['conference'] = conference.session response = self.get_response(params=params) registration_query = Registration.objects.filter( id=response.data['id']) self.assertTrue(registration_query.exists()) registration = Registration.objects.get(id=response.data['id']) self.assertEqual(response.data, { 'id': registration.id, 'registered_at': registration.registered_at.isoformat(), 'school': registration.school.id, 'conference': registration.conference.session, 'is_waitlisted': registration.is_waitlisted, 'num_beginner_delegates': registration.num_beginner_delegates, 'num_intermediate_delegates': registration.num_intermediate_delegates, 'num_advanced_delegates': registration.num_advanced_delegates, 'num_spanish_speaking_delegates': registration.num_spanish_speaking_delegates, 'num_chinese_speaking_delegates': registration.num_chinese_speaking_delegates, 'waivers_completed': registration.waivers_completed, 'country_preferences': registration.country_preference_ids, 'registration_comments': registration.registration_comments, 'committee_preferences': list(registration.committee_preferences.all()), 'delegate_fees_owed': float(registration.delegate_fees_owed), 'delegate_fees_paid': float(registration.delegate_fees_paid), 'registration_fee_paid': registration.registration_fee_paid, 'assignments_finalized': registration.assignments_finalized, 'modified_at': registration.modified_at.isoformat(), })
def test_update_fees(self): '''Fees should be calculated when a Registration is created/updated.''' b, i, a = 3, 5, 7 registration = models.new_registration( num_beginner_delegates=b, num_intermediate_delegates=i, num_advanced_delegates=a, ) conference = Conference.get_current() delegate_fee = conference.delegate_fee self.assertEquals(registration.delegate_fees_owed, delegate_fee * (b + i + a), ) b2, i2, a2 = 5, 10, 15 registration.num_beginner_delegates = b2 registration.num_intermediate_delegates = i2 registration.num_advanced_delegates = a2 registration.save() self.assertEquals(registration.delegate_fees_owed, delegate_fee * (b2 + i2 + a2), )
def create(self, request, *args, **kwargs): if Conference.get_current().open_reg: return self.register(request, *args, **kwargs) raise PermissionDenied('Conference registration is closed.')