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 our development environment still works.
- Create a
testsfolder with the files:tests/__init__.pytests/conftest.pytests/test_planet_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
Check your code coverage using pytest-cov. Review the code coverage exercise on how to use pytest-cov to generate a code coverage report. We will need to change the directory where the application code is located from student to app.
pytest --cov=app --cov-report html --cov-report term
For this project, we will not expect to have high test coverage because we have not tested all of our 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.