def test_post_get(self): """ Test for getting specific posts """ with self.client: # Create a temporary user register_user(self) login_response = login_user(self) data = json.loads(login_response.data.decode()) access_token = data["Authorization"] # Create a post create_post_response = create_post(self, access_token) create_post_response_data = json.loads( create_post_response.data.decode()) # Get that post post_public_id = create_post_response_data["post"]["public_id"] get_post_response = get_post(self, access_token, post_public_id) get_post_response_data = json.loads( get_post_response.data.decode()) # Get content for comparison original_content = create_post_response_data["post"]["content"] received_content = get_post_response_data["post"]["content"] self.assertEqual(get_post_response.status_code, 200) self.assertTrue(get_post_response_data["success"]) self.assertEqual(original_content, received_content)
def test_post_like_unlike(self): """ Test for post liking and unliking """ with self.client: # Create a mock user and login register_user(self) login_response = login_user(self) data = json.loads(login_response.data.decode()) access_token = data["Authorization"] # Post creation create_response = create_post(self, access_token) create_response_data = json.loads(create_response.data.decode()) post = create_response_data["post"] post_public_id = post["public_id"] # Like the post like_response = like_post(self, access_token, post_public_id) like_response_data = json.loads(like_response.data.decode()) self.assertEqual(like_response.status_code, 201) self.assertTrue(like_response_data["success"]) # Unlike the post unlike_response = unlike_post(self, access_token, post_public_id) unlike_response_data = json.loads(unlike_response.data.decode()) self.assertEqual(unlike_response.status_code, 200) self.assertTrue(unlike_response_data["success"])
def test_create_delete_post(self): """ Test for post creation and deletion """ with self.client: # Create a mock user and login register_user(self) login_response = login_user(self) data = json.loads(login_response.data.decode()) access_token = data["Authorization"] # Post creation create_response = create_post(self, access_token) create_response_data = json.loads(create_response.data.decode()) self.assertTrue(create_response_data["success"]) self.assertEqual(create_response.status_code, 201) # Delete the post post_public_id = create_response_data["post"]["public_id"] delete_response = delete_post(self, access_token, post_public_id) delete_response_data = json.loads(delete_response.data.decode()) self.assertTrue(delete_response_data["success"]) self.assertEqual(delete_response.status_code, 200)
def test_post_update(self): """ Test for post updating """ with self.client: # Create a mock post and update it. register_user(self) login_response = login_user(self) data = json.loads(login_response.data.decode()) access_token = data["Authorization"] # Create a post create_response = create_post(self, access_token) create_response_data = json.loads(create_response.data.decode()) # Update the post post_public_id = create_response_data["post"]["public_id"] updated_content = {"content": "Updated content"} update_response = update_post(self, updated_content, access_token, post_public_id) update_response_data = json.loads(update_response.data.decode()) # Compare data original_content = create_response_data["post"]["content"] self.assertNotEqual(original_content, updated_content) self.assertEqual(update_response.status_code, 200) self.assertTrue(update_response_data["success"])
def test_get_info(self): """ Test for getting feed information """ with self.client: # Create a mock user and login register_user(self) login_response = login_user(self) data = json.loads(login_response.data.decode()) access_token = data["Authorization"] # Post creation create_post(self, access_token) # Get the posts get_response = get_post_ids(self, access_token) get_response_data = json.loads(get_response.data.decode()) id_array = get_response_data["post_ids"] # Get post information get_post_response = get_post_information(self, access_token, id_array) get_post_response_data = json.loads( get_post_response.data.decode()) info_array = get_post_response_data["posts"] self.assertTrue(get_post_response_data["success"]) self.assertFalse(info_array[0] is None) self.assertEqual(get_post_response.status_code, 200)
def test_update_user(self): """ Test for updating the user """ with self.client: # User registration register_user(self) login_response = login_user(self) login_response_data = json.loads(login_response.data.decode()) access_token = login_response_data["Authorization"] # Update the user data updated_user = {"bio": "reEeeeEEEEEeEeeeee", "avatar": "test.png"} update_response = update_user(self, updated_user, access_token) update_response_data = json.loads(update_response.data.decode()) self.assertTrue(update_response_data["success"])
def test_get_user(self): """ Get a specific user using its public id """ with self.client: # User registration register_user(self) login_response = login_user(self) login_response_data = json.loads(login_response.data.decode()) access_token = login_response_data["Authorization"] # Get the user data username = login_response_data["user"]["username"] get_response = get_user(self, access_token, username) get_response_data = json.loads(get_response.data.decode()) self.assertEqual(get_response.status_code, 200)
def test_registered_user_login(self): """ Test for login of registered-user login """ with self.client: # User registration user_response = register_user(self) response_data = json.loads(user_response.data.decode()) self.assertEqual(user_response.status_code, 201) # Registered user login login_response = login_user(self) data = json.loads(login_response.data.decode()) self.assertTrue(data["Authorization"]) self.assertEqual(login_response.status_code, 200)
def test_create_delete_reply(self): """ Test for reply creation and deletion """ with self.client: # Create a mock user and login register_user(self) login_response = login_user(self) data = json.loads(login_response.data.decode()) access_token = data["Authorization"] # Create a mock post create_post_resp = create_post(self, access_token) create_post_resp_data = json.loads(create_post_resp.data.decode()) post_public_id = create_post_resp_data["post"]["public_id"] # Create a comment create_comment_resp = create_comment(self, access_token, post_public_id) create_comment_resp_data = json.loads( create_comment_resp.data.decode()) comment_id = create_comment_resp_data["comment"]["id"] # Create a reply create_reply_resp = create_reply(self, access_token, comment_id) create_reply_resp_data = json.loads( create_reply_resp.data.decode()) self.assertTrue(create_reply_resp_data["success"]) self.assertEqual(create_post_resp.status_code, 201) # Delete the reply reply_id = create_reply_resp_data["reply"]["id"] delete_response = delete_reply(self, access_token, reply_id) delete_response_data = json.loads(delete_response.data.decode()) self.assertTrue(delete_response_data["success"]) self.assertEqual(delete_response.status_code, 200)