Esempio n. 1
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)
Esempio n. 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)
Esempio n. 3
0
  def testDashboardAsMentorWithTask(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile = profile_utils.seedNDBProfile(
        self.program.key(), user=user,
        mentor_for=[ndb.Key.from_old_key(self.org.key())])
    task_utils.seedTask(
        self.program, self.org, [profile.key.to_old_key()])

    response = self.get(self._getDashboardUrl())
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(self._getDashboardUrl(), 1)
    self.assertIsJsonResponse(response)
    data = json.loads(response.content)
    self.assertEqual(1, len(data['data']['']))
Esempio n. 4
0
    def testDashboardAsMentorWithTask(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile = profile_utils.seedNDBProfile(
            self.program.key(),
            user=user,
            mentor_for=[ndb.Key.from_old_key(self.org.key())])
        task_utils.seedTask(self.program, self.org, [profile.key.to_old_key()])

        response = self.get(self._getDashboardUrl())
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(self._getDashboardUrl(), 1)
        self.assertIsJsonResponse(response)
        data = json.loads(response.content)
        self.assertEqual(1, len(data['data']['']))
Esempio n. 5
0
  def _testPostPublish(self, profile, initial_status, final_status, action):
    """Creates a new task with the specified initial status, performs
    a POST action and checks if the task has final status after that.

    Args:
      profile: Profile entity of the user who takes the action.
      initial_status: initial status of a task to create
      fianl_status: final status which the task should have after POST action
      action: 'publish' if the task should be published or 'unpublish'
    """
    task = task_utils.seedTask(
        self.program, self.org, [profile.key.to_old_key()],
        status=initial_status)

    data = json.dumps([{'key': str(task.key().id())}])

    if action == 'publish':
      button_id = dashboard_view.MyOrgsTaskList.PUBLISH_BUTTON_ID
    else:
      button_id = dashboard_view.MyOrgsTaskList.UNPUBLISH_BUTTON_ID

    post_data = {
        'idx': dashboard_view.MyOrgsTaskList.IDX,
        'data': data,
        'button_id': button_id
        }

    response = self.post(self._getDashboardUrl(), post_data)
    self.assertResponseOK(response)

    task = task_model.GCITask.get(task.key())
    self.assertEqual(task.status, final_status)
Esempio n. 6
0
    def _testPostPublish(self, profile, initial_status, final_status, action):
        """Creates a new task with the specified initial status, performs
    a POST action and checks if the task has final status after that.

    Args:
      profile: Profile entity of the user who takes the action.
      initial_status: initial status of a task to create
      fianl_status: final status which the task should have after POST action
      action: 'publish' if the task should be published or 'unpublish'
    """
        task = task_utils.seedTask(self.program,
                                   self.org, [profile.key.to_old_key()],
                                   status=initial_status)

        data = json.dumps([{'key': str(task.key().id())}])

        if action == 'publish':
            button_id = dashboard_view.MyOrgsTaskList.PUBLISH_BUTTON_ID
        else:
            button_id = dashboard_view.MyOrgsTaskList.UNPUBLISH_BUTTON_ID

        post_data = {
            'idx': dashboard_view.MyOrgsTaskList.IDX,
            'data': data,
            'button_id': button_id
        }

        response = self.post(self._getDashboardUrl(), post_data)
        self.assertResponseOK(response)

        task = task_model.GCITask.get(task.key())
        self.assertEqual(task.status, final_status)
Esempio n. 7
0
  def testHasTasks(self):
    """Tests profile_logic.hasTasks."""
    student_properties = {'is_student': True}
    student = seeder_logic.seed(GCIProfile, student_properties)

    # Student hasn't been assigned any task.
    self.assertFalse(profile_logic.hasTasks(student))

    mentor_properties = {'mentor_for': [self.foo_org.key()],
                         'is_mentor': True}
    foo_mentor = seeder_logic.seed(GCIProfile, mentor_properties)

    task_utils.seedTask(
        self.program, self.foo_org, [foo_mentor.key()], student=student,
        status=task_model.CLAIMED)

    # Student has been assigned one task.
    self.assertTrue(profile_logic.hasTasks(student))
  def testListLoads(self):
    """Tests that the list data loads properly."""
    # seed a couple of tasks that have been closed by the student
    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[ndb.Key.from_old_key(self.org.key())])
    for _ in range(_NUMBER_OF_TASKS):
      task_utils.seedTask(self.program, self.org, [mentor.key.to_old_key()],
          student=self.student.key.to_old_key(), status=task_model.CLOSED)

    # seed a task that is currently claimed by the student
    # it should not be included in the list of closed tasks
    task_utils.seedTask(self.program, self.org, [mentor.key.to_old_key()],
        student=self.student.key.to_old_key(), status=task_model.CLAIMED)

    response = self.getListResponse(self._taskPageUrl(), 0)
    self.assertIsJsonResponse(response)
    data = response.context['data']['']
    self.assertEqual(len(data), _NUMBER_OF_TASKS)
  def testSubscribedListAsStudent(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile = profile_utils.seedNDBStudent(self.program, user=user)

    response = self.get(_getSubscribedTasksUrl(self.program, user.user_id))
    self.assertResponseOK(response)

    for _ in range(_NUMBER_OF_SUBSCRIBED_TASKS):
      task_utils.seedTask(
          self.program, self.org, [], subscribers=[profile.key.to_old_key()])

    for _ in range(_NUMBER_OF_NON_SUBSCRIBED_TASKS):
      task_utils.seedTask(self.program, self.org, [])

    list_data = self.getListData(
        _getSubscribedTasksUrl(self.program, user.user_id), 0)
    self.assertEqual(_NUMBER_OF_SUBSCRIBED_TASKS, len(list_data))
Esempio n. 10
0
  def testPageLoads(self):
    """Tests that the page loads properly."""
    user = profile_utils.seedNDBUser(host_for=[self.program])
    profile_utils.loginNDB(user)

    # seed a couple of tasks
    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[ndb.Key.from_old_key(self.org.key())])
    for _ in range(_NUMBER_OF_TASKS):
      task_utils.seedTask(self.program, self.org, [mentor.key.to_old_key()])

    response = self.get(self.url)
    self.assertPageTemplatesUsed(response)
    self.assertResponseOK(response)

    response = self.getListResponse(self.url, 0)
    self.assertIsJsonResponse(response)
    data = response.context['data']['']
    self.assertEqual(len(data), _NUMBER_OF_TASKS)
Esempio n. 11
0
    def testSubscribedListAsStudent(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile = profile_utils.seedNDBStudent(self.program, user=user)

        response = self.get(_getSubscribedTasksUrl(self.program, user.user_id))
        self.assertResponseOK(response)

        for _ in range(_NUMBER_OF_SUBSCRIBED_TASKS):
            task_utils.seedTask(self.program,
                                self.org, [],
                                subscribers=[profile.key.to_old_key()])

        for _ in range(_NUMBER_OF_NON_SUBSCRIBED_TASKS):
            task_utils.seedTask(self.program, self.org, [])

        list_data = self.getListData(
            _getSubscribedTasksUrl(self.program, user.user_id), 0)
        self.assertEqual(_NUMBER_OF_SUBSCRIBED_TASKS, len(list_data))
Esempio n. 12
0
  def testMyOrgsTaskList(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile = profile_utils.seedNDBProfile(
        self.program.key(), user=user,
        mentor_for=[ndb.Key.from_old_key(self.org.key())])

    # create a couple of tasks
    task_utils.seedTask(
        self.program, self.org, [profile.key.to_old_key()])
    task_utils.seedTask(
        self.program, self.org, [profile.key.to_old_key()],
        status=task_model.REOPENED)

    response = self.get(self._getDashboardUrl())
    self.assertResponseOK(response)

    list_data = self.getListData(self._getDashboardUrl(),
        dashboard_view.MyOrgsTaskList.IDX)
    self.assertEqual(len(list_data), 2)
Esempio n. 13
0
    def testMyOrgsTaskList(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile = profile_utils.seedNDBProfile(
            self.program.key(),
            user=user,
            mentor_for=[ndb.Key.from_old_key(self.org.key())])

        # create a couple of tasks
        task_utils.seedTask(self.program, self.org, [profile.key.to_old_key()])
        task_utils.seedTask(self.program,
                            self.org, [profile.key.to_old_key()],
                            status=task_model.REOPENED)

        response = self.get(self._getDashboardUrl())
        self.assertResponseOK(response)

        list_data = self.getListData(self._getDashboardUrl(),
                                     dashboard_view.MyOrgsTaskList.IDX)
        self.assertEqual(len(list_data), 2)
Esempio n. 14
0
    def testHasTasks(self):
        """Tests profile_logic.hasTasks."""
        student_properties = {'is_student': True}
        student = seeder_logic.seed(GCIProfile, student_properties)

        # Student hasn't been assigned any task.
        self.assertFalse(profile_logic.hasTasks(student))

        mentor_properties = {
            'mentor_for': [self.foo_org.key()],
            'is_mentor': True
        }
        foo_mentor = seeder_logic.seed(GCIProfile, mentor_properties)

        task_utils.seedTask(self.program,
                            self.foo_org, [foo_mentor.key()],
                            student=student,
                            status=task_model.CLAIMED)

        # Student has been assigned one task.
        self.assertTrue(profile_logic.hasTasks(student))
Esempio n. 15
0
    def testPageLoads(self):
        """Tests that the page loads properly."""
        user = profile_utils.seedNDBUser(host_for=[self.program])
        profile_utils.loginNDB(user)

        # seed a couple of tasks
        mentor = profile_utils.seedNDBProfile(
            self.program.key(),
            mentor_for=[ndb.Key.from_old_key(self.org.key())])
        for _ in range(_NUMBER_OF_TASKS):
            task_utils.seedTask(self.program, self.org,
                                [mentor.key.to_old_key()])

        response = self.get(self.url)
        self.assertPageTemplatesUsed(response)
        self.assertResponseOK(response)

        response = self.getListResponse(self.url, 0)
        self.assertIsJsonResponse(response)
        data = response.context['data']['']
        self.assertEqual(len(data), _NUMBER_OF_TASKS)
Esempio n. 16
0
    def testHasCreatedOrModifiedTask(self):
        """Tests profile_logic.hasCreatedOrModifiedTask."""
        student_properties = {'is_student': True, 'scope': self.program}
        student = seeder_logic.seed(GCIProfile, student_properties)

        mentor_properties = {
            'mentor_for': [self.foo_org.key()],
            'is_mentor': True,
            'scope': self.program
        }
        foo_mentor = seeder_logic.seed(GCIProfile, mentor_properties)
        bar_mentor = seeder_logic.seed(GCIProfile, mentor_properties)

        # Task is modified and created by another mentor.
        task_utils.seedTask(self.program,
                            self.foo_org, [bar_mentor.key()],
                            student=student,
                            status=task_model.CLAIMED,
                            modified_by=bar_mentor,
                            created_by=bar_mentor)
        self.assertFalse(profile_logic.hasCreatedOrModifiedTask(foo_mentor))

        # Task is created by another mentor, but modified by given mentor.
        task_utils.seedTask(self.program,
                            self.foo_org, [bar_mentor.key()],
                            student=student,
                            status=task_model.CLAIMED,
                            modified_by=foo_mentor,
                            created_by=bar_mentor)
        self.assertTrue(profile_logic.hasCreatedOrModifiedTask(foo_mentor))

        # Task is created by the given mentor, but modified by another mentor.
        task_utils.seedTask(self.program,
                            self.foo_org, [bar_mentor.key()],
                            student=student,
                            status=task_model.CLAIMED,
                            modified_by=bar_mentor,
                            created_by=foo_mentor)
        self.assertTrue(profile_logic.hasCreatedOrModifiedTask(foo_mentor))

        # Task is modified and created by the given mentor.
        task_utils.seedTask(self.program,
                            self.foo_org, [bar_mentor.key()],
                            student=student,
                            status=task_model.CLAIMED,
                            modified_by=foo_mentor,
                            created_by=foo_mentor)

        self.assertTrue(profile_logic.hasCreatedOrModifiedTask(foo_mentor))
  def setUp(self):
    """Creates a published task for self.org.
    """
    super(TestStudentTasksForOrganizationPage, self).setUp()
    self.init()
    self.timeline_helper.tasksPubliclyVisible()

    # Create a task, status published
    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[ndb.Key.from_old_key(self.org.key())])
    self.task = task_utils.seedTask(
        self.program, self.org, mentors=[mentor.key.to_old_key()])

    self.student = profile_utils.seedSOCStudent(self.program)
Esempio n. 18
0
    def testListLoads(self):
        """Tests that the list data loads properly."""
        # seed a couple of tasks that have been closed by the student
        mentor = profile_utils.seedNDBProfile(
            self.program.key(),
            mentor_for=[ndb.Key.from_old_key(self.org.key())])
        for _ in range(_NUMBER_OF_TASKS):
            task_utils.seedTask(self.program,
                                self.org, [mentor.key.to_old_key()],
                                student=self.student.key.to_old_key(),
                                status=task_model.CLOSED)

        # seed a task that is currently claimed by the student
        # it should not be included in the list of closed tasks
        task_utils.seedTask(self.program,
                            self.org, [mentor.key.to_old_key()],
                            student=self.student.key.to_old_key(),
                            status=task_model.CLAIMED)

        response = self.getListResponse(self._taskPageUrl(), 0)
        self.assertIsJsonResponse(response)
        data = response.context['data']['']
        self.assertEqual(len(data), _NUMBER_OF_TASKS)
Esempio n. 19
0
    def setUp(self):
        """Creates a published task for self.org.
    """
        super(TestStudentTasksForOrganizationPage, self).setUp()
        self.init()
        self.timeline_helper.tasksPubliclyVisible()

        # Create a task, status published
        mentor = profile_utils.seedNDBProfile(
            self.program.key(),
            mentor_for=[ndb.Key.from_old_key(self.org.key())])
        self.task = task_utils.seedTask(self.program,
                                        self.org,
                                        mentors=[mentor.key.to_old_key()])

        self.student = profile_utils.seedSOCStudent(self.program)
Esempio n. 20
0
  def createTask(self, status=None, org=None, mentor=None, student=None):
    if not mentor:
      mentor = profile_utils.seedNDBProfile(
          self.program.key(), mentor_for=[ndb.Key.from_old_key(self.org.key())])

    if not student:
      student = profile_utils.seedNDBStudent(self.program)

    if not org:
      org = self.org

    if not status:
      status = 'Open'

    return task_utils.seedTask(
        self.program, org, [mentor.key.to_old_key()],
        student=student.key.to_old_key(), status=status)
Esempio n. 21
0
  def testHasCreatedOrModifiedTask(self):
    """Tests profile_logic.hasCreatedOrModifiedTask."""
    student_properties = {'is_student': True, 'scope': self.program}
    student = seeder_logic.seed(GCIProfile, student_properties)

    mentor_properties = {
        'mentor_for': [self.foo_org.key()],
        'is_mentor': True,
        'scope': self.program
        }
    foo_mentor = seeder_logic.seed(GCIProfile, mentor_properties)
    bar_mentor = seeder_logic.seed(GCIProfile, mentor_properties)

    # Task is modified and created by another mentor.
    task_utils.seedTask(
        self.program, self.foo_org, [bar_mentor.key()], student=student,
        status=task_model.CLAIMED, modified_by=bar_mentor,
        created_by=bar_mentor)
    self.assertFalse(profile_logic.hasCreatedOrModifiedTask(foo_mentor))

    # Task is created by another mentor, but modified by given mentor.
    task_utils.seedTask(
        self.program, self.foo_org, [bar_mentor.key()], student=student,
        status=task_model.CLAIMED, modified_by=foo_mentor,
        created_by=bar_mentor)
    self.assertTrue(profile_logic.hasCreatedOrModifiedTask(foo_mentor))

    # Task is created by the given mentor, but modified by another mentor.
    task_utils.seedTask(
        self.program, self.foo_org, [bar_mentor.key()], student=student,
        status=task_model.CLAIMED, modified_by=bar_mentor,
        created_by=foo_mentor)
    self.assertTrue(profile_logic.hasCreatedOrModifiedTask(foo_mentor))

    # Task is modified and created by the given mentor.
    task_utils.seedTask(
        self.program, self.foo_org, [bar_mentor.key()], student=student,
        status=task_model.CLAIMED, modified_by=foo_mentor,
        created_by=foo_mentor)

    self.assertTrue(profile_logic.hasCreatedOrModifiedTask(foo_mentor))
Esempio n. 22
0
    def createTask(self, status=None, org=None, mentor=None, student=None):
        if not mentor:
            mentor = profile_utils.seedNDBProfile(
                self.program.key(),
                mentor_for=[ndb.Key.from_old_key(self.org.key())])

        if not student:
            student = profile_utils.seedNDBStudent(self.program)

        if not org:
            org = self.org

        if not status:
            status = 'Open'

        return task_utils.seedTask(self.program,
                                   org, [mentor.key.to_old_key()],
                                   student=student.key.to_old_key(),
                                   status=status)
Esempio n. 23
0
def _createTestTask(program, org):
  mentor = profile_utils.seedNDBProfile(
      program.key(), mentor_for=[ndb.Key.from_old_key(org.key())])
  return task_utils.seedTask(program, org, mentors=[mentor.key.to_old_key()])