-
Notifications
You must be signed in to change notification settings - Fork 36
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
Sarah and Brooke - Pine - Part 1 #16
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this project! This project is green.
app/planets.py
Outdated
def create_planet_dictionary(self): | ||
return { | ||
"id": self.id, | ||
"name": self.name, | ||
"description": self.description, | ||
"has moons": self.has_moons | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great helper function!
app/routes.py
Outdated
def handle_planet(planet_id): | ||
for planet in planets: | ||
if int(planet_id) == planet.id: | ||
return jsonify(planet.create_planet_dictionary()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
self.description = description | ||
self.has_moons = has_moons | ||
self.id = Planet.number_of_planets | ||
Planet.increase_number_of_planets() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat idea!
Co-authored-by: sarahstandish <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work Sarah & Brooke, you hit the learning goals here. Well done.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of env variables
description = db.Column(db.String(200)) | ||
has_moons = db.Column(db.Boolean) | ||
|
||
def create_planet_dictionary(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great helper function, maybe call this to_dict
instead?
if type(request_body) == list: | ||
for planet in request_body: | ||
new_planet = Planet(name = planet["name"], description = planet["description"], has_moons = planet["has_moons"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No input validation?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability in these cases I suggest also including a response code
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Great that you added tests, future tests would cover the error cases like for post requests with missing or invalid data.
No description provided.