• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 0.9
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.x
    6. Version 2.0
    7. Version 1.0
    8. Version 0.9
    9. Djblets Documentation
    10. Module and Class References
    11. djblets.webapi.testing.testcases
  • Home
  • Guides
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Web API Guides
  • Writing Web API Resources
  • Module and Class References
  • djblets
  • djblets.auth.forms
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.configforms.forms
  • djblets.configforms.pages
  • djblets.configforms.views
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.validators
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.feedview.views
  • djblets.feedview.templatetags.feedtags
  • djblets.forms.fields
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.views
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.serializers
  • djblets.util.views
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • djblets
  • djblets.auth.forms
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.configforms.forms
  • djblets.configforms.pages
  • djblets.configforms.views
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.validators
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.feedview.views
  • djblets.feedview.templatetags.feedtags
  • djblets.forms.fields
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.views
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.serializers
  • djblets.util.views
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • This documentation covers Djblets 0.9. You can select a version above or view the latest documentation.

    djblets.webapi.testing.testcases¶

    Test case support for full API testing.

    This provides a useful mixin, WebAPITestCaseMixin, that can be mixed into a base test case for an API testing suite. This mixin provides a number of useful helpers for calling APIs and validating results, along with generating consistent docstrings.

    class WebAPITestCaseMixin(methodName=’runTest’)[source]¶

    Bases: djblets.testing.testcases.TestCase

    Mixin for test cases for thoroughly testing APIs.

    This helps with the testing of APIs by providing convenient methods for performing HTTP requests and checking their response payloads, redirects, mimetypes, and more.

    Any test methods in a subclass that have the is_test_template flag set to True can include <URL> in their docstring. When the test is run, the <URL> will be replaced by the contents of the subclass’s sample_api_url.

    WebAPITestCaseMixin is meant to be mixed into a new base class that all API test suites would inherit from. Subclasses must provide values for sample_api_url and error_mimetype.

    sample_api_url = None[source]¶

    The path to the resource, which may be placed into the docstring.

    error_mimetype = None[source]¶

    The mimetype representing an error for this API.

    base_url = u’http://testserver’[source]¶

    A fake base URL for API operations.

    shortDescription()[source]¶

    Return a description for a particular test.

    If the test has the is_test_template attribute set, and contains <URL> in the docstring, the URL will be replaced by the contents of sample_api_url.

    Returns:The description of the test.
    Return type:unicode
    api_get(path, query={}, follow_redirects=False, expected_status=200, expected_redirects=[], expected_headers={}, expected_mimetype=None, expected_json=True)[source]¶

    Perform and check a HTTP GET request to an API resource.

    This will perform the request to the resource and validate that all the results are what the caller expects.

    Parameters:
    • path (unicode) – The path to the resource to request.
    • query (dict) – The query string.
    • expected_status (int) – The expected HTTP status.
    • follow_redirects (bool) – Whether to expect and follow redirects to another URL.
    • expected_redirects (list of unicode) – The list of expected redirects performed by the resource(s), in order.
    • expected_headers (dict) – Expected HTTP headers and their values from the response.
    • expected_mimetype (unicode) – The expected mimetype for the response payload.
    • expected_json (bool) – Whether the response is expected to be in JSON format.
    Returns:

    The parsed payload data as a dictionary, if expected_json is True and the response isn’t a HTTP 302. Otherwise, the raw payload contents.

    api_post_with_response(path, query={}, expected_status=201, expected_mimetype=None)[source]¶

    Perform an HTTP POST to an API resource, returning additional data.

    This works like api_post(), but returns the resulting payload and the original HttpResponse.

    This will perform the request to the resource and validate that all the results are what the caller expects.

    Parameters:
    • path (unicode) – The path to the resource to request.
    • query (dict) – The form data to post.
    • expected_status (int) – The expected HTTP status.
    • expected_mimetype (unicode) – The expected mimetype for the response payload.
    Returns:

    A 2-item tuple containing the parsed response and the original HttpResponse.

    Return type:

    tuple

    api_post(*args, **kwargs)[source]¶

    Perform and check an HTTP POST to an API resource.

    This will perform the request to the resource and validate that all the results are what the caller expects.

    Parameters:
    • path (unicode) – The path to the resource to request.
    • query (dict) – The form data to post.
    • expected_status (int) – The expected HTTP status.
    • expected_mimetype (unicode) – The expected mimetype for the response payload.
    Returns:

    The parsed payload data.

    api_put(path, query={}, expected_status=200, follow_redirects=False, expected_redirects=[], expected_mimetype=None)[source]¶

    Perform and check an HTTP PUT to an API resource.

    This will perform the request to the resource and validate that all the results are what the caller expects.

    Parameters:
    • path (unicode) – The path to the resource to request.
    • query (dict) – The form data to post.
    • expected_status (int) – The expected HTTP status.
    • follow_redirects (bool) – Whether to expect and follow redirects to another URL.
    • expected_redirects (list of unicode) – The list of expected redirects performed by the resource(s), in order.
    • expected_mimetype (unicode) – The expected mimetype for the response payload.
    Returns:

    The parsed payload data.

    api_delete(path, expected_status=204)[source]¶

    Perform and check an HTTP DELETE to an API resource.

    This will perform the request to the resource and validate that all the results are what the caller expects.

    Parameters:
    • path (unicode) – The path to the resource to request.
    • expected_status (int) – The expected HTTP status.
    Returns:

    The HTTP respons of the payload. This won’t have any content if the delete was successful.

    Return type:

    HttpResponse

    assertHttpOK(response, check_last_modified=False, check_etag=False)[source]¶

    Assert that a response was OK and optionally has caching headers.

    Parameters:
    • response (HttpResponse) – The HTTP response from the API.
    • check_last_modified (bool) – If set, this will assert that the response has a Last-Modified header.
    • check_etag (bool) – If set, this will assert that the response has a ETag header.
    assertHttpNotModified(response)[source]¶

    Assert that the response was HTTP 304 Not Modified.

    Parameters:response (HttpResponse) – The HTTP response from the API.

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]