Skip to main content

Create a Django request object that mocks a real one.

Project description

Django Request Mock
===================

Django Request Mock is an helper that allows you to generate synthetic request objects that mimic a real one, generated after a real request is being received by the framework.

Useful when coding in an HTTP isolated environment, which prevents you from accessing the request object, such as a cron method or a Celery task. This allows you to render templates and build absolute URIs from such contexts, for instance.

The request object is generated using your settings, and by default contains all the values of a request being sent to your website's default domain, using the SITE_URL configuration variable (can be of that form: https://example.com/)

## Configuration

* Add `request_mock` to your INSTALLED_APPS.

* Ensure `SITE_URL` is defined in your **settings.py**, with a value such as 'https://example.com/'

* When you need to generate a request mock object, simply use the following code:

```python
from request_mock import request_mock

# Generate the mock object
# request_mock(base, path, user) where each argument is optional
request = request_mock()

# Can also be
request = request_mock(
base='https://other.org/',
path='/some/path/for/mock/request/',
user=User.objects.get(username='dummy.user')
)
```

* All done!

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-request-mock-0.1.3.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file django-request-mock-0.1.3.tar.gz.

File metadata

File hashes

Hashes for django-request-mock-0.1.3.tar.gz
Algorithm Hash digest
SHA256 08e32b893b012608594de17fb279d5d74bd0ced917ac2a0e6739d3a19dfa8428
MD5 cf9b9d069d22591a5df0f25484ec786c
BLAKE2b-256 e77d009afa61a2fc9e95527f6c847c648071d75bf02de4adbea4e0d776bac652

See more details on using hashes here.

Provenance

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