Open
Conversation
jbieniosek
reviewed
Oct 21, 2021
jbieniosek
left a comment
There was a problem hiding this comment.
Great work on this project! This project is green.
Comment on lines
+14
to
+20
| def create_planet_dictionary(self): | ||
| return { | ||
| "id": self.id, | ||
| "name": self.name, | ||
| "description": self.description, | ||
| "has moons": self.has_moons | ||
| } No newline at end of file |
| def handle_planet(planet_id): | ||
| for planet in planets: | ||
| if int(planet_id) == planet.id: | ||
| return jsonify(planet.create_planet_dictionary()) No newline at end of file |
| self.description = description | ||
| self.has_moons = has_moons | ||
| self.id = Planet.number_of_planets | ||
| Planet.increase_number_of_planets() |
Co-authored-by: sarahstandish <sarahstandish@users.noreply.github.com>
CheezItMan
reviewed
Oct 29, 2021
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Sarah & Brooke, you hit the learning goals here. Well done.
Comment on lines
+17
to
+23
| if not test_config: | ||
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
| app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_CONNECTION_STRING') | ||
| else: | ||
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
| app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('TEST_DATABASE_CONNECTION_STRING') | ||
| app.config['TESTING'] = True |
| description = db.Column(db.String(200)) | ||
| has_moons = db.Column(db.Boolean) | ||
|
|
||
| def create_planet_dictionary(self): |
There was a problem hiding this comment.
Great helper function, maybe call this to_dict instead?
Comment on lines
+13
to
+15
| if type(request_body) == list: | ||
| for planet in request_body: | ||
| new_planet = Planet(name = planet["name"], description = planet["description"], has_moons = planet["has_moons"]) |
Comment on lines
+29
to
+35
| elif request.method == "GET": | ||
| planets = Planet.query.all() | ||
| planet_list = [] | ||
| for planet in planets: | ||
| planet_list.append(planet.create_planet_dictionary()) | ||
|
|
||
| return jsonify(planet_list), 200 |
| return { "Error" : f"Planet {planet_id} was not found."}, 404 | ||
|
|
||
| if request.method == "GET": | ||
| return jsonify(planet.create_planet_dictionary()) |
There was a problem hiding this comment.
For readability in these cases I suggest also including a response code
Suggested change
| return jsonify(planet.create_planet_dictionary()) | |
| return jsonify(planet.create_planet_dictionary()), 200 |
| "id" : 2 | ||
| }] | ||
|
|
||
| def test_post_all_planets_returns_201(client): |
There was a problem hiding this comment.
👍 Great that you added tests, future tests would cover the error cases like for post requests with missing or invalid data.
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.
No description provided.