Madeline Bennet, Lula San(Pheonix Class)#11
Conversation
anselrognlie
left a comment
There was a problem hiding this comment.
You're off to a good start. There are some formatting nits, and also be sure to include the error status codes on the expected object (the response rather than the abort call), but otherwise you're right on track.
…oded sorting param
…et one book, and post one book
anselrognlie
left a comment
There was a problem hiding this comment.
Nice work making the modifications to connect your API to your database, expanding the endpoints, and adding some tests. Everything here should be able to be applied to your task list implementations.
| from .routes.planets_routes import planet_bp | ||
| import os | ||
|
|
||
| def create_app(config=None): |
There was a problem hiding this comment.
👍 Thanks for renaming this. This param could be used for scenarios other than testing (the name was left over from the previous curriculum).
| app = Flask(__name__) | ||
|
|
||
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
| app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI') |
There was a problem hiding this comment.
👍 Loads the connection string from the environment (provided with our .env during development).
| #from .routes.planets_path import planet_bp | ||
| def create_app(test_config=None): | ||
| from .db import db, migrate | ||
| from .models import planet |
There was a problem hiding this comment.
Note that once we have the Planet model imported in the routes, and the routes are imported here, we don't technically need to import the planet module here. If you find the fact that VS Code shows this as not being used, it would now be safe to remove.
| return { | ||
| "id": self.id, | ||
| "name": self.name, | ||
| "description": self.description, | ||
| "signs of life": self.signs_of_life | ||
| } |
| class Planet(db.Model): | ||
| id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) | ||
| name: Mapped[str] | ||
| description: Mapped[str] | ||
| signs_of_life: Mapped[bool] |
There was a problem hiding this comment.
👍 Nice modifications to associate this model type with our database.
| response_body = response.get_json() | ||
|
|
||
| assert response.status_code == 404 | ||
| assert response_body == no_planet_response_body |
There was a problem hiding this comment.
👍 We should also check that the response body is the expected message.
tests/test_planet_routes.py
Outdated
| before_post_database_response = client.get("/planets") | ||
| before_post_database_response_body =before_post_database_response.get_json() |
There was a problem hiding this comment.
This test starts with no fixtures, so these checks are duplicating the get all with no data case. We don't need them here.
| def test_post_one_planet(client): | ||
| before_post_database_response = client.get("/planets") | ||
| before_post_database_response_body =before_post_database_response.get_json() | ||
| response=client.post("/planets",json={ |
There was a problem hiding this comment.
Nit: Spaces around assignment and after comma
response = client.post("/planets", json={
tests/test_planet_routes.py
Outdated
| print("actual response", response_body) | ||
| print("expected response", planet_1_response_body) |
tests/test_planet_routes.py
Outdated
| assert before_post_database_response.status_code == 200 | ||
| assert before_post_database_response_body == [] |
There was a problem hiding this comment.
These checks aren't need, as above.
Wave 1 & wave 2 of solar-system api project.