tests/app/soc/logic/test_allocations.py
changeset 1717 d4c4c8668871
parent 1308 35b75ffcbb37
child 1718 ca34f4a8c61b
equal deleted inserted replaced
1716:a387bb7a39d4 1717:d4c4c8668871
    62     """Set up required for the slot allocation tests.
    62     """Set up required for the slot allocation tests.
    63     """
    63     """
    64 
    64 
    65     self.slots = 60
    65     self.slots = 60
    66     self.max_slots_per_org = 40
    66     self.max_slots_per_org = 40
       
    67     self.min_slots_per_org = 2
    67     self.allocated = 0
    68     self.allocated = 0
    68 
    69     self.iterative = True
    69     self.applications = {
    70 
    70         'asf': self.allocate(20),
    71     apps = {
    71         'gcc': self.allocate(15),
    72         'asf': self.allocate(20, 20),
    72         'git': self.allocate(6),
    73         'gcc': self.allocate(15, 30),
    73         'google': self.allocate(3),
    74         'git': self.allocate(6, 6),
    74         'melange': self.allocate(100),
    75         'google': self.allocate(3, 10),
       
    76         'melange': self.allocate(100, 3),
    75         }
    77         }
    76 
    78 
       
    79     self.applications = dict([(k,a) for k, (m, a) in apps.iteritems()])
       
    80     self.mentors = dict([(k,m) for k, (m, a) in apps.iteritems()])
       
    81 
    77     self.orgs = self.applications.keys()
    82     self.orgs = self.applications.keys()
    78 
    83 
    79     self.allocater = allocations.Allocator(self.orgs, self.applications,
    84     self.allocater = allocations.Allocator(
    80                                            self.slots, self.max_slots_per_org)
    85         self.orgs, self.applications, self.mentors, self.slots,
    81 
    86         self.max_slots_per_org, self.min_slots_per_org, self.iterative)
    82   def allocate(self, count):
    87 
       
    88   def allocate(self, count, max):
    83     """Returns a list with count new student objects.
    89     """Returns a list with count new student objects.
    84     """
    90     """
    85 
    91 
    86     i = self.allocated
    92     i = self.allocated
    87     j = i + count
    93     j = i + count
    88     self.allocated += count
    94     self.allocated += count
    89 
    95 
    90     return [Student(i) for i in range(i,j)]
    96     return max, [Student(i) for i in range(i,j)]
    91 
    97 
    92   def testAllocate(self):
    98   def testAllocate(self):
    93     """Test that the allocate helper works properly.
    99     """Test that the allocate helper works properly.
    94 
   100 
    95     A meta-test, it never hurts to be certain.
   101     A meta-test, it never hurts to be certain.
    97 
   103 
    98     stash = self.allocated
   104     stash = self.allocated
    99     self.allocated = 0
   105     self.allocated = 0
   100 
   106 
   101     expected = [Student(0), Student(1), Student(2)]
   107     expected = [Student(0), Student(1), Student(2)]
   102     actual = self.allocate(3)
   108     count, actual = self.allocate(3, 0)
   103     self.failUnlessEqual(expected, actual)
   109     self.failUnlessEqual(expected, actual)
       
   110     self.failUnlessEqual(count, 0)
   104 
   111 
   105     expected = []
   112     expected = []
   106     actual = self.allocate(0)
   113     count, actual = self.allocate(0, 10)
   107     self.failUnlessEqual(expected, actual)
   114     self.failUnlessEqual(expected, actual)
       
   115     self.failUnlessEqual(count, 10)
   108 
   116 
   109     expected = [Student(3)]
   117     expected = [Student(3)]
   110     actual = self.allocate(1)
   118     count, actual = self.allocate(1, 5)
   111     self.failUnlessEqual(expected, actual)
   119     self.failUnlessEqual(expected, actual)
       
   120     self.failUnlessEqual(count, 5)
   112 
   121 
   113     self.allocated = stash
   122     self.allocated = stash
   114 
   123 
   115   def testInitialAllocation(self):
   124   def testInitialAllocation(self):
   116     """Test that an allocation with no arguments does not crash.
   125     """Test that an allocation with no arguments does not crash.
   204   def testAdjustedAllocationCorrect(self):
   213   def testAdjustedAllocationCorrect(self):
   205     """Test that locking an allocation assigns the org the allocation.
   214     """Test that locking an allocation assigns the org the allocation.
   206     """
   215     """
   207 
   216 
   208     locked_slots = {}
   217     locked_slots = {}
   209     adjusted_slots = {'google': 1}
   218     adjusted_slots = {'gcc': 10}
   210 
   219 
   211     with_adjusting = self.allocater.allocate(locked_slots, adjusted_slots)
   220     with_adjusting = self.allocater.allocate(locked_slots, adjusted_slots)
   212     without_adjusting = self.allocater.allocate(locked_slots, {})
   221     without_adjusting = self.allocater.allocate(locked_slots, {})
   213 
   222 
   214     expected = without_adjusting['google'] + 1
   223     expected = without_adjusting['gcc'] + 10
   215     actual = with_adjusting['google']
   224     actual = with_adjusting['gcc']
   216 
   225 
   217     self.failUnlessEqual(expected, actual)
   226     self.failUnlessEqual(expected, actual)