- Improve understanding of Flask & SQL Alchemy with repetition
Build a Solar System API. This API will store information about different planets. Creating RESTful endpoints for CRUD operations.
Part I
- Define a
Planetclass with the attributesid,name, anddescription, and one additional attribute - Create a list of
Planetinstances
Part II
- Create an endpoint to get one existing
planet, so that I can see theid,name,description, andtypeof theplanet. - ...such that trying to get one non-existing
planetresponds with get a404response, so that I know theplanetresource was not found. - ... such that trying to get one
planetwith an invalidplanet_idresponds with get a400response, so that I know theplanet_idwas invalid.
Part III
- Create the database
solar_system_development - Setup the
Planetmodel with the attributesid,name, anddescription, andtype. - Create a migration to add a table for the
Planetmodel and then apply it.- Confirm that the
planettable has been created as expected in postgres.
- Confirm that the
- Submit a POST request with new valid
planetdata and get a success response, so that I know the API saved the planet data - Creat an endpoint to get all existing
planets, so that I can see a list of planets, with theirid,name,description, and other data of theplanet.
Part IV
- Submit an UPDATE request with valid planet data to update one existing
planetand get a success response, so that I know the API updated theplanetdata. - Submit a request to delete one existing
planetand get a success response, so that I know the API deleted theplanetdata..- Each of the above endpoints should respond with a
404for non-existing planets and a400for invalidplanet_id.
- Each of the above endpoints should respond with a
Part V
-
Review the requirements for Wave 01 - 04
- Test the endpoints using postman
- Complete or fix any incomplete or broken endpoints
- Look for opportunities to refactor
Part VI
Complete the following requirements, with similar functionality to the Hello Books API:
- Create a
.envfile. - Populate it with two environment variables:
SQLALCHEMY_DATABASE_URIandSQLALCHEMY_TEST_DATABASE_URI. Set their values to the appropriate connection strings. - Create a test database with the correct, matching name.
- Refactor the
create_appmethod to:- Check for a configuration flag
- Read the correct database location from the appropriate environment variables
- Manually test that my development environment still works.
- Create a
testsfolder with the files:tests/__init__.pytests/conftest.pytests/test_routes.py.
- Populate
tests/conftest.pywith the recommended configuration. - Create a test to check
GET/planetsreturns200and an empty array. - Confirm this test runs and passes.
Create test fixtures and unit tests for the following test cases:
GET/planets/1returns a response body that matches our fixtureGET/planets/1with no data in test database (no fixture) returns a404GET/planetswith valid test data (fixtures) returns a200with an array including appropriate test dataPOST/planetswith a JSON request body returns a201
Note: For this project, I will not expect to have high test coverage because I have not tested all of the CRUD routes. Still, it is helpful to practice checking coverage and reading reports of the code which detail the code that is tested, and the code that is not tested.