Descriptions of Unit Tests - bounswe/bounswe2024group4 GitHub Wiki

Descriptions of Unit Tests

SignUpViewTestCase

  • test_sign_up_success: Simulates a POST request to the sign-up endpoint with valid data, checks for a 200 OK response, verifies the JSON response, and confirms user creation in the database.
  • test_sign_up_email_taken: Simulates a POST request with a duplicate email, expecting a 400 Bad Request response.
  • test_sign_up_username_taken: Simulates a POST request with a duplicate username, expecting a 400 Bad Request response.

UserLoginTestCase

  • test_login_view: Sends a POST request with valid credentials to the login view, checks for a 200 OK response, and verifies the username in the JSON response.
  • test_login_view_invalid_credentials: Sends a POST request with invalid credentials, expecting a 401 Unauthorized response and an error message.

PostsTestCase

  • test_post_view: Sends a POST request to the post view, checks for a 200 OK response, and verifies that the post creation message is included in the response content.

CreateCommentTestCase

  • test_create_comment_view: Logs in the user, sends a POST request with valid comment data, verifies a 302 redirect response, checks comment creation, and ensures the comment is associated with the correct post.
  • test_create_comment_view_post_not_found: Logs in the user, sends a POST request with an invalid post ID, expecting a 404 Not Found response.

LikeOrUnlikePostTestCase

  • test_like_post: Logs in the user, sends a POST request to like a post, verifies a 200 OK response, checks the like status in the JSON response, and ensures the post is liked.
  • test_unlike_post: Sends a POST request to unlike a previously liked post, verifies a 200 OK response, checks the unlike status in the JSON response, and ensures the post is unliked.
  • test_only_post_requests_allowed: Sends a GET request to the like_or_unlike_post view, expecting a 405 Method Not Allowed response and an error message.

LikeOrUnlikeCommentTestCase

  • test_like_comment: Logs in the user, sends a POST request to like a comment, verifies a 200 OK response, checks the like status in the JSON response, and ensures the comment is liked.
  • test_unlike_comment: Sends a POST request to unlike a previously liked comment, verifies a 200 OK response, checks the unlike status in the JSON response, and ensures the comment is unliked.
  • test_only_post_requests_allowed: Sends a GET request to the like_or_unlike_comment view, expecting a 405 Method Not Allowed response and an error message.

BookmarkOrUnbookmarkPostTestCase

  • test_bookmark_post: Logs in the user, sends a POST request to bookmark a post, verifies a 200 OK response, checks the bookmark status in the JSON response, and ensures the post is bookmarked.
  • test_unbookmark_post: Sends a POST request to unbookmark a previously bookmarked post, verifies a 200 OK response, checks the unbookmark status in the JSON response, and ensures the post is unbookmarked.
  • test_only_post_requests_allowed: Sends a GET request to the bookmark_or_unbookmark_post view, expecting a 405 Method Not Allowed response and an error message.

PostDetailTestCase

  • test_post_detail: Logs in the user, sends a GET request to post_detail, verifies a 200 OK response, checks the JSON response for post details, user interactions (likes, bookmarks), and comments with their respective like statuses.

UserFollowingsTestCase

  • test_user_followings: Logs in the user, sends a GET request to user_followings, verifies a 200 OK response, and checks the JSON response for the list of followed users with their details.

UserFollowersTestCase

  • test_user_followers: Logs in the user, sends a GET request to user_followers, verifies a 200 OK response, and checks the JSON response for the list of followers with their details.

GetBookmarkedPostIdsTestCase

  • Setup User and Bookmarked Posts: Creates user and bookmarks some posts.
  • Test Get Bookmarked Post IDs: Confirms retrieving bookmarked post IDs returns the correct bookmarked posts.

ProfileViewEditAuthTestCase

  • Setup User and Post: Creates a user and a post by the user.
  • Test Profile Edit Post: Checks profile update via POST request correctly updates user details.
  • Test Profile View GET: Validates fetching profile information returns correct user data and posts.

ProfileViewEditOthersTestCase

  • Setup Multiple Users and Post: Creates multiple users, their posts, and follower relationships.
  • Test Profile View Edit Others: Ensures viewing another user's profile returns correct information including follow status.

ResetPasswordTestCase

  • Setup User: Creates a user for testing password reset functionality.
  • Test Reset Password Email: Checks password reset using email works correctly.
  • Test Reset Password Username: Verifies password reset using username works.
  • Test Reset Password Invalid User: Ensures invalid user results in 404 error.
  • Test Reset Password No Email Username: Validates missing email/username in reset request returns 400 error.
  • Test Reset Password No New Password: Confirms missing new password in reset request returns 400 error.

FollowUserTestCase

  • Setup Users: Creates a user and another user to be followed.
  • Test Follow User: Verifies user can follow another user successfully.
  • Test Follow User Self: Ensures following oneself results in 400 error.
  • Test Follow User Invalid User: Checks following a non-existent user returns 404 error.
  • Test Follow User Already Following: Confirms attempting to follow an already followed user returns 400 error.

UnfollowUserTestCase

  • Setup Users: Creates a user and another user to be followed.
  • Test Unfollow User: Verifies user can unfollow a previously followed user.
  • Test Unfollow User Not Following: Ensures unfollowing a user not followed returns 400 error.
  • Test Unfollow User Invalid User: Checks unfollowing a non-existent user returns 404 error.

FeedTestCase

  • Setup Users and Posts: Creates a user, another user to be followed, and several posts by the followed user.
  • Test Feed Authenticated User: Confirms authenticated user can retrieve feed with posts in reverse order.
  • Test Feed Unauthenticated User: Ensures unauthenticated users cannot access the feed, returns 302 error.

SearchTestCase

  • Test Search: Checks searching for a query returns correct response with player information.

PlayerViewTestCase

  • Test Player View: Verifies fetching player details returns correct information.

SessionViewTestCase

  • Test Session View: Ensures retrieving session information returns valid session key.