コード例 #1
0
    def test_remove_friend_none(self, test_monkey):
        """Test remove_friend() with None values."""
        bill = None
        rich = None
        assert not dba.remove_friend(rich, bill)

        bill = test_monkey
        rich = None
        assert not dba.remove_friend(rich, bill)

        bill = None
        rich = test_monkey
        assert not dba.remove_friend(rich, bill)
コード例 #2
0
 def test_remove_friend(self, test_friends):
     """Test remove_friend()."""
     bill = test_friends[0]
     rich = test_friends[1]
     rich.friends.append(bill)
     assert bill in rich.friends
     assert rich in bill.friend_of
     assert dba.remove_friend(rich, bill)
     assert len(list(rich.friends)) == 0
     assert len(list(bill.friend_of)) == 0
コード例 #3
0
def remove(monkey_id):
    """Remove a monkey from friends."""
    monkey_self = dba.get_monkey_by_id(session['id'])
    monkey = dba.get_monkey_by_id(monkey_id)

    # Only a friend can be the best friend:
    if monkey is monkey_self.best_friend:
        if not dba.clear_best_friend(monkey_self):
            flash('Error clearing best friend!')

    if not dba.remove_friend(monkey_self, monkey):
        flash('Error removing friend!')
    return redirect(request.referrer or url_for('index'))
コード例 #4
0
ファイル: views.py プロジェクト: eugene-doe/MonkeyBook
def remove(monkey_id):
    """Remove a monkey from friends."""
    monkey_self = dba.get_monkey_by_id(session['id'])
    monkey = dba.get_monkey_by_id(monkey_id)

    # Only a friend can be the best friend:
    if monkey is monkey_self.best_friend:
        if not dba.clear_best_friend(monkey_self):
            flash('Error clearing best friend!')

    if not dba.remove_friend(monkey_self, monkey):
        flash('Error removing friend!')
    return redirect(request.referrer or url_for('index'))