コード例 #1
0
ファイル: test_users_backend.py プロジェクト: buskirka/pjuu
    def test_followers_and_unfollowers_pagination_sizes(self):
        """Ensure that the followers and unfollowers feeds are correct if
        changing the feed size.
        """
        users = []
        # Creae 101 users (0 - 100)
        for i in xrange(101):
            users.append(create_account('user{}'.format(i),
                                        'user{}@pjuu.com'.format(i),
                                        'Password'))

        # Make user0 follow all users and visa versa
        for i in xrange(1, 101):
            follow_user(users[0], users[i])
            follow_user(users[i], users[0])

        FEED_ITEMS_PER_PAGE = app.config.get('FEED_ITEMS_PER_PAGE')

        # Check that the correct amount of users come back for follower and
        # following
        self.assertEqual(len(get_followers(users[0]).items),
                         FEED_ITEMS_PER_PAGE)

        self.assertEqual(len(get_followers(users[0], per_page=25).items), 25)
        self.assertEqual(len(get_followers(users[0], per_page=50).items), 50)
        self.assertEqual(len(get_followers(users[0], per_page=100).items), 100)

        self.assertEqual(len(get_following(users[0]).items),
                         FEED_ITEMS_PER_PAGE)

        self.assertEqual(len(get_following(users[0], per_page=25).items), 25)
        self.assertEqual(len(get_following(users[0], per_page=50).items), 50)
        self.assertEqual(len(get_following(users[0], per_page=100).items), 100)
コード例 #2
0
ファイル: views.py プロジェクト: hnk/pjuu
def following(username):
    """Returns all users following the current user as a pagination."""
    user_id = get_uid(username)

    if user_id is None:
        abort(404)

    # Data
    _profile = get_profile(user_id)

    # Pagination
    page = handle_page(request)

    # Get a list of users you are following
    _following = get_following(user_id, page)
    # Post form
    post_form = PostForm()
    return render_template('following.html', profile=_profile,
                           pagination=_following, post_form=post_form)
コード例 #3
0
def following(username):
    """Returns all users following the current user as a pagination."""
    user_id = get_uid(username)

    if user_id is None:
        abort(404)

    # Data
    _profile = get_profile(user_id)

    # Pagination
    page = handle_page(request)

    # Get a list of users you are following
    _following = get_following(user_id, page,
                               current_user.get('feed_pagination_size'))

    return render_template('following.html',
                           profile=_profile,
                           pagination=_following)
コード例 #4
0
ファイル: test_users_backend.py プロジェクト: buskirka/pjuu
    def test_follow_unfollow_get_followers_following_is_following(self):
        """
        Test everything about following. There is not that much to it to
        deserve 3 seperate methods.
        """
        # Create two test users
        user1 = create_account('user1', '*****@*****.**', 'Password')
        user2 = create_account('user2', '*****@*****.**', 'Password')
        # Ensure is_following() is false atm
        self.assertFalse(is_following(user1, user2))
        self.assertFalse(is_following(user2, user1))
        # Ensure user 1 can follow user 2
        self.assertTrue(follow_user(user1, user2))
        # Ensure the user can't follow them again
        self.assertFalse(follow_user(user1, user2))
        # And visa-versa
        self.assertTrue(follow_user(user2, user1))
        # Ensre the user can't follow them again
        self.assertFalse(follow_user(user2, user1))
        # Ensure the id's are in the Redis sorted sets, followers and following
        self.assertIn(user2, r.zrange(k.USER_FOLLOWING.format(user1), 0, -1))
        self.assertIn(user2, r.zrange(k.USER_FOLLOWERS.format(user1), 0, -1))
        self.assertIn(user1, r.zrange(k.USER_FOLLOWING.format(user2), 0, -1))
        self.assertIn(user1, r.zrange(k.USER_FOLLOWERS.format(user2), 0, -1))
        # Ensure the get_followers and get_following functions return
        # the correct data
        self.assertEqual(len(get_following(user1).items), 1)
        self.assertEqual(len(get_following(user1).items), 1)
        self.assertEqual(len(get_following(user2).items), 1)
        self.assertEqual(len(get_following(user2).items), 1)
        # Ensure the totals are correct
        self.assertEqual(get_following(user1).total, 1)
        self.assertEqual(get_followers(user1).total, 1)
        self.assertEqual(get_following(user2).total, 1)
        self.assertEqual(get_followers(user2).total, 1)

        # Make sure is_following() returns correctly
        self.assertTrue(is_following(user1, user2))
        self.assertTrue(is_following(user2, user1))

        # User 1 unfollow user 2 and ensure the sorted sets are updated
        self.assertTrue(unfollow_user(user1, user2))
        self.assertNotIn(user2,
                         r.zrange(k.USER_FOLLOWING.format(user1), 0, -1))
        self.assertNotIn(user1,
                         r.zrange(k.USER_FOLLOWERS.format(user2), 0, -1))

        # Ensure the user can't unfollow the user again
        self.assertFalse(unfollow_user(user1, user2))
        # Ensure is_following shows correctly
        self.assertFalse(is_following(user1, user2))

        # Test what happens when we delete an account.

        # Ensure user 2 is still following user1
        self.assertTrue(is_following(user2, user1))

        # This should clean
        delete_account(user1)

        # Ensure this has cleaned user2 following list
        self.assertFalse(is_following(user2, user1))

        # Ensure get_followers and get_following return the correct value for
        # user2
        self.assertEqual(len(get_following(user2).items), 0)
        # Ensure the totals are correct
        self.assertEqual(get_following(user2).total, 0)
        self.assertEqual(get_followers(user2).total, 0)
        # Make sure is_following() returns correctly
        self.assertFalse(is_following(user1, user2))
        self.assertFalse(is_following(user2, user1))

        # I don't want to play with the above testing to much. I am adding
        # in a test for self cleaning lists. I am going to reset this test
        # case by manually flushing the Redis database :)
        r.flushdb()
        # Back to normal, I don't like artificially uping the number of tests.

        # Test the self cleaning lists in case there is an issue with Redis
        # during an account deletion. We need 2 new users.
        user1 = create_account('user1', '*****@*****.**', 'Password')
        user2 = create_account('user2', '*****@*****.**', 'Password')

        # Follow each other.
        self.assertTrue(follow_user(user1, user2))
        self.assertTrue(follow_user(user2, user1))

        # Manually delete user1
        m.db.users.remove({'_id': user1})

        # Ensure user1 appears in both user2's followers and following lists
        self.assertIn(user1, r.zrange(k.USER_FOLLOWERS.format(user2), 0, -1))
        self.assertIn(user1, r.zrange(k.USER_FOLLOWING.format(user2), 0, -1))

        # Ensure if we actuallt get the lists from the backend functions user1
        # is not there
        self.assertEqual(get_followers(user2).total, 0)
        self.assertEqual(get_following(user2).total, 0)