def test_import(self): '''Test that the admin panel can import Assignments.''' models.new_superuser(username='******', password='******') self.client.login(username='******', password='******') registration = models.new_registration() 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( registration=registration, committee=Committee.objects.get(name='SPD'), country=Country.objects.get(name="Côte d'Ivoire")).exists()) self.assertTrue( Assignment.objects.filter( registration=registration, 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_country_preferences(self): '''It should save a school's country preferences.''' c1 = models.new_country().id c2 = models.new_country().id params = self.get_params(countrypreferences=[0, c1, c2, 0, c1]) response = self.get_response(params=params) self.assertEqual(response.data['countrypreferences'], [c1, c2]) school_id = response.data['id'] school = School.objects.get(id=school_id) self.assertEqual([c1, c2], school.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 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_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_anonymous_user(self): '''Anyone should be able to access a list of all the countries.''' country1 = models.new_country(name='USA') country2 = models.new_country(name='China') country3 = models.new_country(name='Barbara Boxer', special=True) response = self.get_response() self.assertEqual(response.data, [ {'id': country1.id, 'special': country1.special, 'name': country1.name}, {'id': country2.id, 'special': country2.special, 'name': country2.name}, {'id': country3.id, 'special': country3.special, 'name': country3.name}])
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 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 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 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 test_update_country_preferences(self): '''It should filter and replace the country preferences.''' r1 = models.new_registration() r2 = models.new_registration() 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()) r1.update_country_preferences(country_ids) self.assertEquals([c1, c2, c3], r1.country_preference_ids) r2.update_country_preferences(country_ids) self.assertEquals([c1, c2, c3], r2.country_preference_ids) r1.update_country_preferences([c3, c1]) self.assertEquals([c3, c1], r1.country_preference_ids) self.assertEquals([c1, c2, c3], r2.country_preference_ids)
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_update_country_preferences(self): '''It should filter and replace the country preferences.''' r1 = models.new_registration() r2 = models.new_registration() 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()) r1.update_country_preferences(country_ids) self.assertEquals([c1, c2, c3], r1.country_preference_ids) r2.update_country_preferences(country_ids) self.assertEquals([c1, c2, c3], r2.country_preference_ids) r1.update_country_preferences([c3, c1]) self.assertEquals([c3, c1], r1.country_preference_ids) self.assertEquals([c1, c2, c3], r2.country_preference_ids)
def test_anonymous_user(self): '''Anyone should be able to access a list of all the countries.''' country1 = models.new_country(name='USA') country2 = models.new_country(name='China') country3 = models.new_country(name='Barbara Boxer', special=True) response = self.get_response() self.assertEqual(response.data, [{ 'id': country1.id, 'special': country1.special, 'name': country1.name }, { 'id': country2.id, 'special': country2.special, 'name': country2.name }, { 'id': country3.id, 'special': country3.special, 'name': country3.name }])
def test_import(self): '''Test that the admin panel can import delegates. ''' models.new_superuser(username='******', password='******') self.client.login(username='******', password='******') registration = models.new_registration() 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, registration=registration) Assignment.objects.create( committee=cm2, country=co2, registration=registration) 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( registration=registration, 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( registration=registration, committee=Committee.objects.get(name='USS'), country=Country.objects.get(name='Barbara Boxer')), name='Jane Doe').exists())
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 get_test_object(cls): return models.new_country()
def get_test_object(cls): return models.new_country()
def setUp(self): self.country = models.new_country(name='USA', special=False)
def setUp(self): self.country = models.new_country(name='USA', special=False)