django :: test :: client :: Client :: Class Client
[hide private]
[frames] | no frames]

Class Client


A class that can act as a client for testing purposes. It allows the user to compose GET and POST requests, and obtain the response that the server gave to those requests. The server Response objects are annotated with the details of the contexts and templates that were rendered during the process of serving the request. Client objects are stateful - they will retain cookie (and thus session) details for the lifetime of the Client instance. This is not intended as a replacement for Twill/Selenium or the like - it is here to allow testing against the contexts and templates produced by a view, rather than the HTML rendered to the end-user.
Instance Methods [hide private]
 
__init__(self, enforce_csrf_checks=False, **defaults)
x.__init__(...) initializes x; see help(type(x)) for signature
 
_handle_redirects(self, response, **extra)
Follows any redirects by requesting responses from the server using GET.
 
_session(self)
Obtains the current session variables.
 
delete(self, path, data=u'', content_type=u'application/octet-stream', follow=False, **extra)
Send a DELETE request to the server.
 
get(self, path, data={}, follow=False, **extra)
Requests a response from the server using GET.
 
head(self, path, data={}, follow=False, **extra)
Request a response from the server using HEAD.
 
login(self, **credentials)
Sets the Factory to appear as if it has successfully logged into a site.
 
logout(self)
Removes the authenticated user's cookies and session object.
 
options(self, path, data=u'', content_type=u'application/octet-stream', follow=False, **extra)
Request a response from the server using OPTIONS.
 
post(self, path, data={}, content_type=u'multipart/form-data; boundary=BoUnDaRyStRiNg', follow=False, **extra)
Requests a response from the server using POST.
 
put(self, path, data=u'', content_type=u'application/octet-stream', follow=False, **extra)
Send a resource to the server using PUT.
 
request(self, **request)
The master request method.
 
store_exc_info(self, **kwargs)
Stores exceptions when they are generated by a view.

Inherited from RequestFactory: generic

Inherited from RequestFactory (private): _base_environ, _encode_data, _get_path

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  session
Obtains the current session variables.

Inherited from object: __class__

Method Details [hide private]

__init__(self, enforce_csrf_checks=False, **defaults)
(Constructor)

 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__
(inherited documentation)

delete(self, path, data=u'', content_type=u'application/octet-stream', follow=False, **extra)

 
Send a DELETE request to the server.
Overrides: RequestFactory.delete

get(self, path, data={}, follow=False, **extra)

 
Requests a response from the server using GET.
Overrides: RequestFactory.get

head(self, path, data={}, follow=False, **extra)

 
Request a response from the server using HEAD.
Overrides: RequestFactory.head

login(self, **credentials)

 
Sets the Factory to appear as if it has successfully logged into a site. Returns True if login is possible; False if the provided credentials are incorrect, or the user is inactive, or if the sessions framework is not available.

logout(self)

 
Removes the authenticated user's cookies and session object. Causes the authenticated user to be logged out.

options(self, path, data=u'', content_type=u'application/octet-stream', follow=False, **extra)

 
Request a response from the server using OPTIONS.
Overrides: RequestFactory.options

post(self, path, data={}, content_type=u'multipart/form-data; boundary=BoUnDaRyStRiNg', follow=False, **extra)

 
Requests a response from the server using POST.
Overrides: RequestFactory.post

put(self, path, data=u'', content_type=u'application/octet-stream', follow=False, **extra)

 
Send a resource to the server using PUT.
Overrides: RequestFactory.put

request(self, **request)

 
The master request method. Composes the environment dictionary and passes to the handler, returning the result of the handler. Assumes defaults for the query environment, which can be overridden using the arguments to the request.
Overrides: RequestFactory.request

Property Details [hide private]

session

Obtains the current session variables.
Get Method:
_session(self) - Obtains the current session variables.