doc_content stringlengths 1 386k | doc_id stringlengths 5 188 |
|---|---|
patch(path, data='', content_type='application/octet-stream', follow=False, secure=False, **extra)
Makes a PATCH request on the provided path and returns a Response object. Useful for testing RESTful interfaces. The follow, secure and extra arguments act the same as for Client.get(). | django.topics.testing.tools#django.test.Client.patch |
post(path, data=None, content_type=MULTIPART_CONTENT, follow=False, secure=False, **extra)
Makes a POST request on the provided path and returns a Response object, which is documented below. The key-value pairs in the data dictionary are used to submit POST data. For example: >>> c = Client()
>>> c.post('/login/', {'... | django.topics.testing.tools#django.test.Client.post |
put(path, data='', content_type='application/octet-stream', follow=False, secure=False, **extra)
Makes a PUT request on the provided path and returns a Response object. Useful for testing RESTful interfaces. When data is provided, it is used as the request body, and a Content-Type header is set to content_type. The f... | django.topics.testing.tools#django.test.Client.put |
Client.session
A dictionary-like object containing session information. See the session documentation for full details. To modify the session and then save it, it must be stored in a variable first (because a new SessionStore is created every time this property is accessed): def test_something(self):
session = se... | django.topics.testing.tools#django.test.Client.session |
trace(path, follow=False, secure=False, **extra)
Makes a TRACE request on the provided path and returns a Response object. Useful for simulating diagnostic probes. Unlike the other request methods, data is not provided as a keyword parameter in order to comply with RFC 7231#section-4.3.8, which mandates that TRACE re... | django.topics.testing.tools#django.test.Client.trace |
class LiveServerTestCase | django.topics.testing.tools#django.test.LiveServerTestCase |
modify_settings() | django.topics.testing.tools#django.test.modify_settings |
override_settings() | django.topics.testing.tools#django.test.override_settings |
class RequestFactory | django.topics.testing.advanced#django.test.RequestFactory |
class Response
client
The test client that was used to make the request that resulted in the response.
content
The body of the response, as a bytestring. This is the final page content as rendered by the view, or any error message.
context
The template Context instance that was used to render the temp... | django.topics.testing.tools#django.test.Response |
client
The test client that was used to make the request that resulted in the response. | django.topics.testing.tools#django.test.Response.client |
content
The body of the response, as a bytestring. This is the final page content as rendered by the view, or any error message. | django.topics.testing.tools#django.test.Response.content |
context
The template Context instance that was used to render the template that produced the response content. If the rendered page used multiple templates, then context will be a list of Context objects, in the order in which they were rendered. Regardless of the number of templates used during rendering, you can re... | django.topics.testing.tools#django.test.Response.context |
exc_info
A tuple of three values that provides information about the unhandled exception, if any, that occurred during the view. The values are (type, value, traceback), the same as returned by Python’s sys.exc_info(). Their meanings are:
type: The type of the exception.
value: The exception instance.
traceback: ... | django.topics.testing.tools#django.test.Response.exc_info |
json(**kwargs)
The body of the response, parsed as JSON. Extra keyword arguments are passed to json.loads(). For example: >>> response = client.get('/foo/')
>>> response.json()['name']
'Arthur'
If the Content-Type header is not "application/json", then a ValueError will be raised when trying to parse the response. | django.topics.testing.tools#django.test.Response.json |
request
The request data that stimulated the response. | django.topics.testing.tools#django.test.Response.request |
resolver_match
An instance of ResolverMatch for the response. You can use the func attribute, for example, to verify the view that served the response: # my_view here is a function based view
self.assertEqual(response.resolver_match.func, my_view)
# class-based views need to be compared by name, as the functions
# g... | django.topics.testing.tools#django.test.Response.resolver_match |
status_code
The HTTP status of the response, as an integer. For a full list of defined codes, see the IANA status code registry. | django.topics.testing.tools#django.test.Response.status_code |
templates
A list of Template instances used to render the final content, in the order they were rendered. For each template in the list, use template.name to get the template’s file name, if the template was loaded from a file. (The name is a string such as 'admin/index.html'.) Not using Django templates? This attri... | django.topics.testing.tools#django.test.Response.templates |
wsgi_request
The WSGIRequest instance generated by the test handler that generated the response. | django.topics.testing.tools#django.test.Response.wsgi_request |
class DiscoverRunner(pattern='test*.py', top_level=None, verbosity=1, interactive=True, failfast=False, keepdb=False, reverse=False, debug_mode=False, debug_sql=False, parallel=0, tags=None, exclude_tags=None, test_name_patterns=None, pdb=False, buffer=False, enable_faulthandler=True, timing=True, shuffle=False, logger... | django.topics.testing.advanced#django.test.runner.DiscoverRunner |
DiscoverRunner.build_suite(test_labels=None, **kwargs)
Constructs a test suite that matches the test labels provided. test_labels is a list of strings describing the tests to be run. A test label can take one of four forms:
path.to.test_module.TestCase.test_method – Run a single test method in a test case.
path.to... | django.topics.testing.advanced#django.test.runner.DiscoverRunner.build_suite |
DiscoverRunner.get_test_runner_kwargs()
Returns the keyword arguments to instantiate the DiscoverRunner.test_runner with. | django.topics.testing.advanced#django.test.runner.DiscoverRunner.get_test_runner_kwargs |
DiscoverRunner.log(msg, level=None)
New in Django 4.0. If a logger is set, logs the message at the given integer logging level (e.g. logging.DEBUG, logging.INFO, or logging.WARNING). Otherwise, the message is printed to the console, respecting the current verbosity. For example, no message will be printed if the ve... | django.topics.testing.advanced#django.test.runner.DiscoverRunner.log |
DiscoverRunner.run_checks(databases)
Runs the system checks on the test databases. | django.topics.testing.advanced#django.test.runner.DiscoverRunner.run_checks |
DiscoverRunner.run_suite(suite, **kwargs)
Runs the test suite. Returns the result produced by the running the test suite. | django.topics.testing.advanced#django.test.runner.DiscoverRunner.run_suite |
DiscoverRunner.run_tests(test_labels, **kwargs)
Run the test suite. test_labels allows you to specify which tests to run and supports several formats (see DiscoverRunner.build_suite() for a list of supported formats). Deprecated since version 4.0: extra_tests is a list of extra TestCase instances to add to the suite... | django.topics.testing.advanced#django.test.runner.DiscoverRunner.run_tests |
DiscoverRunner.setup_databases(**kwargs)
Creates the test databases by calling setup_databases(). | django.topics.testing.advanced#django.test.runner.DiscoverRunner.setup_databases |
DiscoverRunner.setup_test_environment(**kwargs)
Sets up the test environment by calling setup_test_environment() and setting DEBUG to self.debug_mode (defaults to False). | django.topics.testing.advanced#django.test.runner.DiscoverRunner.setup_test_environment |
DiscoverRunner.suite_result(suite, result, **kwargs)
Computes and returns a return code based on a test suite, and the result from that test suite. | django.topics.testing.advanced#django.test.runner.DiscoverRunner.suite_result |
DiscoverRunner.teardown_databases(old_config, **kwargs)
Destroys the test databases, restoring pre-test conditions by calling teardown_databases(). | django.topics.testing.advanced#django.test.runner.DiscoverRunner.teardown_databases |
DiscoverRunner.teardown_test_environment(**kwargs)
Restores the pre-test environment. | django.topics.testing.advanced#django.test.runner.DiscoverRunner.teardown_test_environment |
DiscoverRunner.test_loader
This is the class that loads tests, whether from TestCases or modules or otherwise and bundles them into test suites for the runner to execute. By default it is set to unittest.defaultTestLoader. You can override this attribute if your tests are going to be loaded in unusual ways. | django.topics.testing.advanced#django.test.runner.DiscoverRunner.test_loader |
DiscoverRunner.test_runner
This is the class of the low-level test runner which is used to execute the individual tests and format the results. By default it is set to unittest.TextTestRunner. Despite the unfortunate similarity in naming conventions, this is not the same type of class as DiscoverRunner, which covers ... | django.topics.testing.advanced#django.test.runner.DiscoverRunner.test_runner |
DiscoverRunner.test_suite
The class used to build the test suite. By default it is set to unittest.TestSuite. This can be overridden if you wish to implement different logic for collecting tests. | django.topics.testing.advanced#django.test.runner.DiscoverRunner.test_suite |
django.test.signals.setting_changed | django.ref.signals#django.test.signals.setting_changed |
django.test.signals.template_rendered | django.ref.signals#django.test.signals.template_rendered |
class SimpleTestCase | django.topics.testing.tools#django.test.SimpleTestCase |
SimpleTestCase.assertContains(response, text, count=None, status_code=200, msg_prefix='', html=False)
Asserts that a response produced the given status_code and that text appears in its content. If count is provided, text must occur exactly count times in the response. Set html to True to handle text as HTML. The com... | django.topics.testing.tools#django.test.SimpleTestCase.assertContains |
SimpleTestCase.assertFieldOutput(fieldclass, valid, invalid, field_args=None, field_kwargs=None, empty_value='')
Asserts that a form field behaves correctly with various inputs.
Parameters:
fieldclass – the class of the field to be tested.
valid – a dictionary mapping valid inputs to their expected cleaned va... | django.topics.testing.tools#django.test.SimpleTestCase.assertFieldOutput |
SimpleTestCase.assertFormError(response, form, field, errors, msg_prefix='')
Asserts that a field on a form raises the provided list of errors when rendered on the form. response must be a response instance returned by the test client. form is the name the Form instance was given in the template context of the respon... | django.topics.testing.tools#django.test.SimpleTestCase.assertFormError |
SimpleTestCase.assertFormsetError(response, formset, form_index, field, errors, msg_prefix='')
Asserts that the formset raises the provided list of errors when rendered. response must be a response instance returned by the test client. formset is the name the Formset instance was given in the template context of the ... | django.topics.testing.tools#django.test.SimpleTestCase.assertFormsetError |
SimpleTestCase.assertHTMLEqual(html1, html2, msg=None)
Asserts that the strings html1 and html2 are equal. The comparison is based on HTML semantics. The comparison takes following things into account: Whitespace before and after HTML tags is ignored. All types of whitespace are considered equivalent. All open tags ... | django.topics.testing.tools#django.test.SimpleTestCase.assertHTMLEqual |
SimpleTestCase.assertHTMLNotEqual(html1, html2, msg=None)
Asserts that the strings html1 and html2 are not equal. The comparison is based on HTML semantics. See assertHTMLEqual() for details. html1 and html2 must contain HTML. An AssertionError will be raised if one of them cannot be parsed. Output in case of error c... | django.topics.testing.tools#django.test.SimpleTestCase.assertHTMLNotEqual |
SimpleTestCase.assertInHTML(needle, haystack, count=None, msg_prefix='')
Asserts that the HTML fragment needle is contained in the haystack one. If the count integer argument is specified, then additionally the number of needle occurrences will be strictly verified. Whitespace in most cases is ignored, and attribute ... | django.topics.testing.tools#django.test.SimpleTestCase.assertInHTML |
SimpleTestCase.assertJSONEqual(raw, expected_data, msg=None)
Asserts that the JSON fragments raw and expected_data are equal. Usual JSON non-significant whitespace rules apply as the heavyweight is delegated to the json library. Output in case of error can be customized with the msg argument. | django.topics.testing.tools#django.test.SimpleTestCase.assertJSONEqual |
SimpleTestCase.assertJSONNotEqual(raw, expected_data, msg=None)
Asserts that the JSON fragments raw and expected_data are not equal. See assertJSONEqual() for further details. Output in case of error can be customized with the msg argument. | django.topics.testing.tools#django.test.SimpleTestCase.assertJSONNotEqual |
SimpleTestCase.assertNotContains(response, text, status_code=200, msg_prefix='', html=False)
Asserts that a response produced the given status_code and that text does not appear in its content. Set html to True to handle text as HTML. The comparison with the response content will be based on HTML semantics instead of... | django.topics.testing.tools#django.test.SimpleTestCase.assertNotContains |
SimpleTestCase.assertRaisesMessage(expected_exception, expected_message, callable, *args, **kwargs)
SimpleTestCase.assertRaisesMessage(expected_exception, expected_message)
Asserts that execution of callable raises expected_exception and that expected_message is found in the exception’s message. Any other outcome i... | django.topics.testing.tools#django.test.SimpleTestCase.assertRaisesMessage |
SimpleTestCase.assertRedirects(response, expected_url, status_code=302, target_status_code=200, msg_prefix='', fetch_redirect_response=True)
Asserts that the response returned a status_code redirect status, redirected to expected_url (including any GET data), and that the final page was received with target_status_co... | django.topics.testing.tools#django.test.SimpleTestCase.assertRedirects |
SimpleTestCase.assertTemplateNotUsed(response, template_name, msg_prefix='')
Asserts that the template with the given name was not used in rendering the response. You can use this as a context manager in the same way as assertTemplateUsed(). | django.topics.testing.tools#django.test.SimpleTestCase.assertTemplateNotUsed |
SimpleTestCase.assertTemplateUsed(response, template_name, msg_prefix='', count=None)
Asserts that the template with the given name was used in rendering the response. response must be a response instance returned by the test client. template_name should be a string such as 'admin/index.html'. The count argument is a... | django.topics.testing.tools#django.test.SimpleTestCase.assertTemplateUsed |
SimpleTestCase.assertURLEqual(url1, url2, msg_prefix='')
Asserts that two URLs are the same, ignoring the order of query string parameters except for parameters with the same name. For example, /path/?x=1&y=2 is equal to /path/?y=2&x=1, but /path/?a=1&a=2 isn’t equal to /path/?a=2&a=1. | django.topics.testing.tools#django.test.SimpleTestCase.assertURLEqual |
SimpleTestCase.assertWarnsMessage(expected_warning, expected_message, callable, *args, **kwargs)
SimpleTestCase.assertWarnsMessage(expected_warning, expected_message)
Analogous to SimpleTestCase.assertRaisesMessage() but for assertWarnsRegex() instead of assertRaisesRegex(). | django.topics.testing.tools#django.test.SimpleTestCase.assertWarnsMessage |
SimpleTestCase.assertXMLEqual(xml1, xml2, msg=None)
Asserts that the strings xml1 and xml2 are equal. The comparison is based on XML semantics. Similarly to assertHTMLEqual(), the comparison is made on parsed content, hence only semantic differences are considered, not syntax differences. When invalid XML is passed i... | django.topics.testing.tools#django.test.SimpleTestCase.assertXMLEqual |
SimpleTestCase.assertXMLNotEqual(xml1, xml2, msg=None)
Asserts that the strings xml1 and xml2 are not equal. The comparison is based on XML semantics. See assertXMLEqual() for details. Output in case of error can be customized with the msg argument. | django.topics.testing.tools#django.test.SimpleTestCase.assertXMLNotEqual |
SimpleTestCase.client | django.topics.testing.tools#django.test.SimpleTestCase.client |
SimpleTestCase.client_class | django.topics.testing.tools#django.test.SimpleTestCase.client_class |
SimpleTestCase.databases
SimpleTestCase disallows database queries by default. This helps to avoid executing write queries which will affect other tests since each SimpleTestCase test isn’t run in a transaction. If you aren’t concerned about this problem, you can disable this behavior by setting the databases class a... | django.topics.testing.tools#django.test.SimpleTestCase.databases |
SimpleTestCase.modify_settings() | django.topics.testing.tools#django.test.SimpleTestCase.modify_settings |
SimpleTestCase.settings() | django.topics.testing.tools#django.test.SimpleTestCase.settings |
skipIfDBFeature(*feature_name_strings) | django.topics.testing.tools#django.test.skipIfDBFeature |
skipUnlessDBFeature(*feature_name_strings) | django.topics.testing.tools#django.test.skipUnlessDBFeature |
class TestCase | django.topics.testing.tools#django.test.TestCase |
TestCase.databases | django.topics.testing.tools#django.test.TestCase.databases |
class TransactionTestCase | django.topics.testing.tools#django.test.TransactionTestCase |
TransactionTestCase.assertNumQueries(num, func, *args, **kwargs)
Asserts that when func is called with *args and **kwargs that num database queries are executed. If a "using" key is present in kwargs it is used as the database alias for which to check the number of queries: self.assertNumQueries(7, using='non_default... | django.topics.testing.tools#django.test.TransactionTestCase.assertNumQueries |
TransactionTestCase.assertQuerysetEqual(qs, values, transform=None, ordered=True, msg=None)
Asserts that a queryset qs matches a particular iterable of values values. If transform is provided, values is compared to a list produced by applying transform to each member of qs. By default, the comparison is also ordering... | django.topics.testing.tools#django.test.TransactionTestCase.assertQuerysetEqual |
TransactionTestCase.available_apps
Warning This attribute is a private API. It may be changed or removed without a deprecation period in the future, for instance to accommodate changes in application loading. It’s used to optimize Django’s own test suite, which contains hundreds of models but no relations between mo... | django.topics.testing.advanced#django.test.TransactionTestCase.available_apps |
TransactionTestCase.databases | django.topics.testing.tools#django.test.TransactionTestCase.databases |
TransactionTestCase.fixtures | django.topics.testing.tools#django.test.TransactionTestCase.fixtures |
TransactionTestCase.reset_sequences
Setting reset_sequences = True on a TransactionTestCase will make sure sequences are always reset before the test run: class TestsThatDependsOnPrimaryKeySequences(TransactionTestCase):
reset_sequences = True
def test_animal_pk(self):
lion = Animal.objects.create(na... | django.topics.testing.advanced#django.test.TransactionTestCase.reset_sequences |
setup_databases(verbosity, interactive, *, time_keeper=None, keepdb=False, debug_sql=False, parallel=0, aliases=None, serialized_aliases=None, **kwargs)
Creates the test databases. Returns a data structure that provides enough detail to undo the changes that have been made. This data will be provided to the teardown_... | django.topics.testing.advanced#django.test.utils.setup_databases |
setup_test_environment(debug=None)
Performs global pre-test setup, such as installing instrumentation for the template rendering system and setting up the dummy email outbox. If debug isn’t None, the DEBUG setting is updated to its value. | django.topics.testing.advanced#django.test.utils.setup_test_environment |
teardown_databases(old_config, parallel=0, keepdb=False)
Destroys the test databases, restoring pre-test conditions. old_config is a data structure defining the changes in the database configuration that need to be reversed. It’s the return value of the setup_databases() method. | django.topics.testing.advanced#django.test.utils.teardown_databases |
teardown_test_environment()
Performs global post-test teardown, such as removing instrumentation from the template system and restoring normal email services. | django.topics.testing.advanced#django.test.utils.teardown_test_environment |
Translation Overview In order to make a Django project translatable, you have to add a minimal number of hooks to your Python code and templates. These hooks are called translation strings. They tell Django: “This text should be translated into the end user’s language, if a translation for this text is available in tha... | django.topics.i18n.translation |
get_script_prefix() | django.ref.urlresolvers#django.urls.get_script_prefix |
include(module, namespace=None)
include(pattern_list)
include((pattern_list, app_namespace), namespace=None)
A function that takes a full Python import path to another URLconf module that should be “included” in this place. Optionally, the application namespace and instance namespace where the entries will be inc... | django.ref.urls#django.urls.include |
path(route, view, kwargs=None, name=None) | django.ref.urls#django.urls.path |
re_path(route, view, kwargs=None, name=None) | django.ref.urls#django.urls.re_path |
register_converter(converter, type_name) | django.ref.urls#django.urls.register_converter |
resolve(path, urlconf=None) | django.ref.urlresolvers#django.urls.resolve |
class ResolverMatch
func
The view function that would be used to serve the URL
args
The arguments that would be passed to the view function, as parsed from the URL.
kwargs
The keyword arguments that would be passed to the view function, as parsed from the URL.
url_name
The name of the URL patter... | django.ref.urlresolvers#django.urls.ResolverMatch |
app_name
The application namespace for the URL pattern that matches the URL. | django.ref.urlresolvers#django.urls.ResolverMatch.app_name |
app_names
The list of individual namespace components in the full application namespace for the URL pattern that matches the URL. For example, if the app_name is 'foo:bar', then app_names will be ['foo', 'bar']. | django.ref.urlresolvers#django.urls.ResolverMatch.app_names |
args
The arguments that would be passed to the view function, as parsed from the URL. | django.ref.urlresolvers#django.urls.ResolverMatch.args |
func
The view function that would be used to serve the URL | django.ref.urlresolvers#django.urls.ResolverMatch.func |
kwargs
The keyword arguments that would be passed to the view function, as parsed from the URL. | django.ref.urlresolvers#django.urls.ResolverMatch.kwargs |
namespace
The instance namespace for the URL pattern that matches the URL. | django.ref.urlresolvers#django.urls.ResolverMatch.namespace |
namespaces
The list of individual namespace components in the full instance namespace for the URL pattern that matches the URL. i.e., if the namespace is foo:bar, then namespaces will be ['foo', 'bar']. | django.ref.urlresolvers#django.urls.ResolverMatch.namespaces |
route
The route of the matching URL pattern. For example, if path('users/<id>/', ...) is the matching pattern, route will contain 'users/<id>/'. | django.ref.urlresolvers#django.urls.ResolverMatch.route |
tried
New in Django 3.2. The list of URL patterns tried before the URL either matched one or exhausted available patterns. | django.ref.urlresolvers#django.urls.ResolverMatch.tried |
url_name
The name of the URL pattern that matches the URL. | django.ref.urlresolvers#django.urls.ResolverMatch.url_name |
view_name
The name of the view that matches the URL, including the namespace if there is one. | django.ref.urlresolvers#django.urls.ResolverMatch.view_name |
reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None) | django.ref.urlresolvers#django.urls.reverse |
reverse_lazy(viewname, urlconf=None, args=None, kwargs=None, current_app=None) | django.ref.urlresolvers#django.urls.reverse_lazy |
add_never_cache_headers(response)
Adds a Cache-Control: max-age=0, no-cache, no-store, must-revalidate,
private header to a response to indicate that a page should never be cached. | django.ref.utils#django.utils.cache.add_never_cache_headers |
get_cache_key(request, key_prefix=None, method='GET', cache=None)
Returns a cache key based on the request path. It can be used in the request phase because it pulls the list of headers to take into account from the global path registry and uses those to build a cache key to check against. If there is no headerlist s... | django.ref.utils#django.utils.cache.get_cache_key |
get_max_age(response)
Returns the max-age from the response Cache-Control header as an integer (or None if it wasn’t found or wasn’t an integer). | django.ref.utils#django.utils.cache.get_max_age |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.