def test_get_profile(self): """ Tests that a user's profile representation can be returned """ # Get test user user1 = create_account('user1', '*****@*****.**', 'Password') # Attempt to get the users repr profile = get_profile(user1) # Ensure we got a profile self.assertIsNotNone(profile) # Check all the keys are present self.assertEqual(profile.get('_id'), user1) self.assertEqual(profile.get('username'), 'user1') self.assertEqual(profile.get('email'), '*****@*****.**') # Ensure all the injected information is present self.assertEqual(profile.get('post_count'), 0) self.assertEqual(profile.get('followers_count'), 0) self.assertEqual(profile.get('following_count'), 0) # Ensure a non-existant profile return None self.assertEqual(get_profile(k.NIL_VALUE), None)
def profile(username): """It will show the users posts. Referred to as "posts" on the site.""" uid = get_uid_username(username) if uid is None: abort(404) # Data _profile = get_profile(uid) # Pagination page = handle_page(request) # Get the posts pagination pagination = get_posts(uid, page) # Post form post_form = PostForm() return render_template('posts.html', profile=_profile, pagination=pagination, post_form=post_form)
def followers(username): """Returns all a users followers as a pagination object.""" 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 _followers = get_followers(user_id, page) # Post form post_form = PostForm() return render_template('followers.html', profile=_profile, pagination=_followers, post_form=post_form)
def followers(username): """Returns all a users followers as a pagination object.""" 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 _followers = get_followers(user_id, page, current_user.get('feed_pagination_size')) return render_template('followers.html', profile=_profile, pagination=_followers)
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')) # Post form post_form = PostForm() return render_template('following.html', profile=_profile, pagination=_following, post_form=post_form)
def profile(username): """It will show the users posts. Referred to as "posts" on the site. .. note: Viewable to public! (Only public posts) """ uid = get_uid_username(username) if uid is None: abort(404) # Data _profile = get_profile(uid) # Pagination page = handle_page(request) # Get the page sizes taking in to account non-logged in users if current_user: page_size = current_user.get('feed_pagination_size', app.config.get('FEED_ITEMS_PER_PAGE', 25)) else: page_size = app.config.get('FEED_ITEMS_PER_PAGE', 25) # Get the posts pagination if current_user: current_user_id = current_user.get('_id') else: current_user_id = None permission = get_user_permission(_profile.get('_id'), current_user_id) _posts = get_posts(uid, page, page_size, perm=permission) # Post form post_form = PostForm() return render_template('posts.html', profile=_profile, pagination=_posts, post_form=post_form)