Exemplo n.º 1
0
    def test_update_assignments(self):
        '''It should correctly update the set of country assignments.'''
        cm1 = TestCommittees.new_committee(name='CM1').id
        cm2 = TestCommittees.new_committee(name='CM2').id
        ct1 = TestCountries.new_country(name='CT1').id
        ct2 = TestCountries.new_country(name='CT2').id
        ct3 = TestCountries.new_country(name='CT3').id
        s1 = TestSchools.new_school(name='S1').id
        s2 = TestSchools.new_school(name='S2').id

        Assignment.objects.bulk_create([
            Assignment(committee_id=cm, country_id=ct, school_id=s1)
            for ct in [ct1, ct2]
            for cm in [cm1, cm2]
        ])

        # TODO: Also assert on delegate deletion.
        updates = [
            (cm1, ct1, s1),
            (cm1, ct2, s1),
            (cm1, ct3, s1),   # ADDED
            # (cm2, ct1, s1), # DELETED
            (cm2, ct2, s2),   # UPDATED
            (cm2, ct3, s2),   # ADDED
        ]

        Assignment.update_assignments(updates)
        new_assignments = [a[1:] for a in Assignment.objects.all().values_list()]

        self.assertEquals(set(updates), set(new_assignments))
Exemplo n.º 2
0
 def test_other_user(self):
     '''A user cannot delete another user's delegates.'''
     joe = TestUsers.new_user(username='******', password='******')
     TestSchools.new_school(user=joe)
     self.do_test(
         username='******', password='******',
         expected_error=auto.EXP_PERMISSION_DENIED)
Exemplo n.º 3
0
    def test_update_assignments(self):
        '''It should correctly update the set of country assignments.'''
        cm1 = TestCommittees.new_committee(name='CM1').id
        cm2 = TestCommittees.new_committee(name='CM2').id
        ct1 = TestCountries.new_country(name='CT1').id
        ct2 = TestCountries.new_country(name='CT2').id
        ct3 = TestCountries.new_country(name='CT3').id
        s1 = TestSchools.new_school(name='S1').id
        s2 = TestSchools.new_school(name='S2').id

        Assignment.objects.bulk_create([
            Assignment(committee_id=cm, country_id=ct, school_id=s1)
            for ct in [ct1, ct2]
            for cm in [cm1, cm2]
        ])

        # 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
        ]

        Assignment.update_assignments(updates)
        new_assignments = [a[1:] for a in Assignment.objects.all().values_list()]

        self.assertEquals(set(updates), set(new_assignments))
Exemplo n.º 4
0
    def test_other_user(self):
        '''It rejects a request from another user.'''
        user2 = TestUsers.new_user(username='******', password='******')
        TestSchools.new_school(user=user2)
        self.client.login(username='******', password='******')

        response = self.get_response(self.school.id)
        self.assertPermissionDenied(response)
Exemplo n.º 5
0
    def test_other_user(self):
        '''It rejects a request from another user.'''
        user2 = TestUsers.new_user(username='******', password='******')
        TestSchools.new_school(user=user2)
        self.client.login(username='******', password='******')

        response = self.get_response(self.school.id)
        self.assertPermissionDenied(response)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    def test_update_waitlist(self):
        '''New schools should be waitlisted based on the conference settings.'''
        self.assertTrue(hasattr(settings, 'CONFERENCE_WAITLIST_OPEN'))

        with self.settings(CONFERENCE_WAITLIST_OPEN=False):
            s1 = TestSchools.new_school()
            self.assertFalse(s1.waitlist)

        with self.settings(CONFERENCE_WAITLIST_OPEN=True):
            s1.save()
            self.assertFalse(s1.waitlist)
            s2 = TestSchools.new_school()
            self.assertTrue(s2.waitlist)
Exemplo n.º 8
0
    def test_update_waitlist(self):
        '''New schools should be waitlisted based on the conference settings.'''
        self.assertTrue(hasattr(settings, 'CONFERENCE_WAITLIST_OPEN'))

        with self.settings(CONFERENCE_WAITLIST_OPEN=False):
            s1 = TestSchools.new_school()
            self.assertFalse(s1.waitlist)

        with self.settings(CONFERENCE_WAITLIST_OPEN=True):
            s1.save()
            self.assertFalse(s1.waitlist)
            s2 = TestSchools.new_school()
            self.assertTrue(s2.waitlist)
Exemplo n.º 9
0
    def test_superuser(self):
        '''it should allow a get request from a superuser.'''
        school = TestSchools.new_school()
        user = TestUsers.new_superuser(username='******', password='******')

        self.client.login(username='******', password='******')
        response = self.get_response(school.id)

        self.assertEqual(response.data, {
            'id': school.id,
            'registered': school.registered,
            '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_email': school.primary_email,
            'primary_phone': school.primary_phone,
            'secondary_name': school.secondary_name,
            'secondary_email': school.secondary_email,
            'secondary_phone': school.secondary_phone,
            'program_type': school.program_type,
            'times_attended': school.times_attended,
            'min_delegation_size': school.min_delegation_size,
            'max_delegation_size': school.max_delegation_size,
            'international': school.international,
            'waitlist': school.waitlist})
Exemplo n.º 10
0
    def test_preference_export(self):
        '''Test that the admin panel can properly export school preferences.'''
        TestUsers.new_user(username='******', password='******')
        TestUsers.new_superuser(username='******', password='******')
        self.client.login(username='******', password='******')
        school = TestSchools.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",
            "Bilingual?",
            "Specialized/Regional?",
            "Crisis?",
            "Alternative?",
            "Press Corps?",
            "Country 1",
            "Country 2",
            "Country 3",
            "Country 4",
            "Country 5",
            "Country 6",
            "Country 7",
            "Country 8",
            "Country 9",
            "Country 10",
            "Registration Comments"
            ]

        fields_csv = ",".join(map(str, header)) + "\r\n"

        countryprefs = [c for c in school.countrypreferences.all()]
        countryprefs += [''] * (10 - len(countryprefs))

        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.prefers_bilingual,
                school.prefers_specialized_regional,
                school.prefers_crisis,
                school.prefers_alternative,
                school.prefers_press_corps]
        fields.extend(countryprefs)
        fields.append(school.registration_comments)

        fields_csv += ",".join(map(str, fields))
        self.assertEquals(fields_csv, response.content[:-2])
Exemplo n.º 11
0
    def test_import(self):
        '''Test that the admin panel can import delegates. '''
        TestUsers.new_superuser(username='******', password='******')
        self.client.login(username='******', password='******')

        school = TestSchools.new_school()
        cm1 = TestCommittees.new_committee(name='SPD')
        cm2 = TestCommittees.new_committee(name='USS')
        co1 = TestCountries.new_country(name="Côte d'Ivoire")
        co2 = TestCountries.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())
Exemplo n.º 12
0
    def test_superuser(self):
        '''it should allow a get request from a superuser.'''
        school = TestSchools.new_school()
        user = TestUsers.new_superuser(username='******', password='******')

        self.client.login(username='******', password='******')
        response = self.get_response(school.id)

        self.assertEqual(
            response.data, {
                'id': school.id,
                'registered': school.registered,
                '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_email': school.primary_email,
                'primary_phone': school.primary_phone,
                'secondary_name': school.secondary_name,
                'secondary_email': school.secondary_email,
                'secondary_phone': school.secondary_phone,
                'program_type': school.program_type,
                'times_attended': school.times_attended,
                'min_delegation_size': school.min_delegation_size,
                'max_delegation_size': school.max_delegation_size,
                'international': school.international,
                'waitlist': school.waitlist
            })
Exemplo n.º 13
0
 def setUp(self):
     self.user = TestUsers.new_user(username='******', password='******')
     self.school = TestSchools.new_school(user=self.user)
     self.country = TestCountries.new_country()
     self.committee1 = TestCommittees.new_committee()
     self.committee2 = TestCommittees.new_committee()
     self.assignment1 = TestAssignments.new_assignment(
         committee=self.committee1,
         country=self.country,
         school=self.school,
     )
     self.assignment2 = TestAssignments.new_assignment(
         committee=self.committee2,
         country=self.country,
         school=self.school,
     )
     self.delegate1 = TestDelegates.new_delegate(
         assignment=self.assignment1,
     )
     self.delegate2 = TestDelegates.new_delegate(
         assignment=self.assignment2,
         name='Trevor Dowds',
         email='*****@*****.**',
         summary='Good!'
     )
Exemplo n.º 14
0
    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),
        )
Exemplo n.º 15
0
    def test_import(self):
        '''Test that the admin panel can import Assignments.'''
        TestUsers.new_superuser(username='******', password='******')
        self.client.login(username='******', password='******')

        school = TestSchools.new_school()
        cm1 = TestCommittees.new_committee(name='SPD')
        cm2 = TestCommittees.new_committee(name='USS')
        co1 = TestCountries.new_country(name="Côte d'Ivoire")
        co2 = TestCountries.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())
Exemplo n.º 16
0
    def test_import(self):
        '''Test that the admin panel can import Assignments.'''
        TestUsers.new_superuser(username='******', password='******')
        self.client.login(username='******', password='******')

        school = TestSchools.new_school()
        cm1 = TestCommittees.new_committee(name='SPD')
        cm2 = TestCommittees.new_committee(name='USS')
        co1 = TestCountries.new_country(name="Côte d'Ivoire")
        co2 = TestCountries.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())
Exemplo n.º 17
0
 def setUp(self):
     self.user = TestUsers.new_user(username='******', password='******')
     self.school = TestSchools.new_school(user=self.user)
     self.committee = TestCommittees.new_committee()
     self.country = TestCountries.new_country()
     self.params['committee'] = self.committee.id
     self.params['school'] = self.school.id
     self.params['country'] = self.country.id
Exemplo n.º 18
0
 def setUp(self):
     self.user = TestUsers.new_user(username="******", password="******")
     self.school = TestSchools.new_school(user=self.user)
     self.committee = TestCommittees.new_committee()
     self.country = TestCountries.new_country()
     self.params["committee"] = self.committee.id
     self.params["school"] = self.school.id
     self.params["country"] = self.country.id
Exemplo n.º 19
0
 def setUp(self):
     self.user = TestUsers.new_user(username='******', password='******')
     self.school = TestSchools.new_school(user=self.user)
     self.committee = TestCommittees.new_committee()
     self.country = TestCountries.new_country()
     self.params['committee'] = self.committee.id
     self.params['school'] = self.school.id
     self.params['country'] = self.country.id
Exemplo n.º 20
0
    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 = TestSchools.new_school(name='S1')
        s2 = TestSchools.new_school(name='S2')
        a = TestAssignments.new_assignment(school=s1, rejected=True)
        d1 = TestDelegates.new_delegate(school=s1, assignment=a)
        d2 = TestDelegates.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)
Exemplo n.º 21
0
    def test_other_user(self):
        '''it should not allow a get request from another user.'''
        school = TestSchools.new_school()
        TestUsers.new_user(username='******', password='******')

        self.client.login(username='******', password='******')
        response = self.get_response(school.id)

        self.assertPermissionDenied(response)
Exemplo n.º 22
0
    def test_other_user(self):
        '''it should not allow a get request from another user.'''
        school = TestSchools.new_school()
        TestUsers.new_user(username='******', password='******')

        self.client.login(username='******', password='******')
        response = self.get_response(school.id)

        self.assertPermissionDenied(response)
Exemplo n.º 23
0
    def test_anonymous_user(self):
        '''It should reject request from an anonymous user.'''
        school = TestSchools.new_school()
        url = self.get_url(school.id)
        data = self.get_response(url)

        self.assertEqual(len(data.keys()), 1)
        self.assertEqual(data['detail'],
                         u'Authentication credentials were not provided.')
Exemplo n.º 24
0
    def test_duplicate_school_name(self):
        '''Validators should not allow for duplicated school names.'''
        params = self.get_params()
        school = TestSchools.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)
Exemplo n.º 25
0
 def setUp(self):
     self.user = TestUsers.new_user(username='******', password='******')
     self.school = TestSchools.new_school(user=self.user)
     self.country = TestCountries.new_country()
     self.committee = TestCommittees.new_committee()
     self.assignment = Assignment.objects.create(
         committee=self.committee,
         country=self.country,
         school=self.school,
     )
Exemplo n.º 26
0
 def setUp(self):
     self.user = TestUsers.new_user(username='******', password='******')
     self.school = TestSchools.new_school(user=self.user)
     self.country = TestCountries.new_country()
     self.committee = TestCommittees.new_committee()
     self.assignment = Assignment.objects.create(
         committee=self.committee,
         country=self.country,
         school=self.school,
     )
Exemplo n.º 27
0
    def test_duplicate_school_name(self):
        '''Validators should not allow for duplicated school names.'''
        params = self.get_params()
        school = TestSchools.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)
Exemplo n.º 28
0
    def test_update_country_preferences(self):
        '''It should filter and replace the school's country preferences.'''
        s1 = TestSchools.new_school()
        s2 = TestSchools.new_school()
        c1 = TestCountries.new_country().id
        c2 = TestCountries.new_country().id
        c3 = TestCountries.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)
Exemplo n.º 29
0
    def test_get(self):
        data = self.get_data(self.url)

        self.assertEqual(len(data.keys()), 1)
        self.assertEqual(data['detail'], u'Not found.')

        school = TestSchools.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()),
        })
Exemplo n.º 30
0
    def test_update_country_preferences(self):
        '''It should filter and replace the school's country preferences.'''
        s1 = TestSchools.new_school()
        s2 = TestSchools.new_school()
        c1 = TestCountries.new_country().id
        c2 = TestCountries.new_country().id
        c3 = TestCountries.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)
Exemplo n.º 31
0
    def test_get(self):
        data = self.get_data(self.url)

        self.assertEqual(len(data.keys()), 1)
        self.assertEqual(data['detail'], 'Not found')

        school = TestSchools.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'], {
                '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,
                'country_preferences': 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),
            })
Exemplo n.º 32
0
    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 = TestSchools.new_school(name='S1')
        assignment = TestAssignments.new_assignment()

        self.assertRaises(ValidationError, Delegate.objects.create,
            name="Test Delegate",
            school=school,
            assignment=assignment
        )
Exemplo n.º 33
0
    def test_self(self):
        '''It should return the correct fields for a single user.'''
        school = TestSchools.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})
Exemplo n.º 34
0
    def test_self(self):
        '''It should return the correct fields for a single user.'''
        school = TestSchools.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,
                    'country_preferences': 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),
                },
                'committee': user.committee_id
            })
Exemplo n.º 35
0
    def test_get(self):
        data = self.get_data(self.url)

        self.assertEqual(len(data.keys()), 1)
        self.assertEqual(data['detail'], 'Not found')

        school = TestSchools.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'], {
            '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,
            'country_preferences': 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),
        })
Exemplo n.º 36
0
    def setUp(self):
        self.user = TestUsers.new_user(username='******', password='******')
        self.school = TestSchools.new_school(user=self.user)

        self.country = TestCountries.new_country()
        self.committee1 = TestCommittees.new_committee()
        self.committee2 = TestCommittees.new_committee()
        self.committee3 = TestCommittees.new_committee()
        self.committee4 = TestCommittees.new_committee()

        self.assignment1 = TestAssignments.new_assignment(
            school=self.school,
            country=self.country,
            commitee=self.committee3
        )

        self.assignment2 = TestAssignments.new_assignment(
            school=self.school,
            country=self.country,
            committee=self.committee2
        )

        self.new_assignment = TestAssignments.new_assignment(
            school=self.school,
            country=self.country,
            committee=self.committee3
        )

        self.faulty_assignment = TestAssignments.new_assignment(
            country=self.country,
            committee=self.committee4
        )

        self.delegate1 = TestDelegates.new_delegate(
            name="Nathaniel Parke",
            school=self.school,
            assignment=self.assignment1
        )

        self.delegate2 = TestDelegates.new_delegate(
            name='Trevor Dowds',
            school=self.school,
            assignment=self.assignment2
        )

        self.params = [
            {'id': self.delegate1.id, 'assignment': self.new_assignment.id},
            {'id': self.delegate2.id, 'assignment': None}
        ]
Exemplo n.º 37
0
    def test_update_assignments(self):
        '''It should correctly update the set of country assignments.'''
        cm1 = TestCommittees.new_committee(name='CM1')
        cm2 = TestCommittees.new_committee(name='CM2')
        ct1 = TestCountries.new_country(name='CT1')
        ct2 = TestCountries.new_country(name='CT2')
        ct3 = TestCountries.new_country(name='CT3')
        s1 = TestSchools.new_school(name='S1')
        s2 = TestSchools.new_school(name='S2')

        Assignment.objects.bulk_create([
            Assignment(committee_id=cm.id, country_id=ct.id, school_id=s1.id)
            for ct in [ct1, ct2]
            for cm in [cm1, cm2]
        ])

        a = Assignment.objects.get(committee_id=cm2.id, country_id=ct2.id)
        d1 = TestDelegates.new_delegate(school=s1, assignment=a)
        d2 = TestDelegates.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
        ]

        Assignment.update_assignments(updates)
        new_assignments = [a[1:] for a in Assignment.objects.all().values_list()]
        delegates = Delegate.objects.all()
        updates = [(cm.id, ct.id, s.id, rej) for cm, ct, s, rej in updates]
        self.assertEquals(set(updates), set(new_assignments))
        self.assertEquals(len(delegates), 2)
Exemplo n.º 38
0
    def test_superuser(self):
        '''it should allow a get request from a superuser.'''
        school = TestSchools.new_school()
        TestUsers.new_superuser(username='******', password='******')

        self.client.login(username='******', password='******')
        response = self.get_response(school.id)

        self.assertEqual(
            response.data, {
                '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,
                '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,
            })
Exemplo n.º 39
0
    def test_superuser(self):
        '''it should allow a get request from a superuser.'''
        school = TestSchools.new_school()
        TestUsers.new_superuser(username='******', password='******')

        self.client.login(username='******', password='******')
        response = self.get_response(school.id)

        self.assertEqual(response.data, {
            '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,
            'country_preferences': school.country_preference_ids,
            'prefers_bilingual': school.prefers_bilingual,
            'prefers_specialized_regional': school.prefers_specialized_regional,
            'prefers_crisis': school.prefers_crisis,
            'prefers_alternative': school.prefers_alternative,
            'prefers_press_corps': school.prefers_press_corps,
            'registration_comments': school.registration_comments,
            'fees_owed': float(school.fees_owed),
            'fees_paid': float(school.fees_paid),
        })
Exemplo n.º 40
0
    def test_preference_export(self):
        '''Test that the admin panel can properly export school preferences.'''
        TestUsers.new_user(username='******', password='******')
        TestUsers.new_superuser(username='******', password='******')
        self.client.login(username='******', password='******')
        school = TestSchools.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",
            "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))

        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.append(school.registration_comments)

        fields_csv += ",".join(map(str, fields))
        self.assertEquals(fields_csv, response.content[:-2])
Exemplo n.º 41
0
    def test_self(self):
        '''It should allow the get request from the user.'''
        school = TestSchools.new_school()

        self.client.login(username=school.advisor.username, password='******')
        response = self.get_response(school.id)
        self.assertEqual(response.data, {
            '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,
            'country_preferences': 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,
        })
Exemplo n.º 42
0
    def test_import(self):
        '''Test that the admin panel can import delegates. '''
        TestUsers.new_superuser(username='******', password='******')
        self.client.login(username='******', password='******')

        school = TestSchools.new_school()
        cm1 = TestCommittees.new_committee(name='SPD')
        cm2 = TestCommittees.new_committee(name='USS')
        co1 = TestCountries.new_country(name="Côte d'Ivoire")
        co2 = TestCountries.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())
Exemplo n.º 43
0
    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,
        )

        self.assertEquals(
            school.fees_owed,
            school.REGISTRATION_FEE + school.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,
            school.REGISTRATION_FEE + school.DELEGATE_FEE * (b2 + i2 + a2),
        )
Exemplo n.º 44
0
    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,
        )

        self.assertEquals(
            school.fees_owed,
            school.REGISTRATION_FEE + school.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,
            school.REGISTRATION_FEE + school.DELEGATE_FEE * (b2 + i2 + a2),
        )
Exemplo n.º 45
0
 def setUp(self):
     self.user = TestUsers.new_user(username='******', password='******')
     self.school = TestSchools.new_school(user=self.user)
     self.assignment = TestAssignments.new_assignment(school=self.school)
Exemplo n.º 46
0
 def setUp(self):
     self.school = TestSchools.new_school()
     self.user = self.school.advisor
Exemplo n.º 47
0
 def setUp(self):
     self.user = TestUsers.new_user(username='******', password='******')
     self.school = TestSchools.new_school(user=self.user)
     self.assignment = TestAssignments.new_assignment(school=self.school)
     self.delegate = TestDelegates.new_delegate(assignment=self.assignment)
     self.params['assignment'] = self.assignment.id
Exemplo n.º 48
0
    def test_anonymous_user(self):
        '''It should reject request from an anonymous user.'''
        school = TestSchools.new_school()
        response = self.get_response(school.id)

        self.assertNotAuthenticated(response)
Exemplo n.º 49
0
    def test_info_export(self):
        '''Test that the admin panel can properly export a list of schools.'''
        TestUsers.new_user(username='******', password='******')
        TestUsers.new_superuser(username='******', password='******')
        self.client.login(username='******', password='******')
        school = TestSchools.new_school()
        self.client.logout()
        self.client.login(username='******', password='******')

        response = self.client.get(reverse('admin:core_school_info'))

        self.assertTrue(response)

        header = [
            "ID",
            "Name",
            "Address",
            "City",
            "State",
            "Zip Code",
            "Country",
            "Primary Name",
            "Primary Gender",
            "Primary Email",
            "Primary Phone",
            "Primary Type",
            "Secondary Name",
            "Secondary Gender",
            "Secondary Email",
            "Secondary Phone",
            "Secondary Type",
            "Program Type",
            "Times Attended",
            "International",
            "Waitlist",
            "Beginners",
            "Intermediates",
            "Advanced",
            "Spanish Speakers",
            "Chinese Speakers",
            "Registration Comments",
            "Fees Owed",
            "Fees Paid",
        ]

        fields_csv = ",".join(map(str, header)) + "\r\n"

        fields = [
            school.id,
            school.name,
            school.address,
            school.city,
            school.state,
            school.zip_code,
            school.country,
            school.primary_name,
            school.primary_gender,
            school.primary_email,
            school.primary_phone,
            school.primary_type,
            school.secondary_name,
            school.secondary_gender,
            school.secondary_email,
            school.secondary_phone,
            school.secondary_type,
            school.program_type,
            school.times_attended,
            school.international,
            school.waitlist,
            school.beginner_delegates,
            school.intermediate_delegates,
            school.advanced_delegates,
            school.spanish_speaking_delegates,
            school.chinese_speaking_delegates,
            school.registration_comments,
            school.fees_owed,
            school.fees_paid,
        ]

        fields_csv += ",".join(map(str, fields))
        self.assertEquals(fields_csv, response.content[:-2])
Exemplo n.º 50
0
 def get_test_object(cls):
     return TestSchools.new_school()
Exemplo n.º 51
0
 def setUp(self):
     self.school = TestSchools.new_school()
     self.user = self.school.advisor