Esempio n. 1
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!'
     )
Esempio n. 2
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))
Esempio n. 3
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())
Esempio n. 4
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())
Esempio n. 5
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))
Esempio n. 6
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())
Esempio n. 7
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}
        ]
 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 = Assignment.objects.create(
         committee=self.committee1,
         country=self.country,
         school=self.school,
     )
     self.assignment2 = Assignment.objects.create(
         committee=self.committee2,
         country=self.country,
         school=self.school,
     )
Esempio n. 9
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 = Assignment.objects.create(
         committee=self.committee1,
         country=self.country,
         school=self.school,
     )
     self.assignment2 = Assignment.objects.create(
         committee=self.committee2,
         country=self.country,
         school=self.school,
     )
Esempio n. 10
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
Esempio n. 11
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
Esempio n. 12
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
Esempio n. 13
0
    def test_anonymous_user(self):
        '''Anyone should be able to access a list of all the committees.'''
        c1 = TestCommittees.new_committee(name='DISC', delegation_size=100)
        c2 = TestCommittees.new_committee(name='JCC', special=True,
                                          delegation_size=30)

        response = self.get_response()
        self.assertEqual(response.data, [
            {'delegation_size': c1.delegation_size,
             'special': c1.special,
             'id': c1.id,
             'full_name': c1.full_name,
             'name': c1.name},
            {'delegation_size': c2.delegation_size,
             'special': c2.special,
             'id': c2.id,
             'full_name': c2.full_name,
             'name': c2.name}])
Esempio n. 14
0
    def test_anonymous_user(self):
        '''Anyone should be able to access a list of all the committees.'''
        c1 = TestCommittees.new_committee(name='DISC', delegation_size=100)
        c2 = TestCommittees.new_committee(name='JCC', special=True,
                                          delegation_size=30)

        response = self.get_response()
        self.assertEqual(response.data, [
            {'delegation_size': c1.delegation_size,
             'special': c1.special,
             'id': c1.id,
             'full_name': c1.full_name,
             'name': c1.name},
            {'delegation_size': c2.delegation_size,
             'special': c2.special,
             'id': c2.id,
             'full_name': c2.full_name,
             'name': c2.name}])
Esempio n. 15
0
 def test_anonymous_user(self):
     '''It should return the correct fields for a committee.'''
     c = TestCommittees.new_committee()
     response = self.get_response(c.id)
     self.assertEqual(response.data, {
         'id': c.id,
         'name': c.name,
         'full_name': c.full_name,
         'delegation_size': c.delegation_size,
         'special': c.special})
Esempio n. 16
0
 def test_anonymous_user(self):
     '''It should return the correct fields for a committee.'''
     c = TestCommittees.new_committee()
     response = self.get_response(c.id)
     self.assertEqual(response.data, {
         'id': c.id,
         'name': c.name,
         'full_name': c.full_name,
         'delegation_size': c.delegation_size,
         'special': c.special})
Esempio n. 17
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())
Esempio n. 18
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)
Esempio n. 19
0
 def get_test_object(cls):
     return TestCommittees.new_committee()
Esempio n. 20
0
 def setUp(self):
     self.committee = TestCommittees.new_committee()
Esempio n. 21
0
 def setUp(self):
     self.committee = TestCommittees.new_committee()