def test_clear_best_friend(self, test_friends): """Test clear_best_friend().""" bill = test_friends[0] rich = test_friends[1] rich.friends.append(bill) rich.best_friend = bill assert dba.clear_best_friend(rich) assert rich.best_friend is None assert rich.best_friend_id is None
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'))
def clear_best(): """Clear your best friend.""" monkey_self = dba.get_monkey_by_id(session['id']) if not dba.clear_best_friend(monkey_self): flash('Error clearing best friend!') return redirect(request.referrer or url_for('index'))
def test_clear_best_friend_none(self): """Test clear_best_friend() with None values.""" monkey = None assert not dba.clear_best_friend(monkey)