Beispiel #1
0
    def test_approved_unapproved_is_approved(self):
        """Ensure a user can approve and unapprove a follower. Also test the
        checking of this state"""
        user1 = create_account('user1', '*****@*****.**', 'Password')
        user2 = create_account('user2', '*****@*****.**', 'Password')
        user3 = create_account('user3', '*****@*****.**', 'Password')

        # User should not be following a user
        self.assertFalse(is_approved(user1, user2))

        # User can't approve a user he is not following
        self.assertFalse(approve_user(user1, user2))

        # Follow wrong way round. The user to be approved must follow you
        follow_user(user1, user2)
        self.assertFalse(approve_user(user1, user2))
        self.assertFalse(is_approved(user1, user2))

        # Correct way round
        follow_user(user2, user1)
        self.assertTrue(approve_user(user1, user2))
        self.assertTrue(is_approved(user1, user2))

        # Try an un-approved a non follower
        self.assertFalse(is_approved(user1, user3))
        self.assertFalse(unapprove_user(user1, user3))

        # Try and un-approve a non approved follower
        follow_user(user3, user1)
        self.assertFalse(is_approved(user1, user3))
        self.assertFalse(unapprove_user(user1, user3))

        # Un-approve an approved folloer
        self.assertTrue(is_approved(user1, user2))
        self.assertTrue(unapprove_user(user1, user2))
        self.assertFalse(is_approved(user1, user2))

        # Ensure a user is un-approved if they stop following you
        # and you had approved them
        self.assertTrue(approve_user(user1, user2))
        self.assertTrue(is_approved(user1, user2))
        unfollow_user(user2, user1)
        self.assertFalse(is_approved(user1, user2))
Beispiel #2
0
def unapprove(username):
    """Unfollow a user"""
    redirect_url = handle_next(request, url_for('users.followers',
                               username=current_user.get('username')))

    user_id = get_uid(username)

    # If we don't get a uid from the username the page doesn't exist
    if user_id is None:
        abort(404)

    if user_id != current_user.get('_id'):
        if unapprove_user(current_user.get('_id'), user_id):
            flash('You have untrusted %s' % username, 'success')
        else:
            flash('You can\'t untrust a user who is not trusted',
                  'error')
    else:
        flash('You can\'t untrust your self', 'information')

    return redirect(redirect_url)
Beispiel #3
0
def unapprove(username):
    """Unfollow a user"""
    redirect_url = handle_next(
        request,
        url_for('users.followers', username=current_user.get('username')))

    user_id = get_uid(username)

    # If we don't get a uid from the username the page doesn't exist
    if user_id is None:
        abort(404)

    if user_id != current_user.get('_id'):
        if unapprove_user(current_user.get('_id'), user_id):
            flash('You have untrusted %s' % username, 'success')
        else:
            flash('You can\'t untrust a user who is not trusted', 'error')
    else:
        flash('You can\'t untrust your self', 'information')

    return redirect(redirect_url)