def test_dao_find_by_task_id(self): self.create_task_comment() # Verify that find_all_by_task_id() function is working properly task_comments = TaskCommentDAO.get_all_task_comments_by_task_id( user_id=1, task_id=1, relation_id=2)[0] task_comment = TaskCommentDAO.get_task_comment(1, 1)[0].json() self.assertEqual(task_comment, task_comments)
def test_dao_create_task_comment(self): self.create_task_comment() # Verify that task comment was inserted in database through DAO task_comment = TaskCommentDAO.get_task_comment(1, 1)[0] self.assertTrue(task_comment is not None) self.assertTrue(task_comment.id is not None) self.assertTrue(task_comment.task_id == 1) self.assertIsNotNone(task_comment.creation_date) self.assertEqual(task_comment.comment, "comment")
def test_full_task_comment_creation_api(self): non_existent_task_comment = TaskCommentDAO.get_task_comment(1, 1) self.assertEqual(non_existent_task_comment[1], 404) auth_header = get_test_request_header(self.admin_user.id) expected_response = messages.TASK_COMMENT_WAS_CREATED_SUCCESSFULLY actual_response = self.client.post( f"mentorship_relation/{self.relation_id}/task/{self.task_id}/comment", follow_redirects=True, headers=auth_header, content_type="application/json", data=json.dumps(dict(comment="comment")), ) self.assertEqual(201, actual_response.status_code) self.assertDictEqual(expected_response, json.loads(actual_response.data)) new_comment = TaskCommentDAO.get_task_comment(1, 1)[0] self.assertIsNotNone(new_comment) self.assertEqual(self.relation_id, new_comment.relation_id) self.assertEqual("comment", new_comment.comment)
def test_dao_delete_comment(self): self.create_task_comment() TaskCommentDAO.delete_comment(user_id=1, _id=1, task_id=1, relation_id=2) expected_response = messages.TASK_COMMENT_DOES_NOT_EXIST, 404 actual_response = TaskCommentDAO.get_task_comment(1, 1) # Verify that task comment was deleted self.assertEqual(expected_response, actual_response)
def test_dao_modify_comment(self): self.create_task_comment() TaskCommentDAO.modify_comment(user_id=1, _id=1, task_id=1, relation_id=2, comment="modified comment") # Verify that task comment was modified task_comment = TaskCommentDAO.get_task_comment(1, 1)[0] self.assertTrue(task_comment is not None) self.assertTrue(task_comment.id is not None) self.assertTrue(task_comment.task_id == 1) self.assertIsNotNone(task_comment.creation_date) self.assertIsNotNone(task_comment.creation_date) self.assertEqual(task_comment.comment, "modified comment")
def test_task_comment_deletion_api(self): auth_header = get_test_request_header(self.admin_user.id) expected_response = messages.TASK_COMMENT_WAS_DELETED_SUCCESSFULLY actual_response = self.client.delete( f"mentorship_relation/{self.relation_id}/task/{self.task_id}" f"/comment/{self.comment_id}", follow_redirects=True, headers=auth_header, content_type="application/json", ) self.assertEqual(200, actual_response.status_code) self.assertDictEqual(expected_response, json.loads(actual_response.data)) modified_comment = TaskCommentDAO.get_task_comment(1, 1) self.assertEqual(modified_comment[0], messages.TASK_COMMENT_DOES_NOT_EXIST) self.assertEqual(modified_comment[1], 404)
def test_full_task_comment_modification_api(self): auth_header = get_test_request_header(self.admin_user.id) expected_response = messages.TASK_COMMENT_WAS_UPDATED_SUCCESSFULLY actual_response = self.client.put( f"mentorship_relation/{self.relation_id}/task/{self.task_id}" f"/comment/{self.comment_id}", follow_redirects=True, headers=auth_header, content_type="application/json", data=json.dumps(dict(comment="Modified comment.")), ) self.assertEqual(200, actual_response.status_code) self.assertDictEqual(expected_response, json.loads(actual_response.data)) modified_comment = TaskCommentDAO.get_task_comment(1, 1)[0] self.assertIsNotNone(modified_comment) self.assertEqual(self.relation_id, modified_comment.relation_id) self.assertEqual("Modified comment.", modified_comment.comment)