Conversation
| completed_at : Mapped[datetime | None] | ||
| goal_id: Mapped[Optional[int]] = mapped_column(ForeignKey("goal.id")) |
There was a problem hiding this comment.
You use two different styles of syntax for declaring an attribute as optional that essentially get treated the same by SQLAlchemy under the hood: [type|None] and Mapped[Optional[type]]. Would prefer that you stick to one style for consistency.
| new_goal = Goal(title="Wake up in morning") | ||
| goal_dict = new_goal.to_dict() | ||
|
|
||
| assert goal_dict["id"] is None |
There was a problem hiding this comment.
This test case tests the error behavior related to validate_model when the function is passed an ID that doesn't exist. Instead of creating a goal, we should be checking that the error response we get back validate_model has the status code we expect to receive and that the response body contains the values we expect.
Have a look at what e on line 100 is by using your debugger.
This test needs to be updated.
| new_task = Task(title="",description="") | ||
| task_dict = new_task.to_dict() | ||
|
|
||
| response = e.value.get_response() | ||
| assert response.status_code == 400 | ||
| assert response.get_json() == {"details": "Invalid data"} | ||
|
|
||
| assert task_dict["title"] == "" | ||
| assert task_dict["description"] == "" |
There was a problem hiding this comment.
Same as my comment above. These lines of code don't actually test the scenario described by the test name test_route_utilities_create_model_with_task_missing_title.
See on lines 134-137 we create an invalid request body that we pass to create_model and we want to test that the function behaves as we expect.
Do we get the right status code back? Does the response body look like how we expect it to look?
Debug this test and inspect what e on line 140 is. How can you use that to write assertions?
| response = e.value.get_response() | ||
|
|
||
| raise Exception("Complete test with assertion status code and response body") | ||
| assert response.status_code == 400 | ||
| response_body = response.get_data(as_text=True) | ||
| assert "message" in response_body |
| { | ||
| "message":"goal_title is missing." | ||
| } |
There was a problem hiding this comment.
What is this dictionary for? Did you intend to write an assertion about it related to the response body?
| title= task_data["title"], | ||
| description= task_data["description"], | ||
| completed_at= task_data.get("completed_at"), | ||
| goal_id= task_data.get("goal_id",None)) No newline at end of file |
There was a problem hiding this comment.
👀❗️ Take care to check that your code follows correct formatting. This is direct concern related to how folks perform at internship. At internship and at work, code with incorrect spacing or blank lines looks sloppy and people could pass judgement about someone's skill based on how their code looks.
| title= task_data["title"], | |
| description= task_data["description"], | |
| completed_at= task_data.get("completed_at"), | |
| goal_id= task_data.get("goal_id",None)) | |
| title=task_data["title"], | |
| description= ask_data["description"], | |
| completed_at=task_data.get("completed_at"), | |
| goal_id=task_data.get("goal_id",None)) |
Co-authored-by: Ashley Yang <ashley.minghui@gmail.com>
Co-authored-by: Ashley Yang <ashley.minghui@gmail.com>
No description provided.