• 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. Review Bot 4.x
    2. Version 4.x
    3. Version 3.0
    4. Version 2.0
    5. Version 1.0
    6. Module and Class Reference
    7. reviewbot.testing.testcases
  • Home
  • Installation
  • Manually Installing Review Bot
  • Review Bot Docker Images
  • Upgrading Review Bot
  • Configuring Review Bot
  • Review Bot Tools
  • Cargo Tool
  • Checkstyle
  • Clang Static Analyzer
  • Cppcheck
  • Cpplint
  • Doc8
  • FBInfer
  • Flake8
  • Go Fmt
  • Go Tool
  • JSHint
  • PMD
  • Pycodestyle
  • Pydocstyle
  • Pyflakes
  • RuboCop
  • Rust Fmt
  • Secret Scanner
  • ShellCheck
  • Module and Class Reference
  • reviewbot.tools.base
  • reviewbot.tools.base.mixins
  • reviewbot.tools.base.registry
  • reviewbot.tools.base.tool
  • reviewbot.testing.testcases
  • reviewbot.testing.utils
  • reviewbot.tools.testing
  • reviewbot.tools.testing.decorators
  • reviewbot.tools.testing.testcases
  • reviewbot.processing.review
  • reviewbot.utils.api
  • reviewbot.utils.filesystem
  • reviewbot.utils.log
  • reviewbot.utils.process
  • reviewbot.utils.text
  • reviewbot.celery
  • reviewbot.config
  • reviewbot.deprecation
  • reviewbot.errors
  • reviewbot.repositories
  • reviewbot.tasks
  • reviewbot.tools.cargotool
  • reviewbot.tools.checkstyle
  • reviewbot.tools.clang
  • reviewbot.tools.cppcheck
  • reviewbot.tools.cpplint
  • reviewbot.tools.doc8
  • reviewbot.tools.fbinfer
  • reviewbot.tools.flake8
  • reviewbot.tools.gofmt
  • reviewbot.tools.gotool
  • reviewbot.tools.jshint
  • reviewbot.tools.pmd
  • reviewbot.tools.pycodestyle
  • reviewbot.tools.pydocstyle
  • reviewbot.tools.pyflakes
  • reviewbot.tools.rbsecretscanner
  • reviewbot.tools.rubocop
  • reviewbot.tools.rustfmt
  • reviewbot.tools.shellcheck
  • General Index
  • Python Module Index
  • Release Notes
  • reviewbot.testing.testcases¶

    Common test case for Review Bot unit testing.

    New in version 3.0.

    Classes

    DummyFileDiffResource(transport, payload, url)

    A specialization of FileDiffResource that provides custom data.

    DummyRootResource(transport, payload, url, ...)

    A specialization of RootResource that stubs out some functions.

    FileAttachmentItemResource(transport, ...[, ...])

    An item resource for file attachments.

    FileAttachmentListResource(transport, ...[, ...])

    A list resource for file attachments.

    RepositoryListResource(**kwargs)

    An list resource for repositories.

    ReviewBotExtensionResource(transport, ...[, ...])

    An item resource for the Review Bot extension.

    ReviewBotReviewResource(transport, payload, url)

    An item resource for Review Bot reviews.

    ReviewBotReviewsResource(transport, payload, url)

    A list resource for Review Bot reviews.

    ReviewBotToolsResource(transport, payload, url)

    A list resource for Review Bot reviews.

    StatusUpdateResource(transport, payload, url)

    An item resource for status updates.

    TestCase([methodName])

    Base class for Review Bot worker unit tests.

    class FileAttachmentItemResource(transport, payload, url, token=None, **kwargs)[source]¶

    Bases: ItemResource

    An item resource for file attachments.

    This exists so we can more easily spy on methods for this resource.

    class FileAttachmentListResource(transport, payload, url, token=None, item_mime_type=None, **kwargs)[source]¶

    Bases: FileAttachmentListResource

    A list resource for file attachments.

    This stubs out some functionality for testing purposes.

    upload_attachment(**kwargs)[source]¶

    Upload a file attachment.

    This will construct a FileAttachmentItemResource() that can be spied on.

    Parameters:

    **kwargs (dict, unused) – Unused keyword arguments.

    Returns:

    The resulting item resource.

    Return type:

    FileAttachmentItemResource

    __annotations__ = {}¶
    class DummyFileDiffResource(transport, payload, url, token=None, **kwargs)[source]¶

    Bases: FileDiffResource

    A specialization of FileDiffResource that provides custom data.

    This takes in special _diff_data`, ``_patch, _original_content, and _patched_content data in the payload, avoiding using HTTP requests to fetch it.

    __getattribute__(name)[source]¶

    Return an attribute from the resource.

    This will conditionally allow access to get_original_file() and get_patched_file() methods based on whether original/patched file content is set.

    Parameters:

    name (str) – The name of the attribute.

    Returns:

    The attribute value.

    Return type:

    object

    Raises:

    AttributeError – The requested attribute does not exist.

    get_patch(**kwargs)[source]¶

    Return the patch for this FileDiff.

    Parameters:

    **kwargs (unused) – Unused keyword arguments.

    Returns:

    The item resource representing the patch file.

    Return type:

    rbtools.api.resource.ItemResource

    get_diff_data(**kwargs)[source]¶

    Return the diff data.

    Parameters:

    **kwargs (unused) – Unused keyword arguments.

    Returns:

    The diff data.

    Return type:

    rbtools.api.resource.ResourceDictField

    __annotations__ = {}¶
    class RepositoryListResource(**kwargs)[source]¶

    Bases: ListResource

    An list resource for repositories.

    This exists so we can more easily spy on methods for this resource.

    New in version 3.0.

    __init__(**kwargs)[source]¶
    __annotations__ = {}¶
    class ReviewBotReviewResource(transport, payload, url, token=None, **kwargs)[source]¶

    Bases: ItemResource

    An item resource for Review Bot reviews.

    This exists so we can more easily spy on methods for this resource.

    __annotations__ = {}¶
    class ReviewBotReviewsResource(transport, payload, url, token=None, item_mime_type=None, **kwargs)[source]¶

    Bases: ListResource

    A list resource for Review Bot reviews.

    This stubs out some functionality for testing purposes.

    create(**kwargs)[source]¶

    Create a new item resource.

    This will construct a ReviewBotReviewResource() that can be spied on.

    Parameters:

    **kwargs (dict, unused) – Unused keyword arguments.

    Returns:

    The resulting item resource.

    Return type:

    ReviewBotReviewResource

    __annotations__ = {}¶
    class ReviewBotToolsResource(transport, payload, url, token=None, item_mime_type=None, **kwargs)[source]¶

    Bases: ListResource

    A list resource for Review Bot reviews.

    This stubs out some functionality for testing purposes.

    create(**kwargs)[source]¶

    Create a new item resource.

    This will actually construct nothing at all. It’s intended to be spied on.

    Parameters:

    **kwargs (dict, unused) – Unused keyword arguments.

    Returns:

    None, always.

    Return type:

    object

    __annotations__ = {}¶
    class ReviewBotExtensionResource(transport, payload, url, token=None, **kwargs)[source]¶

    Bases: ItemResource

    An item resource for the Review Bot extension.

    This stubs out some functionality for testing purposes.

    get_review_bot_reviews(**kwargs)[source]¶

    Return a new Review Bot reviews list resource.

    Parameters:

    **kwargs (dict, unused) – Unused keyword arguments.

    Returns:

    The new list resource.

    Return type:

    ReviewBotReviewResource

    get_tools(**kwargs)[source]¶

    Return a new Review Bot tools list resource.

    Parameters:

    **kwargs (dict, unused) – Unused keyword arguments.

    Returns:

    The new list resource.

    Return type:

    ReviewBotToolsResource

    __annotations__ = {}¶
    class StatusUpdateResource(transport, payload, url, token=None, **kwargs)[source]¶

    Bases: ItemResource

    An item resource for status updates.

    This stubs out some functionality for testing purposes.

    update(**kwargs)[source]¶

    Update the item resource.

    This does nothing. It’s intended to be spied on.

    Parameters:

    **kwargs (dict, unused) – Unused keyword arguments.

    __annotations__ = {}¶
    class DummyRootResource(transport, payload, url, **kwargs)[source]¶

    Bases: RootResource

    A specialization of RootResource that stubs out some functions.

    get_extension(extension_name, **kwargs)[source]¶

    Return an extension resource.

    This only supports the Review Bot extension ID.

    Parameters:
    • extension_name (str) – The extension name requested.

    • **kwargs (dict) – Unused keyword arguments.

    Returns:

    The extension resource instance.

    Return type:

    ReviewBotExtensionResource

    get_files(**kwargs)[source]¶

    Return all filediffs resources.

    This will always be empty.

    Parameters:

    **kwargs (unused) – Unused keyword arguments.

    Returns:

    The empty list.

    Return type:

    list

    get_repositories(**kwargs)[source]¶

    Return all repository resources.

    This will be empty by default. Consumers can spy on this to override results.

    Parameters:

    **kwargs (unused) – Unused keyword arguments.

    Returns:

    The resulting repository list resource.

    Return type:

    RepositoryListResource

    get_status_update(review_request_id, status_update_id, **kwargs)[source]¶

    Return a status update item resource.

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

    • status_update_id (Int) – The ID of the status update.

    • **kwargs (dict, unused) – Additional keyword arguments.

    Returns:

    The resulting status update resource.

    Return type:

    StatusUpdateResource

    get_user_file_attachments(username, **kwargs)[source]¶

    Return a user file attachment list resource.

    Parameters:
    • username (str) – The username for the user who owns the file attachments.

    • **kwargs (dict, unused) – Additional keyword arguments.

    Returns:

    The resulting user file attachment list resource.

    Return type:

    FileAttachmentListResource

    __annotations__ = {}¶
    class TestCase(methodName='runTest')[source]¶

    Bases: TestCase

    Base class for Review Bot worker unit tests.

    This provides additional utility functions to aid in testing.

    New in version 3.0.

    preserve_path_env = False[source]¶

    Whether to preserve the PATH environment variable.

    Type:

    bool

    config = {}[source]¶

    Custom configuration used for all tests.

    This will be applied when setting up the test.

    Type:

    dict

    maxDiff = 10000[source]¶
    classmethod setUpClass()[source]¶

    Hook method for setting up class fixture before running tests in the class.

    classmethod tearDownClass()[source]¶

    Hook method for deconstructing the class fixture after running all tests in the class.

    setUp()[source]¶

    Hook method for setting up the test fixture before exercising it.

    shortDescription()[source]¶

    Return the description of the current test.

    This changes the default behavior to replace all newlines with spaces, allowing a test description to span lines. It should still be kept short, though.

    Returns:

    The test description, without truncating lines.

    Return type:

    str

    override_config(new_config)[source]¶

    Override the Review Bot configuration temporarily.

    This context manager allows a caller to set brand-new configuration for the duration of the context.

    Parameters:

    new_config (dict) – The new configuration. This will be merged into a copy of the default configuration.

    Context:

    Code will be executed with the new configuration.

    create_review(review_request_id=123, diff_revision=1, settings={})[source]¶

    Create a Review for testing.

    Parameters:
    • review_request_id (int, optional) – The ID of the review request being reviewed.

    • diff_revision (int, optional) – The revision of the diffset being reviewed.

    • settings (dict, optional) – Custom settings to provide for the review.

    Returns:

    The resulting Review object.

    Return type:

    reviewbot.processing.review.Review

    create_review_file(review, filediff_id=42, source_file='/test.txt', dest_file='/test.txt', source_revision='abc123', status='modified', patch=None, original_content=<object object>, patched_content=<object object>, patched_file_path=None, diff_data=None, extra_data={})[source]¶

    Create a File representing a review on a filediff for testing.

    Parameters:
    • (reviewbot.processing.review.Review (review) – The review that this File will be bound to.

    • filediff_id (int, optional) – The ID of the FileDiff being reviewed.

    • source_file (str, optional) – The filename of the original version of the file.

    • dest_file (str, optional) – The filename of the modified version of the file.

    • source_revision (str, optional) – The source revision for the file.

    • status (str, optional) – The status value set for the FileDiff.

    • patch (bytes, optional) – The patch content. If not provided, one will be generated.

    • original_content (bytes, optional) – The original version of the file. If not provided, one will be generated.

    • patched_content (bytes, optional) – The patched version of the file. If not provided, one will be generated.

    • patched_file_path (str, optional) – The local path to the patched file content.

    • diff_data (dict, optional) – The diff data, used to match up line numbers to diff virtual line numbers. If not provided, one will be generated, but most test suites will need to generate this themselves.

    • extra_data (dict, optional) – Extra data to attach in the FileDiff.

    Returns:

    The resulting File object.

    Return type:

    reviewbot.processing.review.File

    create_diff_data(chunks)[source]¶

    Create new diff data based on a simplified chunk format.

    This will generate the full diff data format based on the chunks. The caller needs to provide a list of chunks containing relevant content (any gaps will be automatically filled in).

    Parameters:

    chunks (list of dict) –

    A simplifed list of chunk data. Each should have the following keys:

    change:

    One of equal, replace, insert, or delete.

    old_linenum:

    The line number of the old/original side of the chunk.

    new_linenum:

    The line number of the new/modified side of the chunk.

    lines:

    A list of lines.

    For equal or replace, each entry must be a tuple of original and modified lines.

    For insert or delete, each entry must be a single string for the corresponding side.

    Returns:

    The resulting diff data.

    Return type:

    dict

    create_filediff_resource(filediff_id=42, review_request_id=123, source_file='/test.txt', source_revision='abc123', dest_file='/test.txt', status='modified', binary=False, patch=None, original_content=<object object>, patched_content=<object object>, diff_data=None, extra_data={})[source]¶

    Create a FileDiffResource for testing.

    Parameters:
    • filediff_id (int, optional) – The ID of the FileDiff being reviewed.

    • review_request_id (int, optional) – The ID of the review request that owns the FileDiff.

    • source_file (str, optional) – The filename of the original version of the file.

    • source_revision (str, optional) – The source revision for the file.

    • dest_file (str, optional) – The filename of the modified version of the file.

    • status (str, optional) – The status value set for the FileDiff.

    • binary (bool, optional) – Whether this is a binary file.

    • patch (bytes, optional) – The patch content. If not provided, one will be generated.

    • original_content (bytes, optional) – The original version of the file. If not provided, one will be generated.

    • patched_content (bytes, optional) – The patched version of the file. If not provided, one will be generated.

    • diff_data (dict, optional) – The diff data, used to match up line numbers to diff virtual line numbers. If not provided, one will be generated, but most test suites will need to generate this themselves.

    • extra_data (dict, optional) – Extra data to attach in the FileDiff.

    Returns:

    The resulting File object.

    Return type:

    reviewbot.processing.review.File

    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]
    • FileAttachmentItemResource
    • FileAttachmentListResource
      • FileAttachmentListResource.upload_attachment()
      • FileAttachmentListResource.__annotations__
    • DummyFileDiffResource
      • DummyFileDiffResource.__getattribute__()
      • DummyFileDiffResource.get_patch()
      • DummyFileDiffResource.get_diff_data()
      • DummyFileDiffResource.__annotations__
    • RepositoryListResource
      • RepositoryListResource.__init__()
      • RepositoryListResource.__annotations__
    • ReviewBotReviewResource
      • ReviewBotReviewResource.__annotations__
    • ReviewBotReviewsResource
      • ReviewBotReviewsResource.create()
      • ReviewBotReviewsResource.__annotations__
    • ReviewBotToolsResource
      • ReviewBotToolsResource.create()
      • ReviewBotToolsResource.__annotations__
    • ReviewBotExtensionResource
      • ReviewBotExtensionResource.get_review_bot_reviews()
      • ReviewBotExtensionResource.get_tools()
      • ReviewBotExtensionResource.__annotations__
    • StatusUpdateResource
      • StatusUpdateResource.update()
      • StatusUpdateResource.__annotations__
    • DummyRootResource
      • DummyRootResource.get_extension()
      • DummyRootResource.get_files()
      • DummyRootResource.get_repositories()
      • DummyRootResource.get_status_update()
      • DummyRootResource.get_user_file_attachments()
      • DummyRootResource.__annotations__
    • TestCase
      • TestCase.preserve_path_env
      • TestCase.config
      • TestCase.maxDiff
      • TestCase.setUpClass()
      • TestCase.tearDownClass()
      • TestCase.setUp()
      • TestCase.shortDescription()
      • TestCase.override_config()
      • TestCase.create_review()
      • TestCase.create_review_file()
      • TestCase.create_diff_data()
      • TestCase.create_filediff_resource()