Skip to content

Spruce - Ngozi Amaefule#84

Open
ngoziamaefule wants to merge 4 commits intoAda-C16:masterfrom
ngoziamaefule:master
Open

Spruce - Ngozi Amaefule#84
ngoziamaefule wants to merge 4 commits intoAda-C16:masterfrom
ngoziamaefule:master

Conversation

@ngoziamaefule
Copy link

No description provided.

Copy link

@audreyandoy audreyandoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ngozi! You hit all the learning goals and passed all the tests. You did a great job practicing the single responsibility principle for your goal routes and organizing your code neatly.

I added comments to your PR for ways to refactor, use helper methods, and list comprehension.

Great work! You definitely earned 🟢 on this project :)

Comment on lines +7 to +8
title = db.Column(db.String)
tasks = db.relationship('Task', backref='goal', lazy=True) No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to store goals with a NULL title? Consider setting nullable=False to ensure every goal requires a title.

Comment on lines +8 to +10
title = db.Column(db.String)
description = db.Column(db.String)
completed_at = db.Column(db.DateTime, nullable=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our tests don't confirm this, but should tasks be able to store NULL titles and descriptions?

All columns are nullable by default, so we can remove the nullable = True attribute from the completed_at column and it will work the same way.

from flask import Blueprint
import re
from flask import Blueprint, jsonify, request
from flask.helpers import make_response

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not using make_response anywhere else in this file so we can omit this import.

"id": new_task.task_id,
"title": new_task.title,
"description": new_task.description,
"is_complete": new_task.completed_at is not None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Great use the not operator to determine the value of is_complete.

request_body = request.get_json()

if "title" not in request_body or "description" not in request_body or "completed_at" not in request_body:
return jsonify({"details": "Invalid data"}), 400

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a Flask app returns a dictionary, it automatically converts that dictionary into JSON. So there's no need to use jsonify() for dictionaries. We should use jsonify() for all other datatypes though!

"is_complete": False if task.completed_at == None else True
})

return jsonify({"id": goal.goal_id, "title": goal.title, "tasks": tasks_and_goals}), 200 No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work practicing the single responsibility principle for the goal routes!

Comment on lines +54 to +57
# Assert
assert response.status_code == 404
assert response_body == None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +78 to +95
# Act
response = client.put("/goals/1", json={
"title": "Updated Goal Title"
})
response_body = response.get_json()

# Assert
assert response.status_code == 200
assert "goal" in response_body
assert response_body == {
"goal": {
"id": 1,
"title": "Updated Goal Title"
}
}
goal = Goal.query.get(1)
assert goal.title == "Updated Goal Title"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +107 to +115
# Act
response = client.put("/goals/1", json={
"title": "Updated Goal Title"
})
response_body = response.get_json()

# Assert
assert response.status_code == 404
assert response_body == None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +143 to +150
# Act
response = client.delete("/goals/1")
response_body = response.get_json()

# Assert
assert response.status_code == 404
assert response_body == None
assert Goal.query.all() == []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last assert statement doesn't scale well. We can't assume that deleting a goal would always produce an empty goal table. Rather, we can do a query to retrieve a goal at id 1 and confirm that None is returned.

Suggested change
# Act
response = client.delete("/goals/1")
response_body = response.get_json()
# Assert
assert response.status_code == 404
assert response_body == None
assert Goal.query.all() == []
assert Goal.query.get(1) == None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants