def test003MethodsForUser(self):

    user_name = 'TakashiMatsuo-' + self.postfix
    family_name = 'Matsuo'
    given_name = 'Takashi'
    password = '123$$abc'
    suspended = 'false'

    try:
      created_user = self.apps_client.CreateUser(
        user_name=user_name, family_name=family_name, given_name=given_name,
        password=password, suspended=suspended)
    except Exception, e:
      self.assert_(False, 'Unexpected exception occurred: %s' % e)

    self.created_user = created_user
    self.assertEquals(created_user.login.user_name, user_name)
    self.assertEquals(created_user.login.suspended, suspended)
    self.assertEquals(created_user.name.family_name, family_name)
    self.assertEquals(created_user.name.given_name, given_name)

    # self.assertEquals(created_user.quota.limit,
    #                   gdata.apps.service.DEFAULT_QUOTA_LIMIT)

    """Tests RetrieveAllUsers method"""

    try:
      user_feed = self.apps_client.RetrieveAllUsers()
    except Exception, e:
      self.assert_(False, 'Unexpected exception occurred: %s' % e)

    succeed = False
    for a_entry in user_feed.entry:
      if a_entry.login.user_name == user_name:
        succeed = True
    self.assert_(succeed, 'There must be a user: %s' % user_name)

    """Tests UpdateUser method"""

    new_family_name = 'NewFamilyName'
    new_given_name = 'NewGivenName'
    new_quota = '4096'

    created_user.name.family_name = new_family_name
    created_user.name.given_name = new_given_name
    created_user.quota.limit = new_quota
    created_user.login.suspended = 'true'

    try:
      new_user_entry = self.apps_client.UpdateUser(user_name, created_user)
    except Exception, e:
      self.fail('Unexpected exception occurred: %s' % e)
    
    self.assert_(isinstance(new_user_entry, gdata.apps.UserEntry),
        "new user entry must be an instance of gdata.apps.UserEntry: %s"
        % new_user_entry)
    self.assertEquals(new_user_entry.name.family_name, new_family_name)
    self.assertEquals(new_user_entry.name.given_name, new_given_name)
    self.assertEquals(new_user_entry.login.suspended, 'true')

    # quota limit update does not always success.
    # self.assertEquals(new_user_entry.quota.limit, new_quota)

    nobody = gdata.apps.UserEntry()
    nobody.login = gdata.apps.Login(user_name='nobody-' + self.postfix)
    nobody.name = gdata.apps.Name(family_name='nobody', given_name='nobody')

    # make sure that there is no account with nobody- + self.postfix
    try:
      tmp_entry = self.apps_client.RetrieveUser('nobody-' + self.postfix)
    except gdata.apps.service.AppsForYourDomainException, e:
      self.assertEquals(e.error_code, gdata.apps.service.ENTITY_DOES_NOT_EXIST)
    except Exception, e:
      self.fail('Unexpected exception occurred: %s' % e)
    else:
      self.fail('No exception occurred')

    # make sure that UpdateUser fails with AppsForYourDomainException.
    try:
      new_user_entry = self.apps_client.UpdateUser('nobody-' + self.postfix,
                                                   nobody)
    except gdata.apps.service.AppsForYourDomainException, e:
      self.assertEquals(e.error_code, gdata.apps.service.ENTITY_DOES_NOT_EXIST)
    except Exception, e:
      self.fail('Unexpected exception occurred: %s' % e)
    else:
      self.fail('No exception occurred')

    """Tests DeleteUser method"""

    try:
      self.apps_client.DeleteUser(user_name)
    except Exception, e:
      self.assert_(False, 'Unexpected exception occurred: %s' % e)

    # make sure that the account deleted
    try:
      self.apps_client.RetrieveUser(user_name)
    except gdata.apps.service.AppsForYourDomainException, e:
      self.assertEquals(e.error_code, gdata.apps.service.ENTITY_DOES_NOT_EXIST)
    except Exception, e:
      self.fail('Unexpected exception occurred: %s' % e)
    else:
      self.fail('No exception occurred')
    self.created_user = None
      
    # make sure that DeleteUser fails with AppsForYourDomainException.
    try:
      self.apps_client.DeleteUser(user_name)
    except gdata.apps.service.AppsForYourDomainException, e:
      self.assertEquals(e.error_code, gdata.apps.service.ENTITY_DOES_NOT_EXIST)
    except Exception, e:
      self.fail('Unexpected exception occurred: %s' % e)
    else:
      self.fail('No exception occurred')
Tests methods for user
dataset/ETHPy150Open kuri65536/python-for-android/python-build/python-libs/gdata/tests/gdata_tests/apps/service_test.py/AppsServiceUnitTest01.test003MethodsForUser