Skip to main content

No project description provided

Project description

EchoTester

Django app , that record requests that comes to your project then run them whenever you want to determine if things breaks while development (in case you don't have tests written) --- or you wanna to simulate a scenario each time you made a change

How to use it

Installation

Just install it from pip

pip install django-echo-tester

Then register is as an django app

INSTALLED_APPS = [
    ...    
    'echo_tester'
]

Then we need to record the requests to use it later.

MIDDLEWARE = [
    ...
    'echo_tester.middleware.TesterMiddleware',
]

Basic use

To run the saved requests, to test if there is breaking ones or not.

python manage.py runecho

Settings variables and advanced use

NOTE: Keys we use is just the path in the dictionary in other words you can consider the dictionary is an class instance and you get a value from it

for example:

request = {
    ...
    'headers': {
        'Content-Type': 'application/json',
        ...
    }
}

# To access the key wanted we use
path = 'headers.Content-Type'

Request

RequestObject

{
    "path": "/random/path/in/your/app/",
    "url": "http://domain.com/random/path/in/your/app/",
    "scheme": "http",
    "cookies": {
        "token": "12345"
    },
    "method": "GET",
    "headers": {
        "Content-Length": "",
        "Content-Type": "text/plain",
        "Accept": "*/*",
    },
    "payload": {
        "files": {},
        "get": {},
        "post": {},
        "json": null
    },
    "user": {
        "is_authenticated": false,
        "is_staff": false,
        "username": "",
        "id": null,
        "pk": null
    }
}
# How should identify the request is new or duplicated
ECHO_TESTER_REQUEST_IDENTIFIERS = [
    'method', 'user.pk', 'headers.Content-Type'
]

# Skip paths starts with this
ECHO_TESTER_SKIP_PATH = [
    '/admin',
    '/secret-app'
]

Response

ResponseObject

{
    "status_code": 404,
    "cookies": {},
    "headers": {
        "Content-Type": "text/html"
    },
    "data": "[DATA DROPPED]",
    "content_length": null,
    "content_encoding": null,
    "content_type": "text/html"
}
# What to check if response is changed or broken
ECHO_TESTER_RESPONSE_CHECKS = [
    'status_code', 'headers.Content-Type'
]

# Drop html from the response default is `True`
ECHO_TESTER_DROP_HTML_FROM_RESPONSE = True

Credentials

we need to track and update credentials to make sure saved requests and responses is always valid.

# Track & update credentials or not
ECHO_TESTER_CREDENTIALS_WATCH = True

# the key of who this credentials related for (credential owner id)
ECHO_TESTER_CREDENTIALS_IDENTIFIER_KEY = 'user.pk'

# what key uses to track credentials, if you use session/token based authentication
# just add the valid kays
ECHO_TESTER_CREDENTIALS_KEYS = [
    'cookies.sessionid'
]

General settings

# raise or skip errors that happened while listening 
ECHO_TESTER_RAISE_ERRORS = True 

# stop this middleware while running tests
# just provide a part of the name if you want
ECHO_TESTER_SKIP_MIDDLEWARE_CONTAIN = [
    # FOR Example: stop csrf and stop recording
    'csrf', apps.EchoTesterConfig.name
]

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

django-echo-tester-0.0.5.tar.gz (12.7 kB view hashes)

Uploaded Source

Built Distribution

django_echo_tester-0.0.5-py3-none-any.whl (15.4 kB view hashes)

Uploaded Python 3

Supported by

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