Skip to main content

Versatile integration tests for web app views

Project description

License

PyPI version Python versions

Test Ruff Mypy

Documentation

DOCUMENTATION NOT UP TO DATE

Development

Set up environement

pip install -e ".[dev,django,fastapi]"

Publishing process

[!info] Make sure the version vx.x.x tag match with the version in pyproject.toml

Run the test and python checks

bash scripts/test.sh
bash scripts/python_checks.sh
mkdocs build

Test PyPI

[!info] this should be done on branch test

git add .
git commit -m "ready for vx.x.x"
git tag vx.x.x
git push origin vx.x.x

The publication process is then handled by .github/workflows/publish-testpypi.yml

Old way (no GitHub action)

We keep it for history. This was done before we use GitHub actions

python3 -m build
python3 -m twine upload --repository testpypi dist/* --verbose

PyPI

[!info] this should be done on branch master

git add .
git commit -m "ready for vx.x.x"
git tag vx.x.x
git push origin master --tags

The publication process is then handled by .github/workflows/publish-pypi.yml

[!warning] Make sure the version vx.x.x tag match with the version in requirements.txt in relevant repositories

scenery

scenery simplifies writing extensive and maintainable integration tests for your Django application while keeping your testing codebase DRY.

Scenery Demo

Features

  • Human-readable YAML configuration files for test scenarios
  • Launch your entire test suite with a single command
  • Full control over set-up and tear-down actions
  • Easily share data across multiple tests
  • Flexible and extensible directive system for response validation

Installation

Install scenery using pip:

pip install pca-scenery

Usage

Test Manifests

With scenery, integration tests are configured using YAML, a human-readable data serialization language, making maintenance easy for developers. A given YAML file is called a manifest.

In a manifest, a test is described by a scene which defines the request to a given URL and the checks (called directives) that should be applied to the HTTP response.

Example 1: Simple GET request

scene:
  method: GET
  url: "index"
  directives:
    - status_code: 200

This test sends a GET request to the '/index' URL and checks if the returned status code is 200.

Example 2: POST request with data

cases:
  CASE_A:
    item_1:
        foo: 0
  CASE_B:
    item_1:
        foo: 1

scene:
  method: POST
  url: "item"
  data:
    item_id: !case item_1:foo
  directives:
    - status_code: 200

This test sends a POST request to the '/item' URL with {item_id: 0} and {item_id: 1} as data and checks if the returned status code is 200.

Advanced Features

The full syntax of scenery allows you to:

  • Test a given scene with different data sets
  • Shared data for use across multiple tests
  • Have full control over set-up and tear-down methods
  • Leverage YAML syntax to parsimonly define your tests

Settings

scenery relies on 4 environment variables, which can be easily provided by a scenery_settings.py file at the root of your project (or any location you prefer).

# scenery_settings.py
SCENERY_MANIFESTS_FOLDER = "path/to/your/manifests"
SCENERY_COMMON_ITEMS = "path/to/shared/data.yml"
SCENERY_SET_UP_INSTRUCTIONS = "path/to/your/set_up_tear_down_functions"
SCENERY_DJANGO_APP_NAME = "your_app_name"

Running Tests

You also need to provide the Django settings you want to use. To run your tests, use the following command:

python -m scenery --django_settings=your_project.settings.test

You can also add additional command-line arguments to filter tests, set verbosity, etc. Run python -m scenery --help for more information.

For more detailed information, please visit our official documentation.

Contributing

We welcome contributions to scenery! Here are some ways you can contribute:

  1. Report bugs or request features by opening an issue
  2. Improve documentation
  3. Submit pull requests with bug fixes or new features

Please read our Contributing Guide for more details.

License

scenery is licensed under the MIT License. See the LICENSE file for details.

Credits

scenery was created by Etienne Madinier.

It relies on great open-source projects:


For more information, examples, and advanced usage, please visit our official documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pca_scenery-0.1.21.tar.gz (35.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pca_scenery-0.1.21-py3-none-any.whl (41.0 kB view details)

Uploaded Python 3

File details

Details for the file pca_scenery-0.1.21.tar.gz.

File metadata

  • Download URL: pca_scenery-0.1.21.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pca_scenery-0.1.21.tar.gz
Algorithm Hash digest
SHA256 4aaf2a9afcbef346855ff0e25c4cf735d83a60e132b1f7f89af24bf967640e4f
MD5 68040842f8d9a79f1fb95bb90810bd21
BLAKE2b-256 783d42afc5ab5bbb6521eb8e42b0d5aea7bd9731162185668f5a6bdd00d3235f

See more details on using hashes here.

File details

Details for the file pca_scenery-0.1.21-py3-none-any.whl.

File metadata

  • Download URL: pca_scenery-0.1.21-py3-none-any.whl
  • Upload date:
  • Size: 41.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pca_scenery-0.1.21-py3-none-any.whl
Algorithm Hash digest
SHA256 5cd245ac1a5367eec6199c69e390f8d0ca43f723080ceba3619b6210b77fa217
MD5 0dfa34a4c92574e66d1bf7055af3e955
BLAKE2b-256 215f268921483397006cfeac0f7a1641f5045f1a561d1040bfde9469e8141a49

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page