예제 #1
0
  def testProfileUpdated(self):
    """Tests that profile properties are updated properly."""
    # seed a profile
    profile = profile_utils.seedNDBProfile(self.program.key(), user=self.user)
    result = profile_logic.editProfile(
        profile.key, OTHER_TEST_PROFILE_PROPERTIES)
    self.assertTrue(result)

    # check that updated profile is persisted
    profile = result.extra.key.get()
    self.assertIsNotNone(profile)

    # check properties
    self.assertEqual(
        profile.key.id(),
        '%s/%s' % (self.program.key().name(), self.user.key.id()))
    self.assertEqual(profile.program.to_old_key(), self.program.key())
    self.assertEqual(profile.first_name, OTHER_TEST_FIRST_NAME)
    self.assertEqual(profile.last_name, OTHER_TEST_LAST_NAME)
    self.assertEqual(profile.photo_url, OTHER_TEST_PHOTO_URL)
    self.assertEqual(profile.birth_date, OTHER_TEST_BIRTH_DATE)
    self.assertEqual(profile.residential_address.street, OTHER_TEST_STREET)
    self.assertEqual(profile.residential_address.city, OTHER_TEST_CITY)
    self.assertEqual(profile.residential_address.country, OTHER_TEST_COUNTRY)
    self.assertEqual(profile.residential_address.province, OTHER_TEST_PROVINCE)
    self.assertEqual(
        profile.residential_address.postal_code, OTHER_TEST_POSTAL_CODE)
예제 #2
0
 def testProfileDoesNotExist(self):
   """Tests that error is raised when a profile does not exist."""
   result = profile_logic.editProfile(
       self.profile_key, TEST_PROFILE_PROPERTIES)
   self.assertFalse(result)
   self.assertEqual(
       result.extra,
       profile_logic.PROFILE_DOES_NOT_EXIST % self.profile_key.id())
예제 #3
0
  def post(self, data, check, mutator):
    """See base.RequestHandler.post for specification."""
    form = NotificationSettingsForm(data=data.POST)
    if form.is_valid():
      properties = form.getNotificationSettingsProperties()
      profile_properties = {
          profile_model.Profile.notification_settings._name:
              profile_logic.createtNotificationSettings(properties)
          }

      result = profile_logic.editProfile(
          data.ndb_profile.key, profile_properties)
      if not result:
        raise exception.BadRequest(message=result.extra)
      else:
        url = self.linker.program(
            data.program, self.url_names.PROFILE_NOTIFICATION_SETTINGS)
      return http.HttpResponseRedirect(url)
    else:
      # TODO(nathaniel): problematic self-call.
      return self.get(data, check, mutator)