Пример #1
0
    def test_get_following(self):
        with app.test_request_context():
            user1 = TEST_USERS[0]
            user2 = TEST_USERS[1]
            user3 = TEST_USERS[2]
            user_name1 = user1[0]
            user_name2 = user2[0]
            user_name3 = user3[0]
            main.add_follower(user_name1, user_name3)
            main.add_follower(user_name2, user_name3)
            following_resp = main.get_following(user_name3)

            def correct_following():
                # Creates lists representing the data
                # of users retrieved from the database
                # when fetching a user as a follower
                stored_user1 = user1.copy()
                stored_user2 = user2.copy()
                # Removes the password from the list
                stored_user1.remove(user1[1])
                stored_user2.remove(user2[1])
                # Adds the number of followers, which in
                # this case is 1 since user3 is following
                # both user1 and user2
                stored_user1 += [1]
                stored_user1.remove("image")
                stored_user2 += [1]
                stored_user2.remove("image")
                return following_resp["following"] == [stored_user1, stored_user2]

            self.failIf(not correct_following())
Пример #2
0
    def test_is_following(self):
        with app.test_request_context():
            user1 = TEST_USERS[0][0]
            user2 = TEST_USERS[1][0]
            main.add_follower(user1, user2)
            is_following_resp = main.user_is_following(user2, user1)

            def user_is_following():
                return is_following_resp["is_following"]

            self.failIf(not user_is_following())
Пример #3
0
    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())
Пример #4
0
    def test_idea_feed_fetch(self):
        with app.test_request_context():
            user1 = TEST_USERS[0]
            user2 = TEST_USERS[1]
            post_ideas()
            # Make user1 follow user2
            main.add_follower(user2[0], user1[0])
            response = main.get_idea_feed(user1[0])

            def correct_idea_feed():
                return response["ideas"] == [STORED_TEST_IDEAS[0], STORED_TEST_IDEAS[1]]

            self.failIf(not correct_idea_feed())
Пример #5
0
    def test_other_user_idea_fetch(self):
        with app.test_request_context():
            user1 = TEST_USERS[0]
            user2 = TEST_USERS[1]
            post_ideas()
            # Make user1 follow user2
            main.add_follower(user2[0], user1[0])
            # Fetches the ideas posted by both users
            user1_response = main.get_other_user_recent_ideas(user1[0])
            user2_response = main.get_other_user_recent_ideas(user2[0])

            def correct_ideas_fetched():
                scen_1 = user1_response["ideas"] == [STORED_TEST_IDEAS[0]]
                scen_2 = user2_response["ideas"] == [STORED_TEST_IDEAS[1]]
                return scen_1 and scen_2

            self.failIf(not correct_ideas_fetched())