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

c17 sea turtles - jae #111

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

Conversation

jaekerrclayton
Copy link

No description provided.

Copy link

@anselrognlie anselrognlie left a comment

Choose a reason for hiding this comment

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

Great job!

Your tests are all passing and your code is very readable.

Moving forward, try thinking more about how to separate the various responsibilities of your code. Deciding where things should go is really tricky. Often, we try to figure out what's the smallest number of things that needs to know some information to allow everything to run, and we'll organize our code to hide as much detail from the parts that don't need to know about it. We call this loose coupling, and it can make for much more reusable, flexible, maintainable, and testable code!

Overall, nicely done!


from flask import jsonify, abort, make_response

def error_message(message, status_code):

Choose a reason for hiding this comment

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

👍

For the name of this file, the file doesn't contain routes for something called a helper, it contains helpers for routes, so I would name this route_helpers.py

@@ -0,0 +1,43 @@
"""empty message

Choose a reason for hiding this comment

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

It's good practice to add a message when generating a migration to help no what's in which file. It's not such an issue with only one migration files, but it can be very helpful if we have several.

"title": "New Year, New Goal"
}
}
goal = Goal.query.get(1)

Choose a reason for hiding this comment

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

👍 Good idea to verify that the change was actually saved and not just returned.

Personally, I like to keep tests at the same level of abstraction throughout, so here, since we're writing HTTP client tests, rather than going directly to the database (like lots of other tests here), I would prefer to issue a follow-up GET request.

assert response.status_code == 404

assert response_body == {"details": "Goal with id #1 not found"}
assert Goal.query.all() == []

Choose a reason for hiding this comment

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

Personally, I wouldn't feel the need to check that the goals collection is empty. The test started out with no goals, and it would be particularly odd of trying to delete a non-existent goal would lead to the creation of any additional goals.

id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String, nullable=False)
description = db.Column(db.String, nullable=False)
is_complete = db.Column(db.Boolean, default=False)

Choose a reason for hiding this comment

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

Consider not making an actual is_complete column. We can calculate whether the task is complete or not based on the completed_at timestamp. If we store redundant data, we run the risk of the two pieces of data getting out of sync (say we update one but forget to update the other).

for id in request_body['task_ids']:
new_task = validate_task(id)
goal.tasks.append(new_task)

Choose a reason for hiding this comment

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

Nice use of the relationship to build the association between the tasks and the goal.

Note that as written, this would add the supplied tasks to any tasks already associated with the goal. The tests are ambiguous about whether we want that behavior, or whether the tasks should be replaced. Try thinking about what we would do if we wanted the replacement behavior.

db.session.commit()
return {"id": goal.id,
"task_ids" : request_body['task_ids']}

Choose a reason for hiding this comment

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

Rather than echoing back the ids that came in the request id, consider loading the actual task ids from the goal. What if the goal had other associated tasks before adding this batch?

app/routes.py Outdated
text=f"Someone just completed {task.title}"
headers = {"Authorization": slack_bot_token}
slack_url = f'https://slack.com/api/chat.postMessage?channel={channel_name}&text={text}'

Choose a reason for hiding this comment

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

If using a POST, we should send the data to the endpoint using the request body rather than through query params. (Check out the requests.post data= or json= arguments).

app/routes.py Outdated
Comment on lines 207 to 214
channel_name = 'test-channel'
text=f"Someone just completed {task.title}"
headers = {"Authorization": slack_bot_token}
slack_url = f'https://slack.com/api/chat.postMessage?channel={channel_name}&text={text}'

## UNCOMMENT RESPONSE TO POST
#response = requests.post(slack_url, headers=headers)

Choose a reason for hiding this comment

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

Consider moving the logic here for messaging Slack into a helper method that just takes a message. THen we could call that method both from this route, as well as from the mark incomplete route.

app/routes.py Outdated
Comment on lines 207 to 214
channel_name = 'test-channel'
text=f"Someone just completed {task.title}"
headers = {"Authorization": slack_bot_token}
slack_url = f'https://slack.com/api/chat.postMessage?channel={channel_name}&text={text}'

## UNCOMMENT RESPONSE TO POST
#response = requests.post(slack_url, headers=headers)

Choose a reason for hiding this comment

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

Why is this line commented out? It looks like it should work!

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