Skip to content

C22 Phoenix - Luqi Xie #29

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

C22 Phoenix - Luqi Xie #29

wants to merge 3 commits into from

Conversation

shiqipaper
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.

Looks good! Please review my comments, and let me know if you have any questions. Nice job!

# assertion 2 goes here
assert "goal" in response_body

Choose a reason for hiding this comment

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

We do provide tests with assertions like this, which look for the wrapper key before comparing the dictionary values, but it might be more useful to retrieve the goal from the database and confirm that the expected change was applied.

Comment on lines +154 to +156
assert response_body == {
"details": 'Goal 1 "Build a habit of going outside daily" successfully deleted'
}

Choose a reason for hiding this comment

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

👀 The response_body hasn't been updated to get the "missing" message from this second API call. That's why we're still seeing the first response. We would need to add something like

    response_body = response.get_json()

We should make sure that what we're actually asserting makes sense for the case, and not just pass the test. Here, if we try to retrieve the goal we just deleted, we shouldn't be getting the delete success message again.

# *****************************************************************
# **Complete test with assertion about response body***************
# *****************************************************************
assert response_body == {"message":"Goal 1 not found"}

Choose a reason for hiding this comment

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

Nit: spacing after colon

@@ -0,0 +1,32 @@
"""add goal model

Choose a reason for hiding this comment

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

Nice use of labels on the migrations to be able to tell what each is doing at a glance. Often, since the migrations are named first with a hash, they don't list in the order they were created, making it difficult to trace through a series of migrations.

Choose a reason for hiding this comment

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

It looks like you went through a couple of steps to create your migrations. This is completely fine, and reflects the progress of the work.

On the other hand, while I'm still in "development phase", I often like to have just one clean migration to setup the initial database. So another approach would be to periodically clear out the database and migrations, and make a fresh one once you've got the models configured as desired. This isn't a good idea once a project has been deployed publicly (since we would lose any exisiting data when we drop the database), but can make the migrations a little easier to understand for setting up a fresh deployment.

Comment on lines +6 to +8
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .goal import Goal

Choose a reason for hiding this comment

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

Nice inclusion of this extra check to clear up the type warnings in VS Code.

Comment on lines +23 to +26
"id": goal.id,
"title": goal.title
}

Choose a reason for hiding this comment

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

Prefer to use the to_dict method here.

request_body = request.get_json()

goal.title = request_body["title"]

Choose a reason for hiding this comment

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

Like for Task, we might want similar error handling here as for the POST route.

"id": goal.id,
"title": goal.title,
"tasks": [task.to_dict() for task in goal.tasks]

Choose a reason for hiding this comment

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

Since this is the only route that includes the child tasks, and it's being explicitly added here, that would allow us to remove the logic to do some from to_dict, leaving that to build a dictionary of only the scalar values of Goal. We could still use to_dict here, and then add in the tasks collection that we generate.

for task_id in task_ids:
task = validate_model(Task, task_id)
goal.tasks.append(task)

Choose a reason for hiding this comment

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

This logic appends each task to the current goal, so any pre-existing tasks would still be associated with the goal. In this case, we'd want the result to show all of the tasks now associated with the goal. See below.

response = {
"id": goal.id,
"task_ids": 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 input task ids, since we appended the new tasks to the existing goal, we should fetch the task ids directly from the goal, in case there were any other tasks already associated with this goal. Something like this

        "task_ids": [task.id for task in goal.tasks]}

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