Exemple #1
0
 def test_edit_user_1(self):
     UserController.delete_user('nickname_3', 'email_2')
     UserController.delete_user('nickname_2', 'email_2')
     UserController.add_user(self.user_2)
     user_3 = UserController.retrieve_user('email', 'email_2')
     user_3.nickname = 'nickname_3'
     self.assertIsNot(UserController.edit_user(user_3), 'MISSING'
                      or 'DUPLICATE' or 'FAILURE')
     self.assertEqual(UserController.edit_user(user_3), 'MISSING')
     self.assertEqual(
         UserController.retrieve_user('email', 'email_2').nickname,
         'nickname_3')
     UserController.delete_user('nickname_3', 'email_2')
def update_profile(data):
    user = UserModel(0, data['name'], data['nickname'],
                     data['gender'], data['email'], data['location'],
                     stringToEnum(data['tags']), data['description'], [], [],
                     data['image'], data['google_id'])
    result = UserController.edit_user(user)
    if result == Errors.MISSING.name:
        return result, None
    elif result == Errors.FAILURE.name:
        return result, None
    else:
        user = UserController.retrieve_user(UserFields.googleid.name,
                                            data['google_id'])
        data = {
            'id': user.uid,
            'name': user.name,
            'nickname': user.nickname,
            'email': user.email,
            'location': user.location,
            'description': user.description,
            'gender': user.gender,
            'image': user.image,
            'tags': user.tags,
            'google_id': user.google_id
        }
        return 'OK', data
Exemple #3
0
def test_retrieve_hit():
    user_one = UserModel('0',
                         'chengyun yu',
                         'yuche',
                         'male',
                         '*****@*****.**',
                         '0,0',
                         'sports, dining',
                         'i am a sports guy who likes to eat. '
                         )
    user_two = UserModel('0',
                         'chengyun yu',
                         'yuche',
                         'male',
                         '*****@*****.**',
                         '0,0',
                         'sports, dining',
                         'this is my new description. '
                         )
    user_three = UserModel('0',
                           'non existent',
                           'noext',
                           'male',
                           '*****@*****.**',
                           '0.0',
                           'sports, dining',
                           'i am a sports guy who does not exist. '
                           )

    print("Insert New: " + UserController.add_user(user_one))
    print("Insert Conflict: " + UserController.add_user(user_two))
    print("Update: " + UserController.edit_user(user_two))
    print("Retrieve Hit: " + UserController.retrieve_user(UserFields.email.name, user_two.email))
    print("Retrieve Miss: " + UserController.retrieve_user(UserFields.email.name, user_three.email))
    return 'Tests Finished'
def update_profile():
    global current_user
    if not current_user:
        add_output("You have to login first! \n")
        return
    temp = UserController.retrieve_user(UserFields.email.name,
                                        current_user.email)
    if temp == Errors.MISSING.name:
        add_output("No user with such credentials exists. \n")
        return
    elif temp == Errors.FAILURE.name:
        return_failure()
        return
    user_id = current_user.uid
    current_user = read_user()
    current_user.uid = user_id

    result = UserController.edit_user(current_user)
    if result == Errors.MISSING.name:
        add_output("No user with such credentials exists. \n")
        current_user = temp
    elif result == Errors.FAILURE.name:
        return_failure()
        current_user = temp
    elif result == Errors.DUPLICATE.name:
        add_output("A user with the same credentials already exists! \n")
        current_user = temp
    else:
        add_output("User updated. Email now at: " + current_user.email +
                   ". \n")
        current_user = UserController.retrieve_user(UserFields.userid.name,
                                                    result)
    UserController.print_user(current_user)
    return