Open
Conversation
Co-authored-by: Maria Silva
moons in assert statement
CheezItMan
reviewed
Nov 20, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
Overall nice work. I left some comments and suggestions. Let me know if you have any questions via slack.
Comment on lines
+10
to
+24
| def to_dict(self): | ||
| planet_as_dict = {} | ||
| planet_as_dict["id"] = self.id | ||
| planet_as_dict["name"] = self.name | ||
| planet_as_dict["description"] = self.description | ||
| planet_as_dict["moons"]=self.moons | ||
|
|
||
| return planet_as_dict | ||
|
|
||
| def from_json(cls, req_body): | ||
| return cls( | ||
| name = req_body["name"], | ||
| description = req_body["description"], | ||
| moons = req_body["moons"] | ||
| ) No newline at end of file |
Comment on lines
+10
to
+21
| def validate_model(cls, model_id): | ||
| try: | ||
| model_id = int(model_id) | ||
| except: | ||
| abort(make_response({"message":f"{cls.__name__} {model_id} invalid"}, 400)) | ||
|
|
||
| model = cls.query.get(model_id) | ||
|
|
||
| if not model: | ||
| abort(make_response({"message":f"{cls.__name__} {model_id} not found"}, 404)) | ||
|
|
||
| return model |
|
|
||
|
|
||
| @planets_bp.route("", methods=["POST"]) | ||
| def handle_planets(): |
There was a problem hiding this comment.
Why name this function handle_planets and not create_planet?
Comment on lines
+68
to
+71
| planet.name = request_body["name"] | ||
| planet.description = request_body["description"] | ||
| planet.moons = request_body["moons"] | ||
|
|
There was a problem hiding this comment.
Doing some validation on the request body here would be good. i.e. make sure it has the given fields and they are valid.
Comment on lines
+46
to
+56
| assert response_body[0] == { | ||
| 'id': 1, | ||
| 'name': 'Mars', | ||
| 'description': 'Too hot', | ||
| 'moons': 2} | ||
|
|
||
| assert response_body[1] == { | ||
| 'id': 2, | ||
| 'name' : 'Earth', | ||
| 'description' : 'Home Sweet Home', | ||
| 'moons': 1} |
There was a problem hiding this comment.
You could also do:
Suggested change
| assert response_body[0] == { | |
| 'id': 1, | |
| 'name': 'Mars', | |
| 'description': 'Too hot', | |
| 'moons': 2} | |
| assert response_body[1] == { | |
| 'id': 2, | |
| 'name' : 'Earth', | |
| 'description' : 'Home Sweet Home', | |
| 'moons': 1} | |
| assert response_body == [{ | |
| 'id': 1, | |
| 'name': 'Mars', | |
| 'description': 'Too hot', | |
| 'moons': 2 | |
| }, | |
| { | |
| 'id': 2, | |
| 'name' : 'Earth', | |
| 'description' : 'Home Sweet Home', | |
| 'moons': 1} | |
| ] |
|
|
||
|
|
||
| # 4.POST /books with a JSON request body returns a 201 | ||
| def test_create_one_book(client): |
There was a problem hiding this comment.
You should also have a test that checks what happens when the request body is invalid.
|
|
||
| # DELETE RESOURCE | ||
| @planets_bp.route("/<id>", methods=["DELETE"]) | ||
| def delete_planet(id): |
|
|
||
| # UPDATE RESOURCE | ||
| @planets_bp.route("/<id>", methods=["PUT"]) | ||
| def update_planet(id): |
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.
Tigers - Neema and Maria