• 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. RBTools dev
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.0
    6. Version 1.0
    7. Version 0.7
    8. Version 0.6
    9. Version 0.5
    10. RBTools Python API
    11. Module and Class References
    12. rbtools.testing.api.payloads
  • Home
  • Installing RBTools
  • rbt Command
  • Configuration
  • Authenticating to Review Board
  • Repository Configuration
  • Per-User Configuration
  • Team Foundation Server Configuration
  • Commands
  • alias
  • api-get
  • attach
  • clear-cache
  • close
  • diff
  • install
  • land
  • list-repo-types
  • login
  • logout
  • patch
  • post
  • publish
  • review
  • setup-completion
  • setup-repo
  • stamp
  • status
  • status-update
  • RBTools Workflows
  • Using RBTools With Cliosoft SOS
  • Using RBTools with Git
  • Using RBTools with HCL VersionVault and IBM ClearCase
  • Using RBTools With Perforce
  • RBTools Python API
  • Overview of the Python API Client
  • Tutorial
  • Resource-Specific Functionality
  • Module and Class References
  • rbtools
  • rbtools.deprecation
  • rbtools.api
  • rbtools.api.cache
  • rbtools.api.capabilities
  • rbtools.api.client
  • rbtools.api.decode
  • rbtools.api.decorators
  • rbtools.api.errors
  • rbtools.api.factory
  • rbtools.api.request
  • rbtools.api.resource
  • rbtools.api.transport
  • rbtools.api.transport.sync
  • rbtools.api.utils
  • rbtools.clients
  • rbtools.clients.base
  • rbtools.clients.base.patch
  • rbtools.clients.base.registry
  • rbtools.clients.base.repository
  • rbtools.clients.base.scmclient
  • rbtools.clients.errors
  • rbtools.clients.bazaar
  • rbtools.clients.clearcase
  • rbtools.clients.cvs
  • rbtools.clients.git
  • rbtools.clients.mercurial
  • rbtools.clients.perforce
  • rbtools.clients.plastic
  • rbtools.clients.sos
  • rbtools.clients.svn
  • rbtools.clients.tfs
  • rbtools.config
  • rbtools.config.config
  • rbtools.config.loader
  • rbtools.diffs
  • rbtools.diffs.patches
  • rbtools.diffs.patcher
  • rbtools.diffs.tools
  • rbtools.diffs.tools.backends
  • rbtools.diffs.tools.backends.gnu
  • rbtools.diffs.tools.base
  • rbtools.diffs.tools.base.diff_file_result
  • rbtools.diffs.tools.base.diff_tool
  • rbtools.diffs.tools.errors
  • rbtools.diffs.tools.registry
  • rbtools.diffs.writers
  • rbtools.commands
  • rbtools.commands.main
  • rbtools.commands
  • rbtools.commands.base
  • rbtools.commands.base.commands
  • rbtools.commands.base.errors
  • rbtools.commands.base.options
  • rbtools.commands.base.output
  • rbtools.commands.alias
  • rbtools.commands.api_get
  • rbtools.commands.attach
  • rbtools.commands.clearcache
  • rbtools.commands.close
  • rbtools.commands.diff
  • rbtools.commands.info
  • rbtools.commands.install
  • rbtools.commands.land
  • rbtools.commands.list_repo_types
  • rbtools.commands.login
  • rbtools.commands.logout
  • rbtools.commands.patch
  • rbtools.commands.post
  • rbtools.commands.publish
  • rbtools.commands.review
  • rbtools.commands.setup_completion
  • rbtools.commands.setup_repo
  • rbtools.commands.stamp
  • rbtools.commands.status
  • rbtools.commands.status_update
  • rbtools.hooks
  • rbtools.hooks.common
  • rbtools.hooks.git
  • rbtools.testing
  • rbtools.testing.api
  • rbtools.testing.api.payloads
  • rbtools.testing.api.transport
  • rbtools.testing.commands
  • rbtools.testing.testcase
  • rbtools.testing.transport
  • rbtools.utils
  • rbtools.utils.aliases
  • rbtools.utils.browser
  • rbtools.utils.checks
  • rbtools.utils.commands
  • rbtools.utils.console
  • rbtools.utils.diffs
  • rbtools.utils.encoding
  • rbtools.utils.errors
  • rbtools.utils.filesystem
  • rbtools.utils.graphs
  • rbtools.utils.mimetypes
  • rbtools.utils.process
  • rbtools.utils.repository
  • rbtools.utils.review_request
  • rbtools.utils.source_tree
  • rbtools.utils.users
  • Glossary
  • General Index
  • Python Module Index
  • Release Notes
  • This documentation covers the in-development release of RBTools. You can see the stable RBTools documentation or all previous versions.

    rbtools.testing.api.payloads¶

    API payload generation factory for unit tests.

    New in version 3.1.

    Classes

    LinkExpansionType()

    A type of link expansion.

    ResourcePayloadFactory(server_url)

    Factory for creating simulated API payloads for testing.

    class rbtools.testing.api.payloads.LinkExpansionType[source]¶

    Bases: object

    A type of link expansion.

    This helps to indicate if a link should expand as an item or a list.

    New in version 3.1.

    LIST = 1[source]¶

    Always expand links as lists.

    ITEM = 2[source]¶

    Expand links as individual items (if contents are not a list).

    class rbtools.testing.api.payloads.ResourcePayloadFactory(server_url)[source]¶

    Bases: object

    Factory for creating simulated API payloads for testing.

    This can be used by unit tests (first-party or third-party) or the testing framework to create API payloads that commands or other RBTools logic can test against.

    The results of these aren’t directly injected into any transport. Instead, they’re meant to be built and passed into something like a KGB spy or the rbtools.testing.api.transport.URLMapTransport.

    There are two kinds of payload data that this factory can generate:

    1. HTTP response payloads

      The full payload that would normally be serialized and then sent to a browser in a HTTP response. There are list, item, and error response payload generators:

      • make_error_response_payload()

      • make_item_response_payload()

      • make_list_response_payload()

    2. Object payload data

      These generate data for an object residing in part of the resource tree, for use within either a list or an item response payload. The results are dictionaries that contain:

      Keys:
      item_key (unicode):

      The name of the key that would map to the payload in an item resource. If None, then the contents of the payload will be merged into the root of the response payload.

      mimetype (unicode):

      The mimetype representing the object.

      payload (dict):

      The object payload data, for embedding into item or list response payloads.

      url (unicode):

      The URL to where the item resource for this object would live.

      headers (dict, optional):

      Any optional headers that may correspond to the result when in an item response payload.

      These generators include:

      • make_api_info_object_data()

      • make_repository_object_data()

      • make_repository_info_object_data()

      • make_review_request_draft_object_data()

      • make_review_request_object_data()

      • make_root_object_data()

      • make_session_object_data()

      • make_user_object_data()

    Whenever unit tests need to generate a type of payload not provided in this factory, they should add a suitable function to the factory rather than create it themselves. This will help provide consistency across all unit tests.

    New in version 3.1.

    DEFAULT_CAPABILITIES = {'diffs': {'base_commit_ids': True, 'moved_files': True, 'validation': {'base_commit_ids': True}}, 'extra_data': {'json_patching': True}, 'review_requests': {'commit_ids': True, 'supports_history': True, 'trivial_publish': True}, 'scmtools': {'git': {'empty_files': True, 'symlinks': True}, 'mercurial': {'empty_files': True}, 'perforce': {'empty_files': True, 'moved_files': True}, 'svn': {'empty_files': True}}, 'text': {'can_include_raw_values': True, 'markdown': True, 'per_field_text_types': True}}[source]¶

    The default capabilities that go into the root resource.

    __init__(server_url)[source]¶

    Initialize the factory.

    Parameters:

    server_url (unicode) – The URL to the simulated server. This must ends with /.

    expand_link(payload, link_key, expanded_payload, expand_key=None, expansion_type=None)[source]¶

    Expand a link in the payload.

    This will remove the link from links and add the provided expanded payload to the object payload.

    Parameters:
    • payload (dict) – The payload where the epanded resource will be provided, and where links resides.

    • link_key (unicode) – The name of the link key.

    • expanded_payload (dict or list of dict) – The payload or list of payloads to put in the object payload under the key.

    • expand_key (unicode, optional) – The key to use for the expanded payloads. If not provided, this defaults to the value of link_key.

    make_mimetype(name, payload_format='json')[source]¶

    Return a mimetype for a resource.

    Parameters:
    • name (unicode) – The name of the mimetype, following application/vnd.reviewboard.org.

    • payload_format (unicode, optional) – The payload format indicator, following the +.

    Returns:

    The mimetype for the resource.

    Return type:

    unicode

    make_item_response_payload(object_payload, item_key=None)[source]¶

    Return a new item response payload.

    This will generate a success payload with the provided object payload, either nested within item_key or merged into the root of the payload.

    This is used for items and singletons.

    Parameters:
    • object_payload (dict) – The object payload to include within the response payload.

    • item_key (unicode, optional) – A key to place the object payload within. If None, the object payload will instead be merged into the root of the response payload.

    Returns:

    The item response payload.

    Return type:

    dict

    make_list_response_payload(url, list_key, items)[source]¶

    Return a new list response payload.

    This will generate a success payload with the given list of items, total result count, and list of links.

    Note that this does not handle pagination at this time. All provided items will be included.

    Parameters:
    • url (unicode) – The absolute or relative URL where this list resource would live.

    • list_key (unicode) – The key within the payload that maps to the list of items.

    • items (list of dict) – The list of item payloads to include.

    Returns:

    The list response payload.

    Return type:

    dict

    make_error_response_payload(error_code, error_message, payload_extra={})[source]¶

    Return a new error response payload.

    This will generate an error payload with the given code, message, and any extra payload state to merge into the root of the response payload.

    Parameters:
    • error_code (int) – The API error code.

    • error_message (unicode) – The error message to show.

    • payload_extra (dict, optional) – Optional extra payload state to merge into the root of the response payload.

    Returns:

    The error response payload.

    Return type:

    dict

    make_root_object_data(package_version='5.0.0', version='5.0', capabilities=None)[source]¶

    Return new root resource data.

    Parameters:
    • package_version (unicode) – The Review Board package version to include in the API results. Callers should expect that this value may change over time, and should provide any values they may need for the test.

    • version (unicode) – The Review Board display version to include in the API results. Callers should expect that this value may change over time, and should provide any values they may need for the test.

    • capabilities (dict, optional) – Optional explicit capabilities to include. If not provided, this will use a copy of DEFAULT_CAPABILITIES.

    Returns:

    The resource payload and metadata. See the class documentation for details.

    Return type:

    dict

    make_api_info_object_data(root_payload)[source]¶

    Return new API info resource data.

    Parameters:

    root_payload (dict) – An existing payload for the root resource. The relevant data from that resource will be copied into here.

    Returns:

    The resource payload and metadata. See the class documentation for details.

    Return type:

    dict

    make_repository_object_data(repository_id=1, name='Test Repository', tool='Git', path='/path/to/repo.git', mirror_path='', bug_tracker='', visible=True, extra_data={})[source]¶

    Return new repository resource data.

    Parameters:
    • repository_id (int, optional) – The value of the id field. The URL will also include this value.

    • name (unicode, optional) – The value of the name field.

    • tool (unicode, optional) – The value of the tool field.

    • path (unicode, optional) – The value of the path field.

    • mirror_path (unicode, optional) – The value of the mirror_path field.

    • bug_tracker (unicode, optional) – The value of the bug_tracker field.

    • visible (bool, optional) – The value of the visible field.

    • extra_data (dict, optional) – The value of the extra_data field.

    Returns:

    The resource payload and metadata. See the class documentation for details.

    Return type:

    dict

    make_repository_info_object_data(repository_id, info_payload)[source]¶

    Return new repository info resource data.

    Parameters:
    • repository_id (int, optional) – The value of the id field. The URL will also include this value.

    • info_payload (dict, optional) – The repository-specific payload to include within the info key.

    Returns:

    The resource payload and metadata. See the class documentation for details.

    Return type:

    dict

    make_review_request_object_data(review_request_id, approval_failure=None, approved=False, blocks_ids=[], branch='test-branch', bugs_closed=[], changenum=None, close_description='', close_description_text_type='plain', commit_id=None, created_with_history=True, depends_on_ids=[], description='Test Description', description_text_type='plain', extra_data={}, issue_dropped_count=0, issue_open_count=0, issue_resolved_count=0, issue_verifying_count=0, last_updated='2022-04-21T15:44:00Z', public=True, repository_id=None, ship_it_count=0, status='pending', submitter_username='test-user', summary='Test Summary', target_group_names=[], target_people_usernames=[], testing_done='Test Testing Done', testing_done_text_type='plain', text_type=None, time_added='2022-04-21T12:30:00Z', latest_diff_id=1)[source]¶

    Return new review request resource data.

    Parameters:
    • review_request_id (int) – The ID of the review request.

    • approval_failure (unicode, optional) – The value of the approval_failure field.

    • approved (bool, optional) – The value of the approved field.

    • blocks_ids (list of int, optional) – A list of review request IDs that this blocks, for use in the blocks field.

    • branch (unicode, optional) – The value of the branch field.

    • bugs_closed (list of unicode, optional) – The value of the bugs_closed field.

    • changenum (int, optional) – The value of the changenum field.

    • close_description (unicode, optional) – The value of the close_description field.

    • _text_type (close_description) – The value of the close_description_text_type field.

    • commit_id (unicode, optional) – The value of the commit_id field.

    • created_with_history (bool, optional) – The value of the created_with_history field.

    • depends_on_ids (list of int, optional) – A list of review request IDs that this depends on, for use in the depends_on field.

    • description (unicode, optional) – The value of the description field.

    • description_text_type (unicode, optional) – The value of the description_text_type field.

    • extra_data (dict, optional) – The value of the extra_data field.

    • issue_dropped_count (int, optional) – The value of the issue_dropped_count field.

    • issue_open_count (int, optional) – The value of the issue_open_count field.

    • issue_resolved_count (int, optional) – The value of the issue_resolved_count field.

    • issue_verifying_count (int, optional) – The value of the issue_verifying_count field.

    • last_updated (unicode, optional) – The value of the last_updated field.

    • public (bool, optional) – The value of the public field.

    • repository_id (int, optional) – The ID of the repository, for the repository link.

    • ship_it_count (int, optional) – The value of the ship_it_count field.

    • status (unicode, optional) – The value of the status field.

    • submitter_username (unicode, optional) – The username of the submitter, for the submitter link.

    • summary (unicode, optional) – The value of the summary field.

    • target_group_names (unicode, optional) – A list of group names, for use in the target_groups field.

    • target_people_usernames (unicode, optional) – A list of usernames, for use in the target_people field.

    • testing_done (unicode, optional) – The value of the testing_done field.

    • testing_done_text_type (unicode, optional) – The value of the testing_done_text_type field.

    • text_type (unicode, optional) – The value of the text_type field.

    • time_added (unicode, optional) – The value of the time_added field.

    • latest_diff_id (int, optional) – The ID of the last diff on the review request, for use in the latest_diff link.

    Returns:

    The resource payload and metadata. See the class documentation for details.

    Return type:

    dict

    make_review_request_draft_object_data(draft_id, review_request_id, branch='test-branch', bugs_closed=[], close_description='', close_description_text_type='plain', commit_id=None, depends_on_ids=[], description='Test Description', description_text_type='plain', extra_data={}, last_updated='2022-04-21T15:44:00Z', public=True, submitter_username='test-user', summary='Test Summary', target_group_names=[], target_people_usernames=[], testing_done='Test Testing Done', testing_done_text_type='plain', text_type=None)[source]¶

    Return new review request draft resource data.

    Parameters:
    • draft_id (int) – The ID of the review request draft.

    • review_request_id (int) – The ID of the review request.

    • branch (unicode, optional) – The value of the branch field.

    • bugs_closed (list of unicode, optional) – The value of the bugs_closed field.

    • close_description (unicode, optional) – The value of the close_description field.

    • _text_type (close_description) – The value of the close_description_text_type field.

    • commit_id (unicode, optional) – The value of the commit_id field.

    • depends_on_ids (list of int, optional) – A list of review request IDs that this depends on, for use in the depends_on field.

    • description (unicode, optional) – The value of the description field.

    • description_text_type (unicode, optional) – The value of the description_text_type field.

    • extra_data (dict, optional) – The value of the extra_data field.

    • last_updated (unicode, optional) – The value of the last_updated field.

    • public (bool, optional) – The value of the public field.

    • submitter_username (unicode, optional) – The username of the submitter, for the submitter link.

    • summary (unicode, optional) – The value of the summary field.

    • target_group_names (unicode, optional) – A list of group names, for use in the target_groups field.

    • target_people_usernames (unicode, optional) – A list of usernames, for use in the target_people field.

    • testing_done (unicode, optional) – The value of the testing_done field.

    • testing_done_text_type (unicode, optional) – The value of the testing_done_text_type field.

    • text_type (unicode, optional) – The value of the text_type field.

    Returns:

    The resource payload and metadata. See the class documentation for details.

    Return type:

    dict

    make_session_object_data(authenticated=True, username='test-user')[source]¶

    Return new session resource data.

    Parameters:
    • authenticated (bool, optional) – Whether this should be an authenticated session.

    • username (unicode, optional) – The current username, if authenticated.

    Returns:

    The resource payload and metadata. See the class documentation for details.

    Return type:

    dict

    make_user_object_data(user_id=1, username='test-user', email='test-user@example.com', first_name='Test', last_name='User', is_active=True, avatar_html=None, avatar_urls={})[source]¶

    Return new user resource data.

    Parameters:
    • user_id (int, optional) – The ID of the user.

    • username (unicode, optional) – The value of the username field.

    • email (unicode, optional) – The value of the email field.

    • first_name (unicode, optional) –

      The value of the first_name field.

      This also affects the fullname field.

    • last_name (unicode, optional) –

      The value of the last_name field.

      This also affects the fullname field.

    • is_active (bool, optional) – The value of the is_active field.

    • avatar_html (unicode, optional) – The value of the avatar_html field.

    • avatar_urls (dict, optional) –

      The value of the avatar_urls field.

      If set, and if it contains a 1x key, this will also affect the avatar_url field.

    Returns:

    The resource payload and metadata. See the class documentation for details.

    Return type:

    dict

    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]
    • LinkExpansionType
      • LinkExpansionType.LIST
      • LinkExpansionType.ITEM
    • ResourcePayloadFactory
      • ResourcePayloadFactory.DEFAULT_CAPABILITIES
      • ResourcePayloadFactory.__init__()
      • ResourcePayloadFactory.expand_link()
      • ResourcePayloadFactory.make_mimetype()
      • ResourcePayloadFactory.make_item_response_payload()
      • ResourcePayloadFactory.make_list_response_payload()
      • ResourcePayloadFactory.make_error_response_payload()
      • ResourcePayloadFactory.make_root_object_data()
      • ResourcePayloadFactory.make_api_info_object_data()
      • ResourcePayloadFactory.make_repository_object_data()
      • ResourcePayloadFactory.make_repository_info_object_data()
      • ResourcePayloadFactory.make_review_request_object_data()
      • ResourcePayloadFactory.make_review_request_draft_object_data()
      • ResourcePayloadFactory.make_session_object_data()
      • ResourcePayloadFactory.make_user_object_data()