Beispiel #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, 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))
Beispiel #2
0
    def new_assignment(**kwargs):
        test_committee = TestCommittees.new_committee()
        test_school = TestSchools.new_school()
        test_country = TestCountries.new_country()

        a = Assignment(committee=kwargs.pop('committee', test_committee),
                       school=kwargs.pop('school', test_school),
                       country=kwargs.pop('country', test_country),
                       rejected=kwargs.pop('rejected', False))
        a.save()
        return a
Beispiel #3
0
def new_assignment(**kwargs):
    test_committee = kwargs.pop('committee', None) or new_committee()
    test_registration = kwargs.pop('registration', None) or new_registration()
    test_country = kwargs.pop('country', None) or new_country()

    a = Assignment(
        committee=test_committee,
        registration=test_registration,
        country=test_country,
        rejected=kwargs.pop('rejected', False),
    )
    a.save()
    return a
Beispiel #4
0
def new_assignment(**kwargs):
    test_committee = kwargs.pop('committee', None) or new_committee()
    test_school = kwargs.pop('school', None) or new_school()
    test_country = kwargs.pop('country', None) or new_country()

    a = Assignment(
        committee=test_committee,
        school=test_school,
        country=test_country,
        rejected=kwargs.pop('rejected', False),
    )
    a.save()
    return a
Beispiel #5
0
    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)
Beispiel #6
0
 def test_create_position_paper(self):
     '''Tests that an assigment creates a new position paper upon
        being saved for the first time, but not on subsequent saves.'''
     a = Assignment(committee_id=1, country_id=1, registration_id=1)
     self.assertTrue(a.paper == None)
     a.save()
     self.assertTrue(a.paper != None)
     paper_id = a.paper.id
     a.paper.graded = True
     a.paper.save()
     a.save()
     self.assertTrue(a.paper.graded)
     self.assertEquals(a.paper.id, paper_id)
     a.paper = None
     a.save()
     self.assertFalse(a.paper == None)
     self.assertFalse(a.paper.id == paper_id)
Beispiel #7
0
from xlrd import open_workbook

s = open_workbook('Country Matrix.xlsx').sheet_by_index(0)

country_range = s.nrows - 2
committee_range = 22

for row in range(3, country_range):
    Country.objects.get_or_create(name=s.cell(row, 0).value,
                                  special=(True if row > 204 else False))

for col in range(1, committee_range):
    Committee.objects.get_or_create(
        name=s.cell(1, col).value,
        full_name=s.cell(2, col).value,
        delegation_size=(1 if s.cell(0, col).value == 'SINGLE' else 2),
        special=(True if col > 7 else False))

for row in range(3, country_range):
    for col in range(1, committee_range):
        if s.cell(row, col).value:
            print s.cell(1, col).value
            print s.cell(2, col).value
            print s.cell(row, 0).value
            print s.cell(row, col).value
            print
            country = Country.objects.get(name=s.cell(row, 0).value)
            committee = Committee.objects.get(name=s.cell(1, col).value)
            assignment = Assignment(committee=committee, country=country)
            assignment.save()