def correct_response(): # Checks that the data has been updated in the users table user_data1 = main.get_user_data("new_user_name") user_data2 = main.get_user_data("new_e_mail") scen_1 = user_data1["user_name"] == user_data2["user_name"] == "new_user_name" scen_2 = user_data1["e_mail"] == user_data2["e_mail"] == "new_e_mail" scen_3 = user_data1["country"] == user_data2["country"] == "new_country" scen_4 = user_data1["city"] == user_data2["city"] == "new_city" scen_5 = user_data1["location"] == user_data2["location"] == "new_location" scen_6 = user_data1["avatar_image"] == user_data2["avatar_image"] == "new_image" scen_7 = response["response"] == "Success" users_updated = scen_1 and scen_2 and scen_3 and scen_4 and scen_5 and scen_6 and scen_7 # Checks that the data has been updated in the ideas table # Since an idea by the user who's user name has been updated # had posted an idea, the function get_most_recent_idea returns # a non-empty list when using the new user name as parameter ideas_updated = db.get_most_recent_idea("new_user_name") != [] # Checks that the data has been updated in the messages table # Since the original user has sent a message, the return value # from get conversation using the new user name and the other # user's name has to return a non-empty list messages_updated = db.get_conversation("new_user_name", "TestUser2") != [] # Checks that the data has been updated in the comments table # The user who's name was changed posted a comment on the idea with id 2 comments_updated = False for comment in db.get_comments(2): if "new_user_name" in comment: comments_updated = True return users_updated and ideas_updated and messages_updated and comments_updated
def test_get_user_data(self): with app.test_request_context(): user = TEST_USERS[0] register_user(user) user_data1 = main.get_user_data(user[0]) user_data2 = main.get_user_data(user[2]) def correct_data(): corr_user_name = user_data1["user_name"] == user_data2["user_name"] == user[0] corr_e_mail = user_data1["e_mail"] == user_data2["e_mail"] == user[2] corr_country = user_data1["country"] == user_data2["country"] == user[3] corr_city = user_data1["city"] == user_data2["city"] == user[4] corr_followers = user_data1["followers"] == user_data2["followers"] == 0 corr_location = user_data1["location"] == user_data2["location"] == "Not set" return corr_user_name and corr_e_mail and corr_country and corr_city and corr_followers and corr_location self.failIf(not correct_data())
def test_add_follower(self): with app.test_request_context(): user1 = TEST_USERS[0][0] user2 = TEST_USERS[1][0] main.add_follower(user1, user2) user_data = main.get_user_data(user1) def follower_added(): return user_data["followers"] == 1 self.failIf(not follower_added())