Conversation
jbieniosek
left a comment
There was a problem hiding this comment.
Great work on this project, fantastic extensions! This project is green.
| @planets_bp.route("/picture/<planet_id>", methods=["GET"]) | ||
| def handle_planet_picture(planet_id): | ||
| for planet in planets: | ||
| if planet.id == int(planet_id): | ||
| return render_template('planet_picture.html', url=planet.picture) | ||
|
|
||
| @planets_bp.route("/picturesummary/<planet_id>", methods=["GET"]) | ||
| def handle_planet_summary(planet_id): | ||
| for planet in planets: | ||
| if planet.id == int(planet_id): | ||
| if planet.moon == True: | ||
| moon = "Yes" | ||
| else: | ||
| moon = "No" | ||
| return render_template('planet_summary.html', | ||
| url=planet.picture, | ||
| title=planet.title, | ||
| diameter=planet.description, | ||
| moon=moon) |
| <html> | ||
| <head> | ||
| </head> | ||
|
|
||
| <body> | ||
| <h1>{{title}}</h1> | ||
| <br> | ||
| <i>{{diameter}}</i> | ||
| <br> | ||
| <i>Moon: {{moon}}</i> | ||
| <br> | ||
| <img src="{{ url }}"> | ||
| </body> | ||
|
|
||
| </html> No newline at end of file |
| return { | ||
| "id": planet.id, | ||
| "title": planet.title, | ||
| "description": planet.description, | ||
| "moon":planet.moon, | ||
| "picture": planet.picture | ||
| } |
There was a problem hiding this comment.
I recommend adding ‘jsonify’ to the return even in the case where the Flask default behavior is doing the same thing. Using ‘jsonify’ adds a layer of error protection and also makes it clear that json is the intended behavior.
| return { | |
| "id": planet.id, | |
| "title": planet.title, | |
| "description": planet.description, | |
| "moon":planet.moon, | |
| "picture": planet.picture | |
| } | |
| return jsonify({ | |
| "id": planet.id, | |
| "title": planet.title, | |
| "description": planet.description, | |
| "moon":planet.moon, | |
| "picture": planet.picture | |
| }) |
…ile with planet info (json format)
CheezItMan
left a comment
There was a problem hiding this comment.
Well done Karina & Roslyn, 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( | ||
| "SQLALCHEMY_DATABASE_URI") | ||
| else: | ||
| app.config["TESTING"] = True | ||
| app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False | ||
| app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( | ||
| "SQLALCHEMY_TEST_DATABASE_URI") |
| moons = db.Column(db.Boolean) | ||
| picture = db.Column(db.String) | ||
|
|
||
| def to_dict(self): |
| @planets_bp.route("", methods = ["GET"]) | ||
| def handle_planets(): |
| @planets_bp.route("/<planet_id>", methods=["GET", "PATCH", "PUT", "DELETE"]) | ||
| def handle_planet(planet_id): | ||
| if not planet_id.isnumeric(): | ||
| return { "Error": f"{planet_id} must be numeric."}, 404 |
There was a problem hiding this comment.
An argument can be made for this to be a 400 error as opposed to 404.
| for name, val_type in data_types.items(): | ||
| try: | ||
| assert val_type==type(input_data[name]) | ||
| print(name,type(input_data[name])) |
There was a problem hiding this comment.
print isn't needed
| print(name,type(input_data[name])) |
| return render_template('planet_summary.html', | ||
| url=planet.picture, | ||
| title=planet.name, | ||
| diameter=planet.diameter, | ||
| moon=moon) |
| @planets_bp.route("/picturesummary", methods=["GET"]) | ||
| def handle_planet_summary_params(): |
There was a problem hiding this comment.
Nice custom route and use of render_template
| assert saturn in response_body | ||
| assert jupiter in response_body | ||
|
|
||
| def test_post_one_planet(client): |
There was a problem hiding this comment.
Nice! Another good set of tests for failure cases as well would be good.
We had some extra time so we added an html template to render the planet images.