Open
Conversation
CheezItMan
reviewed
Nov 20, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Masha & Melly,
I left some minor comments, but this is quite well done. Let me know if you have questions via slack.
Comment on lines
+10
to
+29
| def to_dict(self): | ||
|
|
||
| return { | ||
| "name": self.name, | ||
| "color": self.color, | ||
| "description": self.description, | ||
| "id": self.id | ||
| } | ||
| @classmethod | ||
| def from_json(cls, req_body): | ||
| return cls( | ||
| name= req_body["name"], | ||
| color= req_body["color"], | ||
| description= req_body["description"] | ||
| ) | ||
|
|
||
| def update(self, req_body): | ||
| self.name= req_body["name"], | ||
| self.color= req_body["color"], | ||
| self.description= req_body["description"] No newline at end of file |
Comment on lines
+8
to
+19
| def validate_planet(class_obj, planet_id): | ||
| try: | ||
| planet_id = int(planet_id) | ||
| except: | ||
| abort(make_response({"message": f"planet {planet_id} has an invalid planet_id"}, 400)) | ||
|
|
||
| query_result = class_obj.query.get(planet_id) | ||
|
|
||
| if not query_result: | ||
| abort(make_response({"message": f"planet {planet_id} not found"}, 404)) | ||
|
|
||
| return query_result |
|
|
||
| @planets_bp.route("", methods=["POST"]) | ||
| def create_planet(): | ||
| request_body = request.get_json() |
There was a problem hiding this comment.
Some validation on the request_body here would be good to ensure it has the required fields.
| @planets_bp.route("/<planet_id>", methods=["PUT"]) | ||
| def update_planet(planet_id): | ||
| planet = validate_planet(planet_id) | ||
| request_body = request.get_json() |
There was a problem hiding this comment.
Again validation here would be appropriate.
| assert response.status_code == 400 | ||
| assert response_body == "{\"message\":\"planet ABC has an invalid planet_id\"}\n" | ||
|
|
||
| def test_create_planet_can_create_planet_in_empty_db(client): |
There was a problem hiding this comment.
Have a create request with an invalid request body would be a good test as well.
| return make_response (f"Planet #{planet.id} successfully updated") | ||
|
|
||
| @planets_bp.route("/<planet_id>", methods=["DELETE"]) | ||
| def delete_planet(planet_id): |
There was a problem hiding this comment.
Just noting that this and the update action are untested.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Waave 1 and 2