Django Replay

Django Replay is an Apache2 licensed Django application that records and replays web requests.

Features

  • Record requests/responses as easy as “runserver”

  • Test scenarios by replaying requests with validators

  • Template requests/responses for dynamic identifiers

  • Tested on Python 3.7, 3.8, 3.9, 3.10

  • Tested on Django 3.2 LTS and Django 4.0

https://github.com/grantjenks/django-replay/workflows/integration/badge.svg https://github.com/grantjenks/django-replay/workflows/release/badge.svg

Quickstart

Installing Django Replay is simple with pip:

$ pip install django-replay

Add replay to the INSTALLED_APPS in settings.py like:

INSTALLED_APPS += ['replay']

Then migrate the database like:

$ python manage.py migrate

Django Replay provides two management commands:

  1. replayrecord – like “runserver” but request/responses are recorded.

  2. replaytest – runs the scenarios with actions and validators.

Django Replay also provides three models:

  1. Scenario – ordered list of actions.

  2. Action – recorded request/response template.

  3. Validator – regular expression for response validation.

These models can be edited in the admin.

Tutorial

To get started, follow the Quickstart and then record some actions:

$ python manage.py replayrecord

Navigate to http://127.0.0.1:8000/ and use the web app as normal. Once the actions are recorded run CTRL-C to stop the command.

Now create some scenarios in the admin:

$ python manage.py runserver

TODO: Insert screenshots of creating scenarios.

The scenarios can be tested manually using:

$ python manage.py replaytest

Remember to clear the content of the actions. Now the tests can be saved in a fixture.

$ python manage.py dumpdata --indent 4 replay > replay.json

And the scenarios can be integrated with Django’s test framework like so:

from django.test import TestCase
from replay.utils import test_scenarios

 class ReplayTestCase(TestCase):
     fixtures = ['path/to/replay.json']

     def test_scenarios(self):
         test_scenarios()

Templates and Validators

TODO: Describe templating syntax for requests

TODO: Describe regular expression features for validators

Reference and Indices

Django Replay License

Copyright 2017-2022 Grant Jenks

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.