def test004MethodsForNickname(self):
    """Tests methods for nickname"""

    # first create a user account
    user_name = 'EmmyMatsuo-' + self.postfix
    family_name = 'Matsuo'
    given_name = 'Emmy'
    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.fail('Unexpected exception occurred: %s' % e)

    self.created_user = created_user
    # tests CreateNickname method
    nickname = 'emmy-' + self.postfix
    try:
      created_nickname = self.apps_client.CreateNickname(user_name, nickname)
    except Exception, e:
      self.fail('Unexpected exception occurred: %s' % e)

    self.assert_(isinstance(created_nickname, gdata.apps.NicknameEntry),
        "Return value of CreateNickname method must be an instance of " +
        "gdata.apps.NicknameEntry: %s" % created_nickname)
    self.assertEquals(created_nickname.login.user_name, user_name)
    self.assertEquals(created_nickname.nickname.name, nickname)

    # tests RetrieveNickname method
    retrieved_nickname = self.apps_client.RetrieveNickname(nickname)
    self.assert_(isinstance(retrieved_nickname, gdata.apps.NicknameEntry),
        "Return value of RetrieveNickname method must be an instance of " +
        "gdata.apps.NicknameEntry: %s" % retrieved_nickname)
    self.assertEquals(retrieved_nickname.login.user_name, user_name)
    self.assertEquals(retrieved_nickname.nickname.name, nickname)

    # tests RetrieveNicknames method
    nickname_feed = self.apps_client.RetrieveNicknames(user_name)
    self.assert_(isinstance(nickname_feed, gdata.apps.NicknameFeed),
        "Return value of RetrieveNicknames method must be an instance of " +
        "gdata.apps.NicknameFeed: %s" % nickname_feed)
    self.assertEquals(nickname_feed.entry[0].login.user_name, user_name)
    self.assertEquals(nickname_feed.entry[0].nickname.name, nickname)

    # tests RetrieveAllNicknames method
    nickname_feed = self.apps_client.RetrieveAllNicknames()
    self.assert_(isinstance(nickname_feed, gdata.apps.NicknameFeed),
        "Return value of RetrieveAllNicknames method must be an instance of " +
        "gdata.apps.NicknameFeed: %s" % nickname_feed)
    succeed = False
    for a_entry in nickname_feed.entry:
      if a_entry.login.user_name == user_name and \
             a_entry.nickname.name == nickname:
        succeed = True
    self.assert_(succeed,
                 "There must be a nickname entry named %s." % nickname)

    # tests DeleteNickname method
    self.apps_client.DeleteNickname(nickname)
    try:
      non_existence = self.apps_client.RetrieveNickname(nickname)
    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')
dataset/ETHPy150Open kuri65536/python-for-android/python-build/python-libs/gdata/tests/gdata_tests/apps/service_test.py/AppsServiceUnitTest01.test004MethodsForNickname/original