def profile(monkey_id): """Display a monkey's profile, own or not.""" monkey_self = dba.get_monkey_by_id(session['id']) if monkey_self is None: return redirect(url_for('index')) # This condition avoids running a second query when viewing own # profile: if monkey_id == session['id']: # Viewing your own profile monkey = monkey_self else: # Viewing somebody else's profile monkey = dba.get_monkey_by_id(monkey_id) if monkey: profile = dba.get_monkey_profile(monkey) else: # Non-existent id in the URL return redirect(url_for('index')) return render_template('profile.html', monkey=monkey, monkey_self=monkey_self, mutual_friends=profile['mutual_friends'], other_friends=profile['other_friends'], also_friend_of=profile['also_friend_of'])
def test_get_monkey_profile(self, test_monkey): """Test get_monkey_profile().""" monkey = test_monkey profile = dba.get_monkey_profile(monkey) assert 'mutual_friends' in profile assert 'other_friends' in profile assert 'also_friend_of' in profile