Request

These fixtures are related to Django request objects.

class pytest_djangoapp.fixtures.request.DjagoappClient(*, ajax: bool = False, user: AbstractUser = None, enforce_csrf_checks: bool = False, raise_exceptions: bool = True, json: bool = False, **defaults)
store_exc_info(**kwargs)

Store exceptions when they are generated by a view.

class pytest_djangoapp.fixtures.request.DjangoappRequestFactory(ajax=False, json=False, **defaults)
generic(method, path, *args, **kwargs)

Construct an arbitrary HTTP request.

pytest_djangoapp.fixtures.request.request_client()

Fixture allowing test client object generation.

Example:

def test_this(request_client):

    client = request_client()

    response = client.get(
        ('someview', {'somearg': 'one', 'otherarg': 33})
    ).content

    ...

    ajax_client = request_client(ajax=True)
    ...
Parameters:
  • ajax – Make AJAX (XMLHttpRequest) requests.
  • user – User to perform queries from.
  • raise_exceptions – Do not allow Django technical exception handlers to catch exceptions issued by views, propagate them instead.
  • json

    Encode data as JSON.

    Warning

    To be used with Django 2.1+

  • kwargs – Additional arguments for test client initialization.
pytest_djangoapp.fixtures.request.request_factory()

Fixture allowing request object generation.

Example:

def test_this(request_factory):
    factory = request_factory()
Parameters:kwargs
pytest_djangoapp.fixtures.request.request_get(request_factory)

Fixture allowing GET request object generation.

Example:

def test_this(request_get):
    request = request_get('/some')
Parameters:
  • path
  • user – User making this request.
  • ajax – Make AJAX (XMLHttpRequest) request.
  • kwargs – Additional arguments for .get() method.
pytest_djangoapp.fixtures.request.request_post(request_factory)

Fixture allowing POST request object generation.

Example:

def test_this(request_post):
    request = request_post('/some', {'a': 'b'})
Parameters:
  • path
  • data – Data to post.
  • user – User making this request.
  • ajax – Make AJAX (XMLHttpRequest) request.
  • kwargs – Additional arguments for .post() method.