def run_update_task(user_key, program_key):
      """Runs the task and test that it runs correctly.

      Args:
        user_key: Key (ndb) of User.
        program_key: Key (ndb) of GCIProgram.
      """
      update_conversations.spawnUpdateConversationsTask(user_key, program_key)
      self.assertTasksInQueue(n=1, url=TASK_URL)

      for task in self.get_tasks():
        if task['url'] == TASK_URL:
          params = task['params']
          self.assertIn('user_key', params)
          self.assertEqual(params['user_key'], user_key.urlsafe())
          self.assertIn('program_key', params)
          self.assertEqual(params['program_key'], program_key.urlsafe())

      # Test task
      post_data = {
          'user_key': user_key.urlsafe(),
          'program_key': program_key.urlsafe(),
          }
      response = self.post(TASK_URL, post_data)
      self.assertEqual(response.status_code, httplib.OK)

      self.clear_task_queue()
示例#2
0
        def run_update_task(user_key, program_key):
            """Runs the task and test that it runs correctly.

      Args:
        user_key: Key (ndb) of User.
        program_key: Key (ndb) of GCIProgram.
      """
            update_conversations.spawnUpdateConversationsTask(
                user_key, program_key)
            self.assertTasksInQueue(n=1, url=TASK_URL)

            for task in self.get_tasks():
                if task['url'] == TASK_URL:
                    params = task['params']
                    self.assertIn('user_key', params)
                    self.assertEqual(params['user_key'], user_key.urlsafe())
                    self.assertIn('program_key', params)
                    self.assertEqual(params['program_key'],
                                     program_key.urlsafe())

            # Test task
            post_data = {
                'user_key': user_key.urlsafe(),
                'program_key': program_key.urlsafe(),
            }
            response = self.post(TASK_URL, post_data)
            self.assertEqual(response.status_code, httplib.OK)

            self.clear_task_queue()
示例#3
0
  def createOrgProfileFromForm(self, data):
    """Creates a new organization based on the data inserted in the form.

    Args:
      data: A RequestData describing the current request.

    Returns:
      a newly created organization entity or None
    """
    if data.organization:
      form = OrgProfileForm(data=data.POST, instance=data.organization)
    else:
      form = OrgCreateProfileForm(data=data.POST)

    if not form.is_valid():
      return None

    if not data.organization:
      org_id = data.GET['org_id']
      form.cleaned_data['scope'] = data.program
      form.cleaned_data['program'] = data.program
      form.cleaned_data['link_id'] = org_id
      key_name = '%s/%s' % (data.program.key().name(), org_id)

      # find profile of users who should be set as organization administrators
      profile_keys = []
      main_admin_key = (org_app_record_model.OrgAppRecord
          .main_admin.get_value_for_datastore(data.org_app_record))
      if main_admin_key:
        profile = profile_logic.getProfileForUsername(
            main_admin_key.name(), data.program.key())
        if profile:
          profile_keys.append(profile.key())

      backup_admin_key = (org_app_record_model.OrgAppRecord
          .backup_admin.get_value_for_datastore(data.org_app_record))
      if backup_admin_key:
        profile = profile_logic.getProfileForUsername(
            backup_admin_key.name(), data.program.key())
        if profile:
          profile_keys.append(profile.key())

      entity = createOrganizationTxn(data, profile_keys, form, key_name)

      # Update user's involved conversations
      update_conversation_task.spawnUpdateConversationsTask(
          ndb.Key.from_old_key(data.profile.user.key()),
          ndb.Key.from_old_key(data.profile.program.key()))
    else:
      entity = form.save()

    return entity
示例#4
0
    def createOrgProfileFromForm(self, data):
        """Creates a new organization based on the data inserted in the form.

    Args:
      data: A RequestData describing the current request.

    Returns:
      a newly created organization entity or None
    """
        if data.organization:
            form = OrgProfileForm(data=data.POST, instance=data.organization)
        else:
            form = OrgCreateProfileForm(data=data.POST)

        if not form.is_valid():
            return None

        if not data.organization:
            org_id = data.GET['org_id']
            form.cleaned_data['scope'] = data.program
            form.cleaned_data['program'] = data.program
            form.cleaned_data['link_id'] = org_id
            key_name = '%s/%s' % (data.program.key().name(), org_id)

            # find profile of users who should be set as organization administrators
            profile_keys = []
            main_admin_key = (org_app_record_model.OrgAppRecord.main_admin.
                              get_value_for_datastore(data.org_app_record))
            if main_admin_key:
                profile = profile_logic.getProfileForUsername(
                    main_admin_key.name(), data.program.key())
                if profile:
                    profile_keys.append(profile.key())

            backup_admin_key = (org_app_record_model.OrgAppRecord.backup_admin.
                                get_value_for_datastore(data.org_app_record))
            if backup_admin_key:
                profile = profile_logic.getProfileForUsername(
                    backup_admin_key.name(), data.program.key())
                if profile:
                    profile_keys.append(profile.key())

            entity = createOrganizationTxn(data, profile_keys, form, key_name)

            # Update user's involved conversations
            update_conversation_task.spawnUpdateConversationsTask(
                ndb.Key.from_old_key(data.profile.user.key()),
                ndb.Key.from_old_key(data.profile.program.key()))
        else:
            entity = form.save()

        return entity
 def updateConversationsForProfile(self, profile):
     update_conversations_task.spawnUpdateConversationsTask(
         ndb.Key.from_old_key(profile.parent_key()),
         ndb.Key.from_old_key(
             profile_model.Profile.program.get_value_for_datastore(
                 profile)))
 def updateConversationsForProfile(self, profile):
   update_conversations_task.spawnUpdateConversationsTask(
       ndb.Key.from_old_key(profile.parent_key()),
       ndb.Key.from_old_key(
           profile_model.Profile.program.get_value_for_datastore(profile)))