tests/app/soc/logic/test_allocations.py
changeset 1751 17c7a7a48dc7
parent 1721 9acf4fe1b9bb
child 2130 83f4fab7c556
equal deleted inserted replaced
1750:1ac2d27fdb6b 1751:17c7a7a48dc7
    67     self.min_slots_per_org = 2
    67     self.min_slots_per_org = 2
    68     self.allocated = 0
    68     self.allocated = 0
    69     self.iterative = False
    69     self.iterative = False
    70 
    70 
    71     apps = {
    71     apps = {
    72         'asf': self.allocate(20, 20),
    72         'asf': (20, 20),
    73         'gcc': self.allocate(15, 30),
    73         'gcc': (15, 50),
    74         'git': self.allocate(6, 6),
    74         'git': (6, 6),
    75         'google': self.allocate(3, 10),
    75         'google': (3, 10),
    76         'melange': self.allocate(100, 3),
    76         'melange': (100, 3),
    77         }
    77         }
    78 
    78 
    79     self.applications = dict([(k,a) for k, (m, a) in apps.iteritems()])
    79     self.popularity = dict([(k,a) for k, (a, m) in apps.iteritems()])
    80     self.mentors = dict([(k,m) for k, (m, a) in apps.iteritems()])
    80     self.mentors = dict([(k,m) for k, (a, m) in apps.iteritems()])
    81 
    81 
    82     self.orgs = self.applications.keys()
    82     self.orgs = self.popularity.keys()
    83 
    83 
    84     self.allocater = allocations.Allocator(
    84     self.allocater = allocations.Allocator(
    85         self.orgs, self.applications, self.mentors, self.slots,
    85         self.orgs, self.popularity, self.mentors, self.slots,
    86         self.max_slots_per_org, self.min_slots_per_org, self.iterative)
    86         self.max_slots_per_org, self.min_slots_per_org, self.iterative)
    87 
       
    88   def allocate(self, count, max):
       
    89     """Returns a list with count new student objects.
       
    90     """
       
    91 
       
    92     i = self.allocated
       
    93     j = i + count
       
    94     self.allocated += count
       
    95 
       
    96     return max, [Student(i) for i in range(i,j)]
       
    97 
       
    98   def testAllocate(self):
       
    99     """Test that the allocate helper works properly.
       
   100 
       
   101     A meta-test, it never hurts to be certain.
       
   102     """
       
   103 
       
   104     stash = self.allocated
       
   105     self.allocated = 0
       
   106 
       
   107     expected = [Student(0), Student(1), Student(2)]
       
   108     count, actual = self.allocate(3, 0)
       
   109     self.failUnlessEqual(expected, actual)
       
   110     self.failUnlessEqual(count, 0)
       
   111 
       
   112     expected = []
       
   113     count, actual = self.allocate(0, 10)
       
   114     self.failUnlessEqual(expected, actual)
       
   115     self.failUnlessEqual(count, 10)
       
   116 
       
   117     expected = [Student(3)]
       
   118     count, actual = self.allocate(1, 5)
       
   119     self.failUnlessEqual(expected, actual)
       
   120     self.failUnlessEqual(count, 5)
       
   121 
       
   122     self.allocated = stash
       
   123 
    87 
   124   def testInitialAllocation(self):
    88   def testInitialAllocation(self):
   125     """Test that an allocation with no arguments does not crash.
    89     """Test that an allocation with no arguments does not crash.
   126     """
    90     """
   127 
    91 
   218     adjusted_slots = {'gcc': 10}
   182     adjusted_slots = {'gcc': 10}
   219 
   183 
   220     with_adjusting = self.allocater.allocate(locked_slots, adjusted_slots)
   184     with_adjusting = self.allocater.allocate(locked_slots, adjusted_slots)
   221     without_adjusting = self.allocater.allocate(locked_slots, {})
   185     without_adjusting = self.allocater.allocate(locked_slots, {})
   222 
   186 
   223     expected = without_adjusting['gcc']
   187     expected = without_adjusting['gcc'] + 10
   224     actual = with_adjusting['gcc']
   188     actual = with_adjusting['gcc']
   225 
   189 
   226     self.failUnless(actual > expected)
   190     self.failIf(actual < expected, "%d < %d" % (actual, expected))