Complete the following requirements, with similar functionality to the Hello Books API:
- Create a
.env
file. - Populate it with two environment variables:
SQLALCHEMY_DATABASE_URI
andSQLALCHEMY_TEST_DATABASE_URI
. Set their values to the appropriate connection strings. - Create a test database with the correct, matching name.
- Refactor the
create_app
method 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
tests
folder with the files:tests/__init__.py
tests/conftest.py
tests/test_routes.py
.
- Populate
tests/conftest.py
with the recommended configuration. - Create a test to check
GET
/planets
returns200
and an empty array. - Confirm this test runs and passes.
Create test fixtures and unit tests for the following test cases:
GET
/planets/1
returns a response body that matches our fixtureGET
/planets/1
with no data in test database (no fixture) returns a404
GET
/planets
with valid test data (fixtures) returns a200
with an array including appropriate test dataPOST
/planets
with 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.