Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1.92 KB

wave_06.md

File metadata and controls

37 lines (27 loc) · 1.92 KB

Wave 06: Writing Tests

Setup

Complete the following requirements, with similar functionality to the Hello Books API:

  1. Create a .env file.
  2. Populate it with two environment variables: SQLALCHEMY_DATABASE_URI and SQLALCHEMY_TEST_DATABASE_URI. Set their values to the appropriate connection strings.
  3. Create a test database with the correct, matching name.
  4. Refactor the create_app method to:
    • Check for a configuration flag
    • Read the correct database location from the appropriate environment variables
  5. Manually test that our development environment still works.
  6. Create a tests folder with the files:
    • tests/__init__.py
    • tests/conftest.py
    • tests/test_routes.py.
  7. Populate tests/conftest.py with the recommended configuration.
  8. Create a test to check GET /planets returns 200 and an empty array.
  9. Confirm this test runs and passes.

Writing Tests

Create test fixtures and unit tests for the following test cases:

  1. GET /planets/1 returns a response body that matches our fixture
  2. GET /planets/1 with no data in test database (no fixture) returns a 404
  3. GET /planets with valid test data (fixtures) returns a 200 with an array including appropriate test data
  4. POST /planets with a JSON request body returns a 201

Code Coverage

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.