Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Otters - Jodi Denney #104

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Otters - Jodi Denney #104

wants to merge 14 commits into from

Conversation

J-J-D
Copy link

@J-J-D J-J-D commented May 13, 2022

Otters - Jodi Denney

Copy link

@goeunpark goeunpark left a comment

Choose a reason for hiding this comment

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

Fantastic job, Jodi! 🎉

Great job making models, tests, and clear CRUD endpoints in your task routes and goal routes files. This project is a strong implementation of major Flask concepts from Unit 2 and earns a Green. 🟢

I've left a few comments around consistency and where we could DRY up code in the future. Overall, keep up the great work! 🚀

Comment on lines +9 to +11
def to_json(self):
return {"id": self.goal_id,
"title": self.title}

Choose a reason for hiding this comment

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

Great instance method! 🎉

def test_get_task_not_found(client):
# Act
response = client.get("/tasks/1")
response_body = response.get_json()

# Assert
assert response.status_code == 404
assert "message" in response_body
assert response_body == {"message": f"Task 1 not found"}

Choose a reason for hiding this comment

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

👍🏻

Since you're not interpolating a string in L63, you don't need the f in front of `"Task 1 not found"

Comment on lines +107 to +109
assert response.status_code == 404
assert "message" in response_body
assert response_body == {"message": f"Goal 1 not found"}

Choose a reason for hiding this comment

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

👍🏻

@@ -51,13 +51,8 @@ def test_get_tasks_for_specific_goal_no_goal(client):
# Assert
assert response.status_code == 404

Choose a reason for hiding this comment

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

Forgot an assertion about the response body here -- remember to do a scan over for future projects!


tasks_bp = Blueprint("tasks_bp", __name__, url_prefix="/tasks")

SLACK_TOKEN = os.environ.get("SLACK_TOKEN")

Choose a reason for hiding this comment

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

Great job using a constant to call the token from your env file! ✨

@@ -1 +0,0 @@
from flask import Blueprint

Choose a reason for hiding this comment

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

I like that you split up our routes in two separate files! As our project and codebase grows, splitting up big files (and routes.py is often a notoriously big file) in a reasonable way is a good call.

Comment on lines +13 to +25
def validate_goal_id(goal_id):
try:
id = int(goal_id)
except:
abort(make_response(
{"message": f"goal {goal_id} invalid. Must be numerical"}, 400))

goal = Goal.query.get(goal_id)

if not goal:
abort(make_response({"message": f"Goal {goal_id} not found"}, 404))

return goal

Choose a reason for hiding this comment

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

Nice helper method here! This code is also very similar to validate_task_id in task_routes file -- could we modify this code to be able to work for both Models? 🤔

goals = Goal.query.filter_by(title=title_query)
else:
goals = Goal.query.all()
print(goals)

Choose a reason for hiding this comment

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

Remember to remove your print statements when you submit 😉

@goals_bp.route("/<goal_id>", methods=["GET"])
def get_single_goal(goal_id):
goal = validate_goal_id(goal_id)
return{"goal": goal.to_json()}

Choose a reason for hiding this comment

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

Beautiful use of the to_json method! I see that in some endpoints, you use jsonify but it's not consistently used. I recommend using it here as well! Flask will handle this dictionary correctly, but using a consistent pattern helps someone who's reading the code understand that the same thing is happening here.

Additionally, remember to give it an explicit status code!

Comment on lines +94 to +99
# tasks = []
# for id in task_ids:
# tasks.append(validate_task_id(id))
# for task in tasks:
# task.goal_id = goal.goal_id

Choose a reason for hiding this comment

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

Also remember to remove commented out code!

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