예제 #1
0
    def init(self):
        """Performs test setup.

    Sets the following attributes:
      program_helper: a GCIProgramHelper instance
      gci/program: a GCIProgram instance
      site: a Site instance
      org: a GCIOrganization instance
      org_app: a OrgAppSurvey instance
      timeline: a GCITimelineHelper instance
      data: a GCIProfileHelper instance
    """
        from tests.program_utils import GCIProgramHelper
        from tests.timeline_utils import GCITimelineHelper
        from tests.profile_utils import GCIProfileHelper
        super(GCITestCase, self).init()
        self.program_helper = GCIProgramHelper()
        self.founder = self.program_helper.createFounder()
        self.sponsor = self.program_helper.createSponsor()
        self.gci = self.program = self.program_helper.createProgram()
        self.site = self.program_helper.createSite()
        self.org = self.program_helper.createOrg()
        self.org_app = self.program_helper.createOrgApp()
        self.timeline = GCITimelineHelper(self.gci.timeline, self.org_app)
        self.data = GCIProfileHelper(self.gci, self.dev_test)
예제 #2
0
  def testGetRemainingTaskQuota(self):
    """Tests if the remaining task quota that can be published by a given
    organization is correctly returned.
    """
    gci_program_helper = GCIProgramHelper()
    org = gci_program_helper.createOrg()
    org.task_quota_limit = 5
    org.put()

    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[ndb.Key.from_old_key(org.key())])
    student = profile_utils.seedNDBStudent(self.program)

    # valid tasks.
    for _ in xrange(3):
      task_utils.seedTask(
          self.program, org, [mentor.key.to_old_key()],
          student=student.key.to_old_key(), status=task_model.CLOSED)
    # invalid tasks.
      task_utils.seedTask(
          self.program, org, [mentor.key.to_old_key()],
          student=student.key.to_old_key(), status='Unpublished')
    expected_quota = org.task_quota_limit - 3
    actual_quota = org_logic.getRemainingTaskQuota(org)

    self.assertEqual(expected_quota, actual_quota)
예제 #3
0
    def testGetRemainingTaskQuota(self):
        """Tests if the remaining task quota that can be published by a given
    organization is correctly returned.
    """
        gci_program_helper = GCIProgramHelper()
        org = gci_program_helper.createOrg()
        org.task_quota_limit = 5
        org.put()

        mentor = profile_utils.seedNDBProfile(
            self.program.key(), mentor_for=[ndb.Key.from_old_key(org.key())])
        student = profile_utils.seedNDBStudent(self.program)

        # valid tasks.
        for _ in xrange(3):
            task_utils.seedTask(self.program,
                                org, [mentor.key.to_old_key()],
                                student=student.key.to_old_key(),
                                status=task_model.CLOSED)
            # invalid tasks.
            task_utils.seedTask(self.program,
                                org, [mentor.key.to_old_key()],
                                student=student.key.to_old_key(),
                                status='Unpublished')
        expected_quota = org.task_quota_limit - 3
        actual_quota = org_logic.getRemainingTaskQuota(org)

        self.assertEqual(expected_quota, actual_quota)
예제 #4
0
class OrganizationTest(SoCTestCase):
    """Tests the logic for GCIOrganization.
  """
    def setUp(self):
        self.init()
        self.gci_program_helper = GCIProgramHelper()
        self.program = self.gci_program_helper.createProgram()

    def testGetRemainingTaskQuota(self):
        """Tests if the remaining task quota that can be published by a given
    organization is correctly returned.
    """
        gci_program_helper = GCIProgramHelper()
        org = gci_program_helper.createOrg()
        org.task_quota_limit = 5
        org.put()

        mentor = profile_utils.seedNDBProfile(
            self.program.key(), mentor_for=[ndb.Key.from_old_key(org.key())])
        student = profile_utils.seedNDBStudent(self.program)

        # valid tasks.
        for _ in xrange(3):
            task_utils.seedTask(self.program,
                                org, [mentor.key.to_old_key()],
                                student=student.key.to_old_key(),
                                status=task_model.CLOSED)
            # invalid tasks.
            task_utils.seedTask(self.program,
                                org, [mentor.key.to_old_key()],
                                student=student.key.to_old_key(),
                                status='Unpublished')
        expected_quota = org.task_quota_limit - 3
        actual_quota = org_logic.getRemainingTaskQuota(org)

        self.assertEqual(expected_quota, actual_quota)

    def testParticipating(self):
        """Tests if a list of all the organizations participating in a given gci
    program is returned.
    """
        test_org_count = 2
        expected = []
        actual = org_logic.participating(self.program)
        self.assertEqual(expected, actual)
        org1 = self.gci_program_helper.createOrg()
        org2 = self.gci_program_helper.createNewOrg()
        # We need to clear the cache with the key given below as the first call to
        # the function being tested sets an empty cache with the same key.
        key = '%s_participating_orgs_for_%s' % (test_org_count,
                                                self.program.key().name())
        memcache.delete(key)
        expected = set([org1.key(), org2.key()])
        actual = org_logic.participating(self.gci_program_helper.program,
                                         org_count=test_org_count)
        actual = set([org.key() for org in actual])
        self.assertEqual(expected, set(actual))
예제 #5
0
class OrganizationTest(SoCTestCase):
  """Tests the logic for GCIOrganization.
  """

  def setUp(self):
    self.init()
    self.gci_program_helper = GCIProgramHelper()
    self.program = self.gci_program_helper.createProgram()

  def testGetRemainingTaskQuota(self):
    """Tests if the remaining task quota that can be published by a given
    organization is correctly returned.
    """
    gci_program_helper = GCIProgramHelper()
    org = gci_program_helper.createOrg()
    org.task_quota_limit = 5
    org.put()

    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[ndb.Key.from_old_key(org.key())])
    student = profile_utils.seedNDBStudent(self.program)

    # valid tasks.
    for _ in xrange(3):
      task_utils.seedTask(
          self.program, org, [mentor.key.to_old_key()],
          student=student.key.to_old_key(), status=task_model.CLOSED)
    # invalid tasks.
      task_utils.seedTask(
          self.program, org, [mentor.key.to_old_key()],
          student=student.key.to_old_key(), status='Unpublished')
    expected_quota = org.task_quota_limit - 3
    actual_quota = org_logic.getRemainingTaskQuota(org)

    self.assertEqual(expected_quota, actual_quota)

  def testParticipating(self):
    """Tests if a list of all the organizations participating in a given gci
    program is returned.
    """
    test_org_count = 2
    expected = []
    actual = org_logic.participating(self.program)
    self.assertEqual(expected, actual)
    org1 = self.gci_program_helper.createOrg()
    org2 = self.gci_program_helper.createNewOrg()
    # We need to clear the cache with the key given below as the first call to
    # the function being tested sets an empty cache with the same key.
    key = '%s_participating_orgs_for_%s' % (
        test_org_count, self.program.key().name())
    memcache.delete(key)
    expected = set([org1.key(), org2.key()])
    actual = org_logic.participating(
        self.gci_program_helper.program, org_count=test_org_count)
    actual = set([org.key() for org in actual])
    self.assertEqual(expected, set(actual))
예제 #6
0
class OrganizationTest(unittest.TestCase):
  """Tests the logic for GCIOrganization.
  """
  
  def setUp(self):
    self.gci_program_helper = GCIProgramHelper()
    self.program = self.gci_program_helper.createProgram()
    self.task_helper = GCITaskHelper(self.program)
  
  def testGetRemainingTaskQuota(self):
    """Tests if the remaining task quota that can be published by a given 
    organization is correctly returned.
    """
    gci_program_helper = GCIProgramHelper()
    org = gci_program_helper.createOrg()
    org.task_quota_limit = 5
    org.put()
    
    mentor = GCIProfileHelper(self.program, False).createOtherUser(
        '*****@*****.**').createMentor(org)
    
    student = GCIProfileHelper(self.program, False).createOtherUser(
        '*****@*****.**').createStudent()
    #valid tasks.
    for _ in xrange(3):
      self.task_helper.createTask('Closed', org, mentor, student)
    #invalid tasks.
    self.task_helper.createTask('Unpublished', org, mentor, student)
    expected_quota = org.task_quota_limit - 3
    actual_quota = organization_logic.getRemainingTaskQuota(org)

    self.assertEqual(expected_quota, actual_quota)

  def testParticipating(self):
    """Tests if a list of all the organizations participating in a given gci
    program is returned.
    """
    expected = []
    actual = organization_logic.participating(self.program)
    self.assertEqual(expected, actual)
    org1 = self.gci_program_helper.createOrg()
    org2 = self.gci_program_helper.createNewOrg()
    #We need to clear the cache with the key given below as the first call to
    #the function being tested sets an empty cache with the same key.
    key = 'participating_orgs_for' + self.program.key().name()
    memcache.delete(key)
    expected = set([org1.key(), org2.key()])
    actual = organization_logic.participating(self.gci_program_helper.program)
    actual = set([org.key() for org in actual])
    self.assertEqual(expected, set(actual))
예제 #7
0
class RankingTest(unittest.TestCase):
    """Tests the ranking methods for students in GCI.
  """
    def setUp(self):
        self.gci_program_helper = GCIProgramHelper()
        self.program = self.gci_program_helper.createProgram()
        self.task_helper = GCITaskHelper(self.program)
        self.student = GCIProfileHelper(self.program, False).createStudent()

    def testGetOrCreateForStudent(self):
        """Tests if an appropriate ranking object is created for a student.
    """
        #There is no GCIStudentRanking object for self.student in the datastore.
        #Hence, a new entity should be created and returned.
        q = GCIStudentRanking.all()
        q.filter('student', self.student)
        ranking = q.get()

        self.assertEqual(ranking, None)

        actual_ranking = ranking_logic.getOrCreateForStudent(self.student)
        q = GCIStudentRanking.all()
        q.filter('student', self.student)
        expected_ranking = q.get()
        self.assertEqual(expected_ranking.key(), actual_ranking.key())

        #GCIStudentRanking object already exists for a student.
        student = GCIProfileHelper(
            self.program,
            False).createOtherUser('*****@*****.**').createStudent()
        ranking = GCIStudentRanking(program=student.scope, student=student)
        ranking.put()
        actual_ranking = ranking_logic.getOrCreateForStudent(student)

        self.assertEqual(ranking.key(), actual_ranking.key())
예제 #8
0
  def init(self):
    """Performs test setup.

    Sets the following attributes:
      program_helper: a GCIProgramHelper instance
      gci/program: a GCIProgram instance
      site: a Site instance
      org: a GCIOrganization instance
      org_app: a OrgAppSurvey instance
      timeline: a GCITimelineHelper instance
      data: a GCIProfileHelper instance
    """
    from tests.program_utils import GCIProgramHelper
    from tests.timeline_utils import GCITimelineHelper
    from tests.profile_utils import GCIProfileHelper
    super(GCITestCase, self).init()
    self.program_helper = GCIProgramHelper()
    self.founder = self.program_helper.createFounder()
    self.sponsor = self.program_helper.createSponsor()
    self.gci = self.program = self.program_helper.createProgram()
    self.site = self.program_helper.createSite()
    self.org = self.program_helper.createOrg()
    self.org_app = self.program_helper.createOrgApp()
    self.timeline = GCITimelineHelper(self.gci.timeline, self.org_app)
    self.data = GCIProfileHelper(self.gci, self.dev_test)
예제 #9
0
class RankingTest(unittest.TestCase):
  """Tests the ranking methods for students in GCI.
  """

  def setUp(self):
    self.gci_program_helper = GCIProgramHelper()
    self.program = self.gci_program_helper.createProgram()
    self.task_helper = GCITaskHelper(self.program)
    self.student = GCIProfileHelper(self.program, False).createStudent()

  def testGetOrCreateForStudent(self):
    """Tests if an appropriate ranking object is created for a student.
    """
    #There is no GCIStudentRanking object for self.student in the datastore.
    #Hence, a new entity should be created and returned.
    q = GCIStudentRanking.all()
    q.filter('student', self.student)
    ranking = q.get()

    self.assertEqual(ranking, None)

    actual_ranking = ranking_logic.getOrCreateForStudent(self.student)
    q = GCIStudentRanking.all()
    q.filter('student', self.student)
    expected_ranking = q.get()
    self.assertEqual(expected_ranking.key(), actual_ranking.key())

    #GCIStudentRanking object already exists for a student.
    student = GCIProfileHelper(self.program, False).createOtherUser(
        '*****@*****.**').createStudent()
    ranking = GCIStudentRanking(program=student.scope, student=student)
    ranking.put()
    actual_ranking = ranking_logic.getOrCreateForStudent(student)

    self.assertEqual(ranking.key(), actual_ranking.key())
예제 #10
0
  def testGetRemainingTaskQuota(self):
    """Tests if the remaining task quota that can be published by a given 
    organization is correctly returned.
    """
    gci_program_helper = GCIProgramHelper()
    org = gci_program_helper.createOrg()
    org.task_quota_limit = 5
    org.put()
    
    mentor = GCIProfileHelper(self.program, False).createOtherUser(
        '*****@*****.**').createMentor(org)
    
    student = GCIProfileHelper(self.program, False).createOtherUser(
        '*****@*****.**').createStudent()
    #valid tasks.
    for _ in xrange(3):
      self.task_helper.createTask('Closed', org, mentor, student)
    #invalid tasks.
    self.task_helper.createTask('Unpublished', org, mentor, student)
    expected_quota = org.task_quota_limit - 3
    actual_quota = organization_logic.getRemainingTaskQuota(org)

    self.assertEqual(expected_quota, actual_quota)
예제 #11
0
 def setUp(self):
   self.gci_program_helper = GCIProgramHelper()
   self.program = self.gci_program_helper.createProgram()
   self.task_helper = GCITaskHelper(self.program)
예제 #12
0
 def setUp(self):
     self.init()
     self.gci_program_helper = GCIProgramHelper()
     self.program = self.gci_program_helper.createProgram()
예제 #13
0
 def setUp(self):
   self.init()
   self.gci_program_helper = GCIProgramHelper()
   self.program = self.gci_program_helper.createProgram()
예제 #14
0
 def setUp(self):
     self.gci_program_helper = GCIProgramHelper()
     self.program = self.gci_program_helper.createProgram()
     self.task_helper = GCITaskHelper(self.program)
     self.student = GCIProfileHelper(self.program, False).createStudent()
예제 #15
0
 def setUp(self):
   self.gci_program_helper = GCIProgramHelper()
   self.program = self.gci_program_helper.createProgram()
   self.task_helper = GCITaskHelper(self.program)
   self.student = GCIProfileHelper(self.program, False).createStudent()