@@ -0,0 +1,3024 @@
+#!/usr/bin/env python2.5%0A#%0A# Copyright 2011 the Melange authors.%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#   http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A%0A%22%22%22Tests for GCI logic for organizations.%0A%22%22%22%0A%0A__authors__ = %5B%0A    '%22Praveen Kumar%22 %3Cpraveen97uma@gmail.com%3E',%0A    %5D%0A%0A%0Aimport unittest%0A%0Afrom google.appengine.api import memcache%0A%0Afrom soc.modules.gci.logic import organization as organization_logic%0Afrom soc.modules.gci.models.task import GCITask%0A%0Afrom tests.gci_task_utils import GCITaskHelper%0Afrom tests.profile_utils import GCIProfileHelper%0Afrom tests.program_utils import GCIProgramHelper%0A%0Aclass OrganizationTest(unittest.TestCase):%0A  %22%22%22Tests the logic for GCIOrganization.%0A  %22%22%22%0A  %0A  def setUp(self):%0A    self.gci_program_helper = GCIProgramHelper()%0A    self.program = self.gci_program_helper.createProgram()%0A    self.task_helper = GCITaskHelper(self.program)%0A  %0A  def testGetRemainingTaskQuota(self):%0A    %22%22%22Tests if the remaining task quota that can be published by a given %0A    organization is correctly returned.%0A    %22%22%22%0A    gci_program_helper = GCIProgramHelper()%0A    org = gci_program_helper.createOrg()%0A    org.task_quota_limit = 5%0A    org.put()%0A    %0A    mentor = GCIProfileHelper(self.program, False).createOtherUser(%0A        'mentor@gmail.com').createMentor(org)%0A    %0A    student = GCIProfileHelper(self.program, False).createOtherUser(%0A        'student@gmail.com').createStudent()%0A    #valid tasks.%0A    for _ in xrange(3):%0A      self.task_helper.createTask('Closed', org, mentor, student)%0A    #invalid tasks.%0A    self.task_helper.createTask('Unpublished', org, mentor, student)%0A    expected_quota = org.task_quota_limit - 3%0A    actual_quota = organization_logic.getRemainingTaskQuota(org)%0A%0A    self.assertEqual(expected_quota, actual_quota)%0A%0A  def testParticipating(self):%0A    %22%22%22Tests if a list of all the organizations participating in a given gci%0A    program is returned.%0A    %22%22%22%0A    expected = %5B%5D%0A    actual = organization_logic.participating(self.program)%0A    self.assertEqual(expected, actual)%0A    org1 = self.gci_program_helper.createOrg()%0A    org2 = self.gci_program_helper.createNewOrg()%0A    #We need to clear the cache with the key given below as the first call to%0A    #the function being tested sets an empty cache with the same key.%0A    key = 'participating_orgs_for' + self.program.key().name()%0A    memcache.delete(key)%0A    expected = set(%5Borg1.key(), org2.key()%5D)%0A    actual = organization_logic.participating(self.gci_program_helper.program)%0A    actual = set(%5Borg.key() for org in actual%5D)%0A    self.assertEqual(expected, set(actual))%0A

Add tests for gci.logic.organization.