Conversation
…ute to pass tests
nancy-harris
reviewed
Dec 2, 2022
nancy-harris
left a comment
There was a problem hiding this comment.
Excellent job! Your code overall is great! There are a few comments below on ways to make the code easier to read, but otherwise you did a great job!
| @@ -2,4 +2,29 @@ | |||
|
|
|||
|
|
|||
| class Task(db.Model): | |||
|
|
||
| tasks_bp = Blueprint("tasks", __name__, url_prefix="/tasks") | ||
|
|
||
| @tasks_bp.route("", methods=["POST", "GET"]) |
There was a problem hiding this comment.
It would be a good idea to separate "POST" and "GET". Putting them together makes the function really long and harder to read since everything is indented an extra level because of the if statement to distinguish between POST and GET.
| elif request.method == "GET": | ||
| sort_by_query = request.args.get('sort') | ||
|
|
||
| tasks = Task.query.all() |
There was a problem hiding this comment.
It would be a good idea to have this as the else that comes at the end of the if statement that starts on line 33. The way it's done now, all of the tasks are pulled twice if there's a sort to do.
Comment on lines
+12
to
+25
| request_body = request.get_json() | ||
|
|
||
| try: | ||
| task = Task(title = request_body['title'], description = request_body['description']) | ||
| except KeyError: | ||
| invalid_dict = {"details": "Invalid data"} | ||
| return make_response(jsonify(invalid_dict),400) | ||
|
|
||
| db.session.add(task) | ||
| db.session.commit() | ||
|
|
||
| response_body = {"task": task.to_dict()} | ||
|
|
||
| return make_response(jsonify(response_body), 201) |
|
|
||
| return make_response({"details": f'Task {task.task_id} ' f'"{task.title}"' ' successfully deleted'}, 200) | ||
|
|
||
| def validate_model_id(cls,task_id): |
| assert response.status_code == 404 | ||
|
|
||
| raise Exception("Complete test with assertion about response body") | ||
| assert response_body == {"message":"Task 1 not found"} |
|
|
||
| raise Exception("Complete test with assertion about response body") | ||
| # ***************************************************************** | ||
| assert response_body == {"message":"Task 1 not found"} |
| assert response.status_code == 404 | ||
|
|
||
| raise Exception("Complete test with assertion about response body") | ||
| assert response_body == {"message":"Task 1 not found"} |
| assert response.status_code == 404 | ||
|
|
||
| raise Exception("Complete test with assertion about response body") | ||
| assert response_body == {"message": "Task 1 not found"} |
| assert response.status_code == 404 | ||
|
|
||
| raise Exception("Complete test with assertion about response body") | ||
| assert response_body == {"message": "Task 1 not found"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.