rest_framework.test

Module Contents

force_authenticate(request, user=None, token=None)
class HeaderDict

Bases:rest_framework.compat.requests.packages.urllib3._collections.HTTPHeaderDict

get_all(self, key, default)
class CoreAPIClient(*args, **kwargs)

Bases:rest_framework.compat.coreapi.Client

session
class APIRequestFactory(enforce_csrf_checks=False, **defaults)

Bases:django.test.client.RequestFactory

renderer_classes_list
default_format
_encode_data(self, data, format=None, content_type=None)

Encode the data returning a two tuple of (bytes, content_type)

get(self, path, data=None, **extra)
post(self, path, data=None, format=None, content_type=None, **extra)
put(self, path, data=None, format=None, content_type=None, **extra)
patch(self, path, data=None, format=None, content_type=None, **extra)
delete(self, path, data=None, format=None, content_type=None, **extra)
options(self, path, data=None, format=None, content_type=None, **extra)
generic(self, method, path, data='', content_type='application/octet-stream', secure=False, **extra)
request(self, **kwargs)
class ForceAuthClientHandler(*args, **kwargs)

Bases:django.test.client.ClientHandler

A patched version of ClientHandler that can enforce authentication on the outgoing requests.

get_response(self, request)
class APIClient(enforce_csrf_checks=False, **defaults)

Bases:rest_framework.test.APIRequestFactory, django.test.client.Client

credentials(self, **kwargs)

Sets headers that will be used on every outgoing request.

force_authenticate(self, user=None, token=None)

Forcibly authenticates outgoing requests with the given user and/or token.

request(self, **kwargs)
get(self, path, data=None, follow=False, **extra)
post(self, path, data=None, format=None, content_type=None, follow=False, **extra)
put(self, path, data=None, format=None, content_type=None, follow=False, **extra)
patch(self, path, data=None, format=None, content_type=None, follow=False, **extra)
delete(self, path, data=None, format=None, content_type=None, follow=False, **extra)
options(self, path, data=None, format=None, content_type=None, follow=False, **extra)
logout(self)
class APITransactionTestCase

Bases:django.test.testcases.TransactionTestCase

client_class
class APITestCase

Bases:django.test.testcases.TestCase

client_class
class APISimpleTestCase

Bases:django.test.testcases.SimpleTestCase

client_class
class APILiveServerTestCase

Bases:django.test.testcases.LiveServerTestCase

client_class
class URLPatternsTestCase

Bases:django.test.testcases.SimpleTestCase

Isolate URL patterns on a per-TestCase basis. For example,

class ATestCase(URLPatternsTestCase):

urlpatterns = […]

def test_something(self):
class AnotherTestCase(URLPatternsTestCase):

urlpatterns = […]

def test_something_else(self):
classmethod setUpClass(cls)
classmethod tearDownClass(cls)