def setUp(self): self.user = models.new_user(username='******', password='******') self.user2 = models.new_user(username='******', password='******') self.school = models.new_school(user=self.user) self.school2 = models.new_school(user=self.user2) self.assignment1 = models.new_assignment(school=self.school) self.assignment2 = models.new_assignment(school=self.school) self.assignment3 = models.new_assignment(school=self.school2) self.new_assignment = models.new_assignment(school=self.school) self.faulty_assignment = models.new_assignment() self.delegate1 = models.new_delegate(name="Nathaniel Parke", school=self.school, assignment=self.assignment1) self.delegate2 = models.new_delegate(name='Trevor Dowds', school=self.school, assignment=self.assignment2) self.delegate3 = models.new_delegate(name='Kunal Mehta', school=self.school2, assignment=self.assignment3) self.params = [{ 'id': self.delegate1.id, 'assignment': self.new_assignment.id }, { 'id': self.delegate2.id, 'assignment': None }]
def setUp(self): self.user = models.new_user(username='******', password='******') self.school = models.new_school(user=self.user) self.user2 = models.new_user(username='******', password='******') self.school2 = models.new_school(user=self.user2) self.assignment = models.new_assignment(school=self.school) self.params['assignment'] = self.assignment.id self.params['school'] = self.school.id
def test_other_user(self): '''It rejects a request from another user.''' user2 = models.new_user(username='******', password='******') models.new_school(user=user2) self.client.login(username='******', password='******') response = self.get_response(params={'school_id': self.school.id}) self.assertPermissionDenied(response)
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 setUp(self): self.advisor = models.new_user(username='******', password='******') self.advisor2 = models.new_user( username='******', password='******') self.chair = models.new_user( username='******', password='******', user_type=User.TYPE_CHAIR) self.delegate_user = models.new_user( username='******', password='******', user_type=User.TYPE_DELEGATE) self.school = models.new_school(user=self.advisor) self.school2 = models.new_school(user=self.advisor2) self.registration = models.new_registration(school=self.school) self.registration2 = models.new_registration(school=self.school2) self.committee = models.new_committee(user=self.chair) self.assignment1 = models.new_assignment( registration=self.registration, committee=self.committee) self.assignment2 = models.new_assignment( registration=self.registration) self.assignment3 = models.new_assignment( registration=self.registration2, committee=self.committee) self.new_assignment = models.new_assignment( registration=self.registration) self.new_assignment2 = models.new_assignment( registration=self.registration2) self.faulty_assignment = models.new_assignment() self.delegate1 = models.new_delegate( name="Nathaniel Parke", school=self.school, assignment=self.assignment1) self.delegate2 = models.new_delegate( name='Trevor Dowds', school=self.school, assignment=self.assignment2) self.delegate3 = models.new_delegate( name='Kunal Mehta', school=self.school2, assignment=self.assignment3) self.params = [ {'id': self.delegate1.id, 'assignment': self.new_assignment.id}, {'id': self.delegate2.id, 'assignment': None} ]
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 test_other_user(self): '''A user should not be able to partially update another user's info.''' other_user = models.new_user(username='******', password='******') school = models.new_school(user=other_user) self.client.login(username='******', password='******') response = self.get_response(self.registration.id, self.params) self.assertPermissionDenied(response)
def test_import(self): '''Test that the admin panel can import Assignments.''' models.new_superuser(username='******', password='******') self.client.login(username='******', password='******') school = models.new_school() cm1 = models.new_committee(name='SPD') cm2 = models.new_committee(name='USS') co1 = models.new_country(name="Côte d'Ivoire") co2 = models.new_country(name='Barbara Boxer') f = TestFiles.new_csv([ ['Test School', 'SPD', "Côte d'Ivoire"], ['Test School', 'USS', 'Barbara Boxer'] ]) with closing(f) as f: self.client.post(reverse('admin:core_assignment_load'), {'csv': f}) self.assertTrue(Assignment.objects.filter( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='SPD'), country=Country.objects.get(name="Côte d'Ivoire") ).exists()) self.assertTrue(Assignment.objects.filter( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='USS'), country=Country.objects.get(name='Barbara Boxer') ).exists())
def test_import(self): '''Test that the admin panel can import delegates. ''' models.new_superuser(username='******', password='******') self.client.login(username='******', password='******') school = models.new_school() cm1 = models.new_committee(name='SPD') cm2 = models.new_committee(name='USS') co1 = models.new_country(name="Côte d'Ivoire") co2 = models.new_country(name='Barbara Boxer') Assignment.objects.create(committee=cm1, country=co1, school=school) Assignment.objects.create(committee=cm2, country=co2, school=school) f = TestFiles.new_csv([ ['Name', 'Committee', 'Country', 'School'], ['John Doe', 'SPD', "Côte d'Ivoire", 'Test School'], ['Jane Doe', 'USS', 'Barbara Boxer', 'Test School'], ]) with closing(f) as f: self.client.post(reverse('admin:core_delegate_load'), {'csv': f}) self.assertTrue( Delegate.objects.filter(assignment=Assignment.objects.get( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='SPD'), country=Country.objects.get(name="Côte d'Ivoire")), name='John Doe').exists()) self.assertTrue( Delegate.objects.filter(assignment=Assignment.objects.get( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='USS'), country=Country.objects.get(name='Barbara Boxer')), name='Jane Doe').exists())
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 setUp(self): self.user = models.new_user(username='******', password='******') self.school = models.new_school(user=self.user) self.assignment = models.new_assignment(school=self.school) self.delegate = models.new_delegate(assignment=self.assignment, school=self.school) self.params['assignment'] = self.assignment.id
def test_update_assignments(self): '''It should correctly update the set of country assignments.''' cm1 = models.new_committee(name='CM1') cm2 = models.new_committee(name='CM2') ct1 = models.new_country(name='CT1') ct2 = models.new_country(name='CT2') ct3 = models.new_country(name='CT3') s1 = models.new_school(name='S1') r1 = models.new_registration(school=s1) s2 = models.new_school(name='S2') r2 = models.new_registration(school=s2) Assignment.objects.bulk_create([ Assignment(committee_id=cm.id, country_id=ct.id, registration_id=r1.id) for ct in [ct1, ct2] for cm in [cm1, cm2] ]) a = Assignment.objects.get(committee_id=cm2.id, country_id=ct2.id) d1 = models.new_delegate(school=s1, assignment=a) d2 = models.new_delegate(school=s1, assignment=a) # TODO: Also assert on delegate deletion. updates = [ (cm1, ct1, s1, False), (cm1, ct2, s1, False), (cm1, ct3, s1, False), # ADDED # (cm2, ct1, s1), # DELETED (cm2, ct2, s2, False), # UPDATED (cm2, ct3, s2, False), # ADDED ] all_assignments = [ (cm1.id, ct1.id, r1.id, False), (cm1.id, ct2.id, r1.id, False), (cm1.id, ct3.id, r1.id, False), (cm2.id, ct2.id, r2.id, False), (cm2.id, ct3.id, r2.id, False), (cm2.id, ct1.id, r1.id, False), ] Assignment.update_assignments(updates) assignments = [a[1:-1] for a in Assignment.objects.all().values_list()] delegates = Delegate.objects.all() self.assertEquals(set(all_assignments), set(assignments)) self.assertEquals(len(delegates), 2)
def test_get(self): data = self.get_data(self.url) self.assertEqual(len(data.keys()), 1) self.assertEqual(data['detail'], u'Not found.') school = models.new_school() user = school.advisor self.client.login(username=user.username, password='******') data = self.get_data(self.url) self.assertEqual(len(data.keys()), 7) self.assertEqual(data['id'], user.id) self.assertEqual(data['username'], user.username) self.assertEqual(data['first_name'], user.first_name) self.assertEqual(data['last_name'], user.last_name) self.assertEqual(data['user_type'], User.TYPE_ADVISOR) self.assertEqual( data['school'], { u'id': school.id, u'registered': unicode(school.registered.isoformat()), u'name': unicode(school.name), u'address': unicode(school.address), u'city': unicode(school.city), u'state': unicode(school.state), u'zip_code': unicode(school.zip_code), u'country': unicode(school.country), u'primary_name': unicode(school.primary_name), u'primary_gender': school.primary_gender, u'primary_email': unicode(school.primary_email), u'primary_phone': unicode(school.primary_phone), u'primary_type': school.primary_type, u'secondary_name': unicode(school.secondary_name), u'secondary_gender': school.secondary_gender, u'secondary_email': unicode(school.secondary_email), u'secondary_phone': unicode(school.secondary_phone), u'secondary_type': school.secondary_type, u'program_type': school.program_type, u'times_attended': school.times_attended, u'international': school.international, u'waitlist': school.waitlist, u'beginner_delegates': school.beginner_delegates, u'intermediate_delegates': school.intermediate_delegates, u'advanced_delegates': school.advanced_delegates, u'spanish_speaking_delegates': school.spanish_speaking_delegates, u'chinese_speaking_delegates': school.chinese_speaking_delegates, u'waivers_completed': school.waivers_completed, u'countrypreferences': school.country_preference_ids, u'committeepreferences': list( school.committeepreferences.all()), u'registration_comments': unicode( school.registration_comments), u'fees_owed': float(school.fees_owed), u'fees_paid': float(school.fees_paid), u'assignments_finalized': school.assignments_finalized, u'modified_at': unicode(school.modified_at.isoformat()), })
def setUp(self): self.user = models.new_user(username='******', password='******') self.school = models.new_school(user=self.user) self.committee = models.new_committee() self.country = models.new_country() self.params['committee'] = self.committee.id self.params['school'] = self.school.id self.params['country'] = self.country.id
def test_update_assignment(self): '''Tests that when an assignment changes schools, its rejected field is set to False and any delegates assigned to it are no longer assigned to it.''' s1 = models.new_school(name='S1') s2 = models.new_school(name='S2') a = models.new_assignment(school=s1, rejected=True) d1 = models.new_delegate(school=s1, assignment=a) d2 = models.new_delegate(school=s1, assignment=a) self.assertEquals(a.delegates.count(), 2) self.assertTrue(a.rejected) a.school = s2 a.save() self.assertEquals(a.delegates.count(), 0) self.assertEquals(a.rejected, False)
def test_self(self): '''It should return the correct fields for a single user.''' school = models.new_school() user = school.advisor self.client.login(username=user.username, password='******') response = self.get_response(user.id) self.assertEqual( response.data, { 'id': user.id, 'username': user.username, 'first_name': user.first_name, 'last_name': user.last_name, 'user_type': user.user_type, 'school': { 'id': school.id, 'registered': school.registered.isoformat(), 'name': school.name, 'address': school.address, 'city': school.city, 'state': school.state, 'zip_code': school.zip_code, 'country': school.country, 'primary_name': school.primary_name, 'primary_gender': school.primary_gender, 'primary_email': school.primary_email, 'primary_phone': school.primary_phone, 'primary_type': school.primary_type, 'secondary_name': school.secondary_name, 'secondary_gender': school.secondary_gender, 'secondary_email': school.secondary_email, 'secondary_phone': school.secondary_phone, 'secondary_type': school.secondary_type, 'program_type': school.program_type, 'times_attended': school.times_attended, 'international': school.international, 'waitlist': school.waitlist, 'beginner_delegates': school.beginner_delegates, 'intermediate_delegates': school.intermediate_delegates, 'advanced_delegates': school.advanced_delegates, 'spanish_speaking_delegates': school.spanish_speaking_delegates, 'chinese_speaking_delegates': school.chinese_speaking_delegates, 'waivers_completed': school.waivers_completed, 'countrypreferences': school.country_preference_ids, 'committeepreferences': list( school.committeepreferences.all()), 'registration_comments': school.registration_comments, 'fees_owed': float(school.fees_owed), 'fees_paid': float(school.fees_paid), 'assignments_finalized': school.assignments_finalized, 'modified_at': school.modified_at.isoformat(), }, 'committee': user.committee_id })
def setUp(self): self.advisor = models.new_user(username='******', password='******') self.advisor2 = models.new_user( username='******', password='******') self.chair = models.new_user( username='******', password='******', user_type=User.TYPE_CHAIR) self.delegate_user = models.new_user( username='******', password='******', user_type=User.TYPE_DELEGATE) self.school = models.new_school(user=self.advisor) self.school2 = models.new_school(user=self.advisor2) self.registration = models.new_registration(school=self.school) self.registration2 = models.new_registration(school=self.school2) self.committee = models.new_committee(user=self.chair) self.assignment = models.new_assignment( registration=self.registration, committee=self.committee) self.params['assignment'] = self.assignment.id self.params['school'] = self.school.id
def test_duplicate_school_name(self): '''Validators should not allow for duplicated school names.''' params = self.get_params() school = models.new_school(name=params['name']) response = self.get_response(params=params) self.assertEqual(response.data, {"name": ["A school with the name \"%s\" has already been registered." %params['name']]}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def setUp(self): self.advisor = models.new_user(username='******', password='******') self.school = models.new_school(user=self.advisor) self.registration = models.new_registration(school=self.school) self.params = { 'conference': self.registration.conference.session, 'school': self.registration.school.id, 'country_preferences': self.registration.country_preference_ids, 'assignments_finalized': True, }
def setUp(self): self.user = models.new_user(username='******', password='******') self.school = models.new_school(user=self.user) self.country = models.new_country() self.committee = models.new_committee() self.assignment = Assignment.objects.create( committee=self.committee, country=self.country, school=self.school, )
def setUp(self): self.user = models.new_user(username='******', password='******') self.school = models.new_school(user=self.user) self.assignment1 = models.new_assignment(school=self.school) self.assignment2 = models.new_assignment(school=self.school) self.delegate1 = models.new_delegate(assignment=self.assignment1, ) self.delegate2 = models.new_delegate(assignment=self.assignment2, name='Trevor Dowds', email='*****@*****.**', summary='Good!')
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_country_preferences(self): '''It should filter and replace the school's country preferences.''' s1 = models.new_school() s2 = models.new_school() c1 = models.new_country().id c2 = models.new_country().id c3 = models.new_country().id country_ids = [0, c1, c2, c2, 0, c3] self.assertEquals(0, CountryPreference.objects.all().count()) s1.update_country_preferences(country_ids) self.assertEquals([c1, c2, c3], s1.country_preference_ids) s2.update_country_preferences(country_ids) self.assertEquals([c1, c2, c3], s2.country_preference_ids) s1.update_country_preferences([c3, c1]) self.assertEquals([c3, c1], s1.country_preference_ids) self.assertEquals([c1, c2, c3], s2.country_preference_ids)
def test_save(self): """ A delegate's school field and a delegate's assignment's school field should be the same if they both exist on the delegate. """ school = models.new_school(name='S1') assignment = models.new_assignment() self.assertRaises(ValidationError, Delegate.objects.create, name="Test Delegate", school=school, assignment=assignment )
def setUp(self): self.advisor = models.new_user(username='******', password='******') self.school = models.new_school(user=self.advisor) self.registration = models.new_registration(school=self.school) self.assignment = models.new_assignment(registration=self.registration) self.delegate = models.new_delegate( school=self.school, assignment=self.assignment) self.delegate.assignment = None self.delegate.save() self.superuser = models.new_user(is_superuser=True) self.params = {'email': '*****@*****.**'} self.assign_params = {'assignment': self.assignment.id} self.unassign_params = {'assignment': None}
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 setUp(self): self.advisor = models.new_user(username='******', password='******') self.school = models.new_school(user=self.advisor) self.registration = models.new_registration(school=self.school) self.assignment = models.new_assignment(registration=self.registration) self.delegate = models.new_delegate( school=self.school, assignment=self.assignment) self.delegate.assignment = None self.delegate.save() self.superuser = models.new_user(is_superuser=True) self.delegate_user = models.new_user( username='******', delegate=self.delegate, user_type=User.TYPE_DELEGATE)
def setUp(self): self.advisor = models.new_user(username='******', password='******') self.school = models.new_school(user=self.advisor) self.registration = models.new_registration(school=self.school) self.params = { 'conference': self.registration.conference.session, 'school': self.registration.school.id, 'country_preferences': self.registration.country_preference_ids, 'assignments_finalized': True, 'num_beginner_delegates': 0, 'num_intermediate_delegates': 0, 'num_advanced_delegates': 0, 'num_spanish_speaking_delegates': 0, 'num_chinese_speaking_delegates': 0, }
def setUp(self): self.advisor = models.new_user(username='******', password='******') self.chair = models.new_user( username='******', password='******', user_type=User.TYPE_CHAIR) self.school = models.new_school(user=self.advisor) self.registration = models.new_registration(school=self.school) self.committee = models.new_committee(user=self.chair) self.country = models.new_country() self.delegate_user = models.new_user( username='******', password='******', user_type=User.TYPE_DELEGATE) self.params['committee'] = self.committee.id self.params['registration'] = self.registration.id self.params['country'] = self.country.id
def test_preference_export(self): '''Test that the admin panel can properly export school preferences.''' models.new_user(username='******', password='******') models.new_superuser(username='******', password='******') self.client.login(username='******', password='******') school = models.new_school() self.client.logout() self.client.login(username='******', password='******') response = self.client.get(reverse('admin:core_school_preferences')) self.assertTrue(response) header = [ "Name", "Assignments Requested", "Beginners", "Intermediates", "Advanced", "Spanish Speakers", "Chinese Speakers", "Country 1", "Country 2", "Country 3", "Country 4", "Country 5", "Country 6", "Country 7", "Country 8", "Country 9", "Country 10", "Committee Preferences", "Registration Comments" ] fields_csv = ",".join(map(str, header)) + "\r\n" countryprefs = [ c for c in school.countrypreferences.all().order_by( 'countrypreference') ] countryprefs += [''] * (10 - len(countryprefs)) committeeprefs = [ ', '.join([c.name for c in school.committeepreferences.all()]) ] fields = [ school.name, school.beginner_delegates + school.intermediate_delegates + school.advanced_delegates, school.beginner_delegates, school.intermediate_delegates, school.advanced_delegates, school.spanish_speaking_delegates, school.chinese_speaking_delegates, ] fields.extend(countryprefs) fields.extend(committeeprefs) fields.append(school.registration_comments) fields_csv += ",".join(map(str, fields)) self.assertEquals(fields_csv, response.content[:-2])