Conversation
apradoada
left a comment
There was a problem hiding this comment.
Overall well done! I've left a few comments here or there but all in all this is a very well done project!
|
|
||
| def create_app(test_config=None): | ||
| app = Flask(__name__) | ||
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False |
There was a problem hiding this comment.
Great job placing this statement before the conditional so you don't duplicate code!
| __tablename__ = 'planets' | ||
|
|
||
| id = db.Column(db.Integer, primary_key=True, autoincrement=True) | ||
| name = db.Column(db.String, nullable=False) |
There was a problem hiding this comment.
Great job making your planets non-nullable! We would definitely want to make sure we include a name when we create a planet!
| db.session.add(new_planet) | ||
| db.session.commit() | ||
|
|
||
| message = f"New planet {new_planet.name} successfully created, biatch!" |
| if not planet: | ||
| abort(make_response({"message": f"Planet {planet_id} was not found, sucker!"}, 404)) | ||
|
|
||
| return planet |
There was a problem hiding this comment.
Since validate_planet is a helper method, it is usually a good idea to move it either before or after the routes, or to its own file!
| name = request_body["name"], | ||
| description = request_body["description"], | ||
| mass = request_body["mass"], | ||
| ) |
There was a problem hiding this comment.
This might be a good candidate for error handling because it is possible a name, description or mass is not included!
|
|
||
| return make_response({"message": message}, 200) | ||
|
|
||
|
|
| db.session.delete(planet) | ||
| db.session.commit() | ||
|
|
||
| message = f"Planet {planet} succesfully deleted, biatch!" |
|
|
||
| message = f"Planet {planet} succesfully updated, biatch!" | ||
|
|
||
| return make_response({"message": message}, 200) |
There was a problem hiding this comment.
This would be another good candidate for error handling! How could we handle these situations if there was no information provided in the request body?
| db.session.add_all(test_planets) | ||
| db.session.commit() | ||
|
|
||
| return test_planets No newline at end of file |
There was a problem hiding this comment.
Well done with the boilerplate code needed for the app and client fixtures and well done writing your custom fixtures for saving planets to the database!
| assert response.status_code == 200 | ||
| assert response_body == {'message': 'Planet <Planet 2> succesfully updated, biatch!'} | ||
| assert updated_array == [{'id': 1, 'name': 'test_name_2', 'description': 'test_description_2','mass': '2.000'}, | ||
| {'id': 2, 'name': 'test_name_1', 'description': 'test_description_1', 'mass': '1.000'}] No newline at end of file |
There was a problem hiding this comment.
Well done with these tests! They are thoroughly done! And I will always enjoy these messages y'all have created.
No description provided.