示例#1
0
    def testBeforeOrgSignupStart(self):
        """Tests for beforeOrgSignupStart function."""
        # organization application has yet to start
        self.timeline_helper.org_app.survey_start = timeline_utils.future(
            delta=1)
        self.timeline_helper.org_app.survey_end = timeline_utils.future(
            delta=2)
        self.assertTrue(self.timeline_helper.beforeOrgSignupStart())

        # organization application has started
        self.timeline_helper.org_app.survey_start = timeline_utils.past(
            delta=1)
        self.timeline_helper.org_app.survey_end = timeline_utils.future(
            delta=2)
        self.assertFalse(self.timeline_helper.beforeOrgSignupStart())

        # organization application has ended
        self.timeline_helper.org_app.survey_start = timeline_utils.past(
            delta=2)
        self.timeline_helper.org_app.survey_end = timeline_utils.past(delta=1)
        self.assertFalse(self.timeline_helper.beforeOrgSignupStart())

        # no organization application is defined
        self.timeline_helper.org_app = None
        self.assertTrue(self.timeline_helper.beforeOrgSignupStart())
示例#2
0
    def setUp(self):
        sponsor = program_utils.seedSponsor()

        # seed a timeline and set student app period for now
        self.timeline = program_utils.seedTimeline(
            models=types.SOC_MODELS,
            timeline_id=TEST_PROGRAM_ID,
            sponsor_key=sponsor.key(),
            student_signup_start=timeline_utils.past(),
            student_signup_end=timeline_utils.future(delta=50),
            accepted_students_announced_deadline=timeline_utils.future(
                delta=75))

        self.program = program_utils.seedGSoCProgram(
            program_id=TEST_PROGRAM_ID,
            sponsor_key=sponsor.key(),
            timeline_key=self.timeline.key(),
            app_tasks_limit=3)

        # seed a new student info
        self.student = profile_utils.seedNDBStudent(self.program)

        # seed a new proposal
        self.proposal = proposal_utils.seedProposal(
            self.student.key,
            self.program.key(),
            status=proposal_model.STATUS_WITHDRAWN)
示例#3
0
    def testSurveyActiveWithExtension(self):
        """Tests for survey that has personal extension for the profile."""
        # survey has ended
        self.survey.survey_start = timeline_utils.past(delta=200)
        self.survey.survey_end = timeline_utils.past(delta=100)

        # seed an extension
        self.extension = survey_model.PersonalExtension(
            parent=self.profile.key, survey=self.survey_key)
        self.extension.end_date = timeline_utils.future()
        self.extension.put()

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertTrue(result)

        # survey has not started
        self.survey.survey_start = timeline_utils.future(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=200)

        # set the extension so that the survey can be accessed now
        self.extension.end_date = None
        self.extension.start_date = timeline_utils.past()

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertTrue(result)
示例#4
0
    def testSurveyHasNotStarted(self):
        """Tests for survey that has not started yet."""
        # survey has not started yet
        self.survey.survey_start = timeline_utils.future(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=200)

        result = survey_logic.hasSurveyStarted(self.survey, self.profile.key)
        self.assertFalse(result)
示例#5
0
    def testSurveyHasNotStarted(self):
        """Tests for survey that has not started yet."""
        # survey has not started yet
        self.survey.survey_start = timeline_utils.future(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=200)

        result = survey_logic.hasSurveyStarted(self.survey, self.profile.key)
        self.assertFalse(result)
示例#6
0
  def testBeforeStudentSignupAccessDenied(self):
    """Tests that access is denied before student sign-up period."""
    self.program.timeline.student_signup_start = timeline_utils.future(delta=10)
    self.program.timeline.student_signup_end = timeline_utils.future(delta=20)
    self.program.timeline.put()

    access_checker = access.StudentSignupActiveAccessChecker()
    with self.assertRaises(exception.UserError) as context:
      access_checker.checkAccess(self.data, None)
    self.assertEqual(context.exception.status, httplib.FORBIDDEN)
示例#7
0
  def testBeforeOrgSignupAccessDenied(self):
    """Tests that access is denied before organization sign-up starts."""
    self.app_survey.survey_start = timeline_utils.future(delta=100)
    self.app_survey.survey_end = timeline_utils.future(delta=150)
    self.app_survey.put()

    access_checker = access.OrgSignupActiveAccessChecker()
    with self.assertRaises(exception.UserError) as context:
      access_checker.checkAccess(self.data, None)
    self.assertEqual(context.exception.status, httplib.FORBIDDEN)
示例#8
0
    def testBeforeOrgSignupAccessDenied(self):
        """Tests that access is denied before organization sign-up starts."""
        self.app_survey.survey_start = timeline_utils.future(delta=100)
        self.app_survey.survey_end = timeline_utils.future(delta=150)
        self.app_survey.put()

        access_checker = access.OrgSignupActiveAccessChecker()
        with self.assertRaises(exception.UserError) as context:
            access_checker.checkAccess(self.data, None)
        self.assertEqual(context.exception.status, httplib.FORBIDDEN)
示例#9
0
    def testBeforeStudentSignupAccessDenied(self):
        """Tests that access is denied before student sign-up period."""
        self.program.timeline.student_signup_start = timeline_utils.future(
            delta=10)
        self.program.timeline.student_signup_end = timeline_utils.future(
            delta=20)
        self.program.timeline.put()

        access_checker = access.StudentSignupActiveAccessChecker()
        with self.assertRaises(exception.UserError) as context:
            access_checker.checkAccess(self.data, None)
        self.assertEqual(context.exception.status, httplib.FORBIDDEN)
示例#10
0
    def testSurveyHasNotStartedWithExtension(self):
        """Tests for survey that has not started even with an extension."""
        # survey has not started yet
        self.survey.survey_start = timeline_utils.future(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=200)

        # seed an extension
        self.extension = survey_model.PersonalExtension(parent=self.profile.key, survey=self.survey_key)
        self.extension.start_date = timeline_utils.future(delta=50)
        self.extension.put()

        result = survey_logic.hasSurveyStarted(self.survey, self.profile.key)
        self.assertFalse(result)
示例#11
0
  def testPreActivePeriodAccessDenied(self):
    """Tests that access is forbidden before org application is active."""
    # make org application active in the future
    self.updateOrgAppSurvey(survey_start=timeline_utils.future(delta=100),
        survey_end=timeline_utils.future(delta=150))

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(
        self.program.key(), user=user,
        admin_for=[ndb.Key.from_old_key(self.org.key())])

    response = self.get(self.take_url)
    self.assertResponseForbidden(response)
示例#12
0
    def testForBoundPeriod(self):
        """Tests state for periods with both start and end dates."""
        # set the start and end dates to the past so it is after the period
        period = survey_logic.Period(start=timeline_utils.past(), end=timeline_utils.past())
        self.assertEqual(period.state, survey_logic.POST_PERIOD_STATE)

        # set the start date to the past and the end date to the future
        # so it is in the period
        period = survey_logic.Period(start=timeline_utils.past(), end=timeline_utils.future())
        self.assertEqual(period.state, survey_logic.IN_PERIOD_STATE)

        # set the start and end dates to the past so it is before the period
        period = survey_logic.Period(start=timeline_utils.future(), end=timeline_utils.future())
        self.assertEqual(period.state, survey_logic.PRE_PERIOD_STATE)
示例#13
0
    def testSurveyHasNotStartedWithExtension(self):
        """Tests for survey that has not started even with an extension."""
        # survey has not started yet
        self.survey.survey_start = timeline_utils.future(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=200)

        # seed an extension
        self.extension = survey_model.PersonalExtension(
            parent=self.profile.key, survey=self.survey_key)
        self.extension.start_date = timeline_utils.future(delta=50)
        self.extension.put()

        result = survey_logic.hasSurveyStarted(self.survey, self.profile.key)
        self.assertFalse(result)
示例#14
0
    def testSurveyIsNotActive(self):
        """Tests for survey that is not active."""
        # check for survey that has ended
        self.survey.survey_start = timeline_utils.past(delta=200)
        self.survey.survey_end = timeline_utils.past(delta=100)

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertFalse(result)

        # check for survey that has yet to start
        self.survey.survey_start = timeline_utils.future(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=200)

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertFalse(result)
示例#15
0
    def testSurveyIsNotActive(self):
        """Tests for survey that is not active."""
        # check for survey that has ended
        self.survey.survey_start = timeline_utils.past(delta=200)
        self.survey.survey_end = timeline_utils.past(delta=100)

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertFalse(result)

        # check for survey that has yet to start
        self.survey.survey_start = timeline_utils.future(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=200)

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertFalse(result)
示例#16
0
    def testSurveyIsActive(self):
        """Tests for survey that is active."""
        self.survey.survey_start = timeline_utils.past(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=100)

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertTrue(result)
示例#17
0
    def testSurveyIsActive(self):
        """Tests for survey that is active."""
        self.survey.survey_start = timeline_utils.past(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=100)

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertTrue(result)
示例#18
0
  def testSurveyResponseTab(self):
    """Tests that survey response tab has the right URL."""
    # organization application is now
    self.org_app.survey_start = timeline_utils.past()
    self.org_app.survey_end = timeline_utils.future()
    self.org_app.put()

    data = request_data.RequestData(None, None, self.kwargs)
    tabs = soc_tabs.orgTabs(data)

    survey_response_tab = [
        tab for tab in tabs.tabs
        if tab.tab_id == soc_tabs.ORG_APP_RESPONSE_TAB_ID][0]
    self.assertEqual(
        '/gsoc/org/application/submit/%s' % self.org.key.id(),
        survey_response_tab.url)

    # organization application is complete
    self.org_app.survey_start = timeline_utils.past(delta=100)
    self.org_app.survey_end = timeline_utils.past(delta=50)
    self.org_app.put()

    data = request_data.RequestData(None, None, self.kwargs)
    tabs = soc_tabs.orgTabs(data)

    survey_response_tab = [
        tab for tab in tabs.tabs
        if tab.tab_id == soc_tabs.ORG_APP_RESPONSE_TAB_ID][0]
    self.assertEqual(
        '/gsoc/org/survey_response/show/%s' % self.org.key.id(),
        survey_response_tab.url)
示例#19
0
def seedTimeline(models=types.MELANGE_MODELS,
    timeline_id=None, sponsor_key=None, **kwargs):
  """Seeds a new timeline.

  Args:
    models: Instance of types.Models that represent appropriate models.
    timeline_id: Identifier of the new timeline.
    sponsor_key: Sponsor key to be used as scope for the timeline.

  Returns:
    Newly seeded timeline entity.
  """
  timeline_id = timeline_id or string_provider.UniqueIDProvider().getValue()

  sponsor_key = sponsor_key or seedSponsor()

  properties = {
      'key_name': '%s/%s' % (sponsor_key.name(), timeline_id),
      'link_id': timeline_id,
      'program_start': timeline_utils.past(),
      'program_end': timeline_utils.future(),
      'scope': sponsor_key,
      }
  properties.update(kwargs)
  timeline = models.timeline_model(**properties)
  timeline.put()

  return timeline
示例#20
0
  def testForNotActiveProgram(self):
    """Tests that access if denied if the program is not active."""
    data = request_data.RequestData(None, None, None)
    data._program = self.program
    data._timeline = request_data.TimelineHelper(self.program.timeline, None)

    access_checker = access.ProgramActiveAccessChecker()

    # the program is not visible
    data._program.status = program_model.STATUS_INVISIBLE
    data._program.timeline.program_start = timeline_utils.past()
    data._program.timeline.program_end = timeline_utils.future()
    with self.assertRaises(exception.UserError) as context:
      access_checker.checkAccess(data, None)
    self.assertEqual(context.exception.message,
        access._MESSAGE_PROGRAM_NOT_ACTIVE)

    # the program is has already ended
    data._program.status = program_model.STATUS_VISIBLE
    data._program.timeline.program_start = timeline_utils.past(delta=100)
    data._program.timeline.program_end = timeline_utils.past(delta=50)
    with self.assertRaises(exception.UserError) as context:
      access_checker.checkAccess(data, None)
    self.assertEqual(context.exception.message,
        access._MESSAGE_PROGRAM_NOT_ACTIVE)
示例#21
0
    def testSurveyResponseTab(self):
        """Tests that survey response tab has the right URL."""
        # organization application is now
        self.org_app.survey_start = timeline_utils.past()
        self.org_app.survey_end = timeline_utils.future()
        self.org_app.put()

        data = request_data.RequestData(None, None, self.kwargs)
        tabs = soc_tabs.orgTabs(data)

        survey_response_tab = [
            tab for tab in tabs.tabs
            if tab.tab_id == soc_tabs.ORG_APP_RESPONSE_TAB_ID
        ][0]
        self.assertEqual('/gsoc/org/application/submit/%s' % self.org.key.id(),
                         survey_response_tab.url)

        # organization application is complete
        self.org_app.survey_start = timeline_utils.past(delta=100)
        self.org_app.survey_end = timeline_utils.past(delta=50)
        self.org_app.put()

        data = request_data.RequestData(None, None, self.kwargs)
        tabs = soc_tabs.orgTabs(data)

        survey_response_tab = [
            tab for tab in tabs.tabs
            if tab.tab_id == soc_tabs.ORG_APP_RESPONSE_TAB_ID
        ][0]
        self.assertEqual(
            '/gsoc/org/survey_response/show/%s' % self.org.key.id(),
            survey_response_tab.url)
示例#22
0
    def testForNotActiveProgram(self):
        """Tests that access if denied if the program is not active."""
        data = request_data.RequestData(None, None, None)
        data._program = self.program
        data._timeline = request_data.TimelineHelper(self.program.timeline,
                                                     None)

        access_checker = access.ProgramActiveAccessChecker()

        # the program is not visible
        data._program.status = program_model.STATUS_INVISIBLE
        data._program.timeline.program_start = timeline_utils.past()
        data._program.timeline.program_end = timeline_utils.future()
        with self.assertRaises(exception.UserError) as context:
            access_checker.checkAccess(data, None)
        self.assertEqual(context.exception.message,
                         access._MESSAGE_PROGRAM_NOT_ACTIVE)

        # the program is has already ended
        data._program.status = program_model.STATUS_VISIBLE
        data._program.timeline.program_start = timeline_utils.past(delta=100)
        data._program.timeline.program_end = timeline_utils.past(delta=50)
        with self.assertRaises(exception.UserError) as context:
            access_checker.checkAccess(data, None)
        self.assertEqual(context.exception.message,
                         access._MESSAGE_PROGRAM_NOT_ACTIVE)
示例#23
0
def seedTimeline(models=types.MELANGE_MODELS,
                 timeline_id=None,
                 sponsor_key=None,
                 **kwargs):
    """Seeds a new timeline.

  Args:
    models: Instance of types.Models that represent appropriate models.
    timeline_id: Identifier of the new timeline.
    sponsor_key: Sponsor key to be used as scope for the timeline.

  Returns:
    Newly seeded timeline entity.
  """
    timeline_id = timeline_id or string_provider.UniqueIDProvider().getValue()

    sponsor_key = sponsor_key or seedSponsor()

    properties = {
        'key_name': '%s/%s' % (sponsor_key.name(), timeline_id),
        'link_id': timeline_id,
        'program_start': timeline_utils.past(),
        'program_end': timeline_utils.future(),
        'scope': sponsor_key,
    }
    properties.update(kwargs)
    timeline = models.timeline_model(**properties)
    timeline.put()

    return timeline
示例#24
0
    def testExtensionIsUpdated(self):
        """Tests that extension can be updated."""
        extension = survey_model.PersonalExtension(parent=self.profile.key,
                                                   survey=self.survey_key)
        extension.put()

        # set new dates
        start_date = timeline_utils.past()
        end_date = timeline_utils.future()
        result = survey_logic.createOrUpdatePersonalExtension(
            self.profile.key,
            self.survey.key(),
            start_date=start_date,
            end_date=end_date)

        # check that the dates are updated
        self.assertEqual(result.start_date, start_date)
        self.assertEqual(result.end_date, end_date)

        # try cleaning the dates
        result = survey_logic.createOrUpdatePersonalExtension(
            self.profile.key,
            self.survey.key(),
            start_date=None,
            end_date=None)

        # check that the dates are cleared
        self.assertIsNone(result.start_date)
        self.assertIsNone(result.end_date)
示例#25
0
    def testForBoundPeriod(self):
        """Tests state for periods with both start and end dates."""
        # set the start and end dates to the past so it is after the period
        period = survey_logic.Period(start=timeline_utils.past(),
                                     end=timeline_utils.past())
        self.assertEqual(period.state, survey_logic.POST_PERIOD_STATE)

        # set the start date to the past and the end date to the future
        # so it is in the period
        period = survey_logic.Period(start=timeline_utils.past(),
                                     end=timeline_utils.future())
        self.assertEqual(period.state, survey_logic.IN_PERIOD_STATE)

        # set the start and end dates to the past so it is before the period
        period = survey_logic.Period(start=timeline_utils.future(),
                                     end=timeline_utils.future())
        self.assertEqual(period.state, survey_logic.PRE_PERIOD_STATE)
示例#26
0
  def testDuringOrgSignupAccessGranted(self):
    """Tests that access is granted during organization sign-up period."""
    self.app_survey.survey_start = timeline_utils.past()
    self.app_survey.survey_end = timeline_utils.future()
    self.app_survey.put()

    access_checker = access.OrgSignupActiveAccessChecker()
    access_checker.checkAccess(self.data, None)
示例#27
0
    def testDuringOrgSignupAccessGranted(self):
        """Tests that access is granted during organization sign-up period."""
        self.app_survey.survey_start = timeline_utils.past()
        self.app_survey.survey_end = timeline_utils.future()
        self.app_survey.put()

        access_checker = access.OrgSignupActiveAccessChecker()
        access_checker.checkAccess(self.data, None)
示例#28
0
 def testForNoExtension(self):
     """Tests active period if there is no extension."""
     # test for survey with both start and end dates
     self.survey.survey_start = timeline_utils.past()
     self.survey.survey_end = timeline_utils.future()
     period = survey_logic.getSurveyActivePeriod(self.survey)
     self.assertEquals(period.start, self.survey.survey_start)
     self.assertEquals(period.end, self.survey.survey_end)
示例#29
0
 def testForNoExtension(self):
     """Tests active period if there is no extension."""
     # test for survey with both start and end dates
     self.survey.survey_start = timeline_utils.past()
     self.survey.survey_end = timeline_utils.future()
     period = survey_logic.getSurveyActivePeriod(self.survey)
     self.assertEquals(period.start, self.survey.survey_start)
     self.assertEquals(period.end, self.survey.survey_end)
示例#30
0
    def testAfterOrgSignupStartedAccessGranted(self):
        """Tests that access is granted after organization sign-up starts."""
        self.app_survey.survey_start = timeline_utils.past()
        self.app_survey.survey_end = timeline_utils.future()
        self.app_survey.put()

        access_checker = access.OrgSignupStartedAccessChecker()
        access_checker.checkAccess(self.data, None)
示例#31
0
    def setUp(self):
        """See unittest.TestCase.setUp for specification."""
        self.init()

        # student registration is now
        self.program.timeline.student_signup_start = timeline_utils.past()
        self.program.timeline.student_signup_end = timeline_utils.future()
        self.program.timeline.put()
示例#32
0
  def setUp(self):
    """See unittest.TestCase.setUp for specification."""
    self.init()

    # student registration is now
    self.program.timeline.student_signup_start = timeline_utils.past()
    self.program.timeline.student_signup_end = timeline_utils.future()
    self.program.timeline.put()
示例#33
0
  def testDuringStudentSignupAccessGranted(self):
    """Tests that access is granted during student sign-up period."""
    self.program.timeline.student_signup_start = timeline_utils.past(delta=10)
    self.program.timeline.student_signup_end = timeline_utils.future(delta=10)
    self.program.timeline.put()

    access_checker = access.StudentSignupActiveAccessChecker()
    access_checker.checkAccess(self.data, None)
示例#34
0
  def testAfterOrgSignupStartedAccessGranted(self):
    """Tests that access is granted after organization sign-up starts."""
    self.app_survey.survey_start = timeline_utils.past()
    self.app_survey.survey_end = timeline_utils.future()
    self.app_survey.put()

    access_checker = access.OrgSignupStartedAccessChecker()
    access_checker.checkAccess(self.data, None)
示例#35
0
 def createOrgApp(self, override=None):
   """Creates an organization application for the defined properties."""
   override = override or {}
   override.update({
       'key_name': 'gsoc_program/%s/orgapp' % self.program.key().name(),
       'survey_start': timeline_utils.past(),
       'survey_end': timeline_utils.future(),
       })
   return super(GSoCProgramHelper, self).createOrgApp(override)
示例#36
0
  def testBeforeStudentAppPeriod(self):
    # move the student app period to the future
    self.timeline.student_signup_start = timeline_utils.future()
    self.timeline.put()

    # it is not possible to submit a proposal now
    can_submit = proposal_logic.canSubmitProposal(
        self.student, self.program, self.timeline)
    self.assertFalse(can_submit)
示例#37
0
    def testForLeftUnboundPeriod(self):
        """Tests state for periods with no start date."""
        # set the end of period to the past so the period is already over
        period = survey_logic.Period(end=timeline_utils.past())
        self.assertEqual(period.state, survey_logic.POST_PERIOD_STATE)

        # set the end of period to the future so we are currently in
        period = survey_logic.Period(end=timeline_utils.future())
        self.assertEqual(period.state, survey_logic.IN_PERIOD_STATE)
示例#38
0
    def testForRightUnboundPeriod(self):
        """Tests state for periods with no end date."""
        # set the start of period to the past so that we are currently in
        period = survey_logic.Period(start=timeline_utils.past())
        self.assertEqual(period.state, survey_logic.IN_PERIOD_STATE)

        # set the start of period to the future so that is has yet to start
        period = survey_logic.Period(start=timeline_utils.future())
        self.assertEqual(period.state, survey_logic.PRE_PERIOD_STATE)
示例#39
0
    def testForRightUnboundPeriod(self):
        """Tests state for periods with no end date."""
        # set the start of period to the past so that we are currently in
        period = survey_logic.Period(start=timeline_utils.past())
        self.assertEqual(period.state, survey_logic.IN_PERIOD_STATE)

        # set the start of period to the future so that is has yet to start
        period = survey_logic.Period(start=timeline_utils.future())
        self.assertEqual(period.state, survey_logic.PRE_PERIOD_STATE)
示例#40
0
    def testForLeftUnboundPeriod(self):
        """Tests state for periods with no start date."""
        # set the end of period to the past so the period is already over
        period = survey_logic.Period(end=timeline_utils.past())
        self.assertEqual(period.state, survey_logic.POST_PERIOD_STATE)

        # set the end of period to the future so we are currently in
        period = survey_logic.Period(end=timeline_utils.future())
        self.assertEqual(period.state, survey_logic.IN_PERIOD_STATE)
示例#41
0
    def testForExtensionWithStartAndEndDate(self):
        """Tests active period if there is an extension with start and end date."""
        self.survey.survey_start = timeline_utils.past(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=100)

        # test for an extension that is within the survey period
        self.extension.start_date = self.survey.survey_start + timedelta(1)
        self.extension.end_date = self.survey.survey_end - timedelta(1)

        # active period should be the same as for the survey
        period = survey_logic.getSurveyActivePeriod(self.survey,
                                                    self.extension)
        self.assertEquals(period.start, self.survey.survey_start)
        self.assertEquals(period.end, self.survey.survey_end)

        # test for an extension which is a superset of the survey
        self.extension.start_date = self.survey.survey_start - timedelta(1)
        self.extension.end_date = self.survey.survey_end + timedelta(1)

        # active period should be the same as for the extension
        period = survey_logic.getSurveyActivePeriod(self.survey,
                                                    self.extension)
        self.assertEquals(period.start, self.extension.start_date)
        self.assertEquals(period.end, self.extension.end_date)

        # test for an extension which starts earlier than the survey and ends
        # before the survey ends
        self.extension.start_date = self.survey.survey_start - timedelta(1)
        self.extension.end_date = self.survey.survey_end - timedelta(1)

        # active period should start as extension starts and ends as survey ends
        period = survey_logic.getSurveyActivePeriod(self.survey,
                                                    self.extension)
        self.assertEquals(period.start, self.extension.start_date)
        self.assertEquals(period.end, self.survey.survey_end)

        # test for an extension which starts after than the survey and ends
        # before the survey ends
        self.extension.start_date = self.survey.survey_start + timedelta(1)
        self.extension.end_date = self.survey.survey_end + timedelta(1)

        # active period should start when survey starts and end when extension ends
        period = survey_logic.getSurveyActivePeriod(self.survey,
                                                    self.extension)
        self.assertEquals(period.start, self.survey.survey_start)
        self.assertEquals(period.end, self.extension.end_date)

        # test for an extension that does not overlap with the survey dates
        self.extension.start_date = self.survey.survey_start - timedelta(10)
        self.extension.end_date = self.survey.survey_start - timedelta(5)

        # active period should span between extension start and survey end
        period = survey_logic.getSurveyActivePeriod(self.survey,
                                                    self.extension)
        self.assertEquals(period.start, self.extension.start_date)
        self.assertEquals(period.end, self.survey.survey_end)
示例#42
0
  def testBeforeOrgsAnnouncedAccessDenied(self):
    """Tests that access is denied before orgs are announced."""
    self.program.timeline.accepted_organization_announced_deadline = (
        timeline_utils.future())
    self.program.timeline.put()

    access_checker = access.OrgsAnnouncedAccessChecker()
    with self.assertRaises(exception.UserError) as context:
      access_checker.checkAccess(self.data, None)
    self.assertEqual(context.exception.status, httplib.FORBIDDEN)
示例#43
0
    def testBeforeStudentSignUp(self):
        """Tests that correct message is returned before student sign-up."""
        self.program.timeline.student_signup_start = timeline_utils.future()
        self.program.timeline.put()

        message = top_message.orgMemberRegistrationTopMessage(self.data)
        self.assertEqual(
            message._message,
            top_message._ORG_MEMBER_REGISTER_MESSAGE_BEFORE_STUDENT_SIGN_UP %
            self.program.timeline.student_signup_start)
示例#44
0
  def testBeforeStudentSignUp(self):
    """Tests that correct message is returned before student sign-up."""
    self.program.timeline.student_signup_start = timeline_utils.future()
    self.program.timeline.put()

    message = top_message.orgMemberRegistrationTopMessage(self.data)
    self.assertEqual(
        message._message,
        top_message._ORG_MEMBER_REGISTER_MESSAGE_BEFORE_STUDENT_SIGN_UP %
            self.program.timeline.student_signup_start)
示例#45
0
    def testBeforeStudentAppPeriod(self):
        # move the student app period to the future
        self.timeline.student_signup_start = timeline_utils.future()
        self.timeline.put()

        # it is not possible to submit a proposal now
        can_submit = proposal_logic.canSubmitProposal(self.student,
                                                      self.program,
                                                      self.timeline)
        self.assertFalse(can_submit)
示例#46
0
    def testDuringStudentSignupAccessGranted(self):
        """Tests that access is granted during student sign-up period."""
        self.program.timeline.student_signup_start = timeline_utils.past(
            delta=10)
        self.program.timeline.student_signup_end = timeline_utils.future(
            delta=10)
        self.program.timeline.put()

        access_checker = access.StudentSignupActiveAccessChecker()
        access_checker.checkAccess(self.data, None)
示例#47
0
    def testBeforeOrgsAnnouncedAccessDenied(self):
        """Tests that access is denied before orgs are announced."""
        self.program.timeline.accepted_organization_announced_deadline = (
            timeline_utils.future())
        self.program.timeline.put()

        access_checker = access.OrgsAnnouncedAccessChecker()
        with self.assertRaises(exception.UserError) as context:
            access_checker.checkAccess(self.data, None)
        self.assertEqual(context.exception.status, httplib.FORBIDDEN)
示例#48
0
  def testBeforeOrgSignupStart(self):
    """Tests for beforeOrgSignupStart function."""
    # organization application has yet to start
    self.timeline_helper.org_app.survey_start = timeline_utils.future(delta=1)
    self.timeline_helper.org_app.survey_end = timeline_utils.future(delta=2)
    self.assertTrue(self.timeline_helper.beforeOrgSignupStart())

    # organization application has started
    self.timeline_helper.org_app.survey_start = timeline_utils.past(delta=1)
    self.timeline_helper.org_app.survey_end = timeline_utils.future(delta=2)
    self.assertFalse(self.timeline_helper.beforeOrgSignupStart())

    # organization application has ended
    self.timeline_helper.org_app.survey_start = timeline_utils.past(delta=2)
    self.timeline_helper.org_app.survey_end = timeline_utils.past(delta=1)
    self.assertFalse(self.timeline_helper.beforeOrgSignupStart())

    # no organization application is defined
    self.timeline_helper.org_app = None
    self.assertTrue(self.timeline_helper.beforeOrgSignupStart())
示例#49
0
 def getOrgAppCreatePostData(self):
   """Returns the post data dictionary for creating or editing org app."""
   time_fmt = '%Y-%m-%d %H:%M:%S'
   return {
       'title': 'GSoC Org App',
       'short_name': 'GSoCOA',
       'content': 'Organization application for GSoC',
       'survey_start': timeline_utils.past().strftime(time_fmt),
       'survey_end': timeline_utils.future().strftime(time_fmt),
       'schema': json.dumps(ORG_APP_SCHEMA),
       }
示例#50
0
 def createOrgApp(self, override=None):
     """Creates an organization application for the defined properties."""
     override = override or {}
     override.update({
         'key_name':
         'gsoc_program/%s/orgapp' % self.program.key().name(),
         'survey_start':
         timeline_utils.past(),
         'survey_end':
         timeline_utils.future(),
     })
     return super(GSoCProgramHelper, self).createOrgApp(override)
示例#51
0
  def setUp(self):
    sponsor = program_utils.seedSponsor()

    # seed a timeline and set student app period for now
    self.timeline = program_utils.seedTimeline(
        models=types.SOC_MODELS, timeline_id=TEST_PROGRAM_ID,
        sponsor_key=sponsor.key(), student_signup_start=timeline_utils.past(),
        student_signup_end=timeline_utils.future(delta=50),
        accepted_students_announced_deadline=timeline_utils.future(delta=75))

    self.program = program_utils.seedGSoCProgram(
        program_id=TEST_PROGRAM_ID, sponsor_key=sponsor.key(),
        timeline_key=self.timeline.key(), app_tasks_limit=3)

    # seed a new student info
    self.student = profile_utils.seedNDBStudent(self.program)

    # seed a new proposal
    self.proposal = proposal_utils.seedProposal(
        self.student.key, self.program.key(),
        status=proposal_model.STATUS_WITHDRAWN)
示例#52
0
    def testForExtensionWithStartAndEndDate(self):
        """Tests active period if there is an extension with start and end date."""
        self.survey.survey_start = timeline_utils.past(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=100)

        # test for an extension that is within the survey period
        self.extension.start_date = self.survey.survey_start + timedelta(1)
        self.extension.end_date = self.survey.survey_end - timedelta(1)

        # active period should be the same as for the survey
        period = survey_logic.getSurveyActivePeriod(self.survey, self.extension)
        self.assertEquals(period.start, self.survey.survey_start)
        self.assertEquals(period.end, self.survey.survey_end)

        # test for an extension which is a superset of the survey
        self.extension.start_date = self.survey.survey_start - timedelta(1)
        self.extension.end_date = self.survey.survey_end + timedelta(1)

        # active period should be the same as for the extension
        period = survey_logic.getSurveyActivePeriod(self.survey, self.extension)
        self.assertEquals(period.start, self.extension.start_date)
        self.assertEquals(period.end, self.extension.end_date)

        # test for an extension which starts earlier than the survey and ends
        # before the survey ends
        self.extension.start_date = self.survey.survey_start - timedelta(1)
        self.extension.end_date = self.survey.survey_end - timedelta(1)

        # active period should start as extension starts and ends as survey ends
        period = survey_logic.getSurveyActivePeriod(self.survey, self.extension)
        self.assertEquals(period.start, self.extension.start_date)
        self.assertEquals(period.end, self.survey.survey_end)

        # test for an extension which starts after than the survey and ends
        # before the survey ends
        self.extension.start_date = self.survey.survey_start + timedelta(1)
        self.extension.end_date = self.survey.survey_end + timedelta(1)

        # active period should start when survey starts and end when extension ends
        period = survey_logic.getSurveyActivePeriod(self.survey, self.extension)
        self.assertEquals(period.start, self.survey.survey_start)
        self.assertEquals(period.end, self.extension.end_date)

        # test for an extension that does not overlap with the survey dates
        self.extension.start_date = self.survey.survey_start - timedelta(10)
        self.extension.end_date = self.survey.survey_start - timedelta(5)

        # active period should span between extension start and survey end
        period = survey_logic.getSurveyActivePeriod(self.survey, self.extension)
        self.assertEquals(period.start, self.extension.start_date)
        self.assertEquals(period.end, self.survey.survey_end)
示例#53
0
  def testForActiveProgram(self):
    """Tests that access is granted if the program is active."""

    data = request_data.RequestData(None, None, None)
    data._program = self.program
    data._timeline = request_data.TimelineHelper(self.program.timeline, None)

    access_checker = access.ProgramActiveAccessChecker()

    # program is active and visible
    data._program.status = program_model.STATUS_VISIBLE
    data._program.timeline.program_start = timeline_utils.past()
    data._program.timeline.program_end = timeline_utils.future()
    access_checker.checkAccess(data, None)
示例#54
0
    def testSurveyNotActiveWithExtension(self):
        """Tests that the survey is not active even with extension."""
        # survey has ended
        self.survey.survey_start = timeline_utils.past(delta=200)
        self.survey.survey_end = timeline_utils.past(delta=100)

        # seed an extension that also has ended
        self.extension = survey_model.PersonalExtension(parent=self.profile.key, survey=self.survey_key)
        self.extension.end_date = timeline_utils.past()
        self.extension.put()

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertFalse(result)

        # survey has not started, neither the extension
        self.survey.survey_start = timeline_utils.future(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=200)

        self.extension.end_date = None
        self.extension.start_date = timeline_utils.future()

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertFalse(result)
示例#55
0
  def setUp(self):
    sponsor = program_utils.seedSponsor()

    # seed a timeline and set student app period for now
    self.timeline = program_utils.seedTimeline(
        models=types.SOC_MODELS, timeline_id=TEST_PROGRAM_ID,
        sponsor_key=sponsor.key(), student_signup_start=timeline_utils.past(),
        student_signup_end=timeline_utils.future())

    self.program = program_utils.seedGSoCProgram(
        program_id=TEST_PROGRAM_ID, sponsor_key=sponsor.key(),
        timeline_key=self.timeline.key(), app_tasks_limit=3)

    self.student = profile_utils.seedNDBStudent(self.program)
示例#56
0
    def testSurveyHasStarted(self):
        """Tests for survey that has already started."""
        # survey is in active state
        self.survey.survey_start = timeline_utils.past(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=100)

        result = survey_logic.hasSurveyStarted(self.survey, self.profile.key)
        self.assertTrue(result)

        # survey has already ended
        self.survey.survey_start = timeline_utils.past(delta=200)
        self.survey.survey_end = timeline_utils.past(delta=100)

        result = survey_logic.hasSurveyStarted(self.survey, self.profile.key)
        self.assertTrue(result)
示例#57
0
    def testSurveyNotActiveWithExtension(self):
        """Tests that the survey is not active even with extension."""
        # survey has ended
        self.survey.survey_start = timeline_utils.past(delta=200)
        self.survey.survey_end = timeline_utils.past(delta=100)

        # seed an extension that also has ended
        self.extension = survey_model.PersonalExtension(
            parent=self.profile.key, survey=self.survey_key)
        self.extension.end_date = timeline_utils.past()
        self.extension.put()

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertFalse(result)

        # survey has not started, neither the extension
        self.survey.survey_start = timeline_utils.future(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=200)

        self.extension.end_date = None
        self.extension.start_date = timeline_utils.future()

        result = survey_logic.isSurveyActive(self.survey, self.profile.key)
        self.assertFalse(result)
示例#58
0
    def testSurveyHasStarted(self):
        """Tests for survey that has already started."""
        # survey is in active state
        self.survey.survey_start = timeline_utils.past(delta=100)
        self.survey.survey_end = timeline_utils.future(delta=100)

        result = survey_logic.hasSurveyStarted(self.survey, self.profile.key)
        self.assertTrue(result)

        # survey has already ended
        self.survey.survey_start = timeline_utils.past(delta=200)
        self.survey.survey_end = timeline_utils.past(delta=100)

        result = survey_logic.hasSurveyStarted(self.survey, self.profile.key)
        self.assertTrue(result)
示例#59
0
    def testForActiveProgram(self):
        """Tests that access is granted if the program is active."""

        data = request_data.RequestData(None, None, None)
        data._program = self.program
        data._timeline = request_data.TimelineHelper(self.program.timeline,
                                                     None)

        access_checker = access.ProgramActiveAccessChecker()

        # program is active and visible
        data._program.status = program_model.STATUS_VISIBLE
        data._program.timeline.program_start = timeline_utils.past()
        data._program.timeline.program_end = timeline_utils.future()
        access_checker.checkAccess(data, None)
示例#60
0
    def testDuringStudentSignUp(self):
        """Tests that correct message is returned during student sign-up."""
        self.program.timeline.student_signup_start = timeline_utils.past()
        self.program.timeline.student_signup_end = timeline_utils.future()
        self.program.timeline.put()

        message = top_message.orgMemberRegistrationTopMessage(self.data)

        # TODO(daniel): host should be obtained dynamically.
        register_url = (
            'http://some.testing.host.tld/gsoc/profile/register/student/%s' %
            self.program.key().name())
        self.assertEqual(
            message._message,
            top_message._ORG_MEMBER_REGISTER_MESSAGE_ACTIVE_STUDENT_SIGN_UP %
            register_url)