reviewbot.testing.testcases¶
Common test case for Review Bot unit testing.
New in version 3.0.
Classes
|
A specialization of FileDiffResource that provides custom data. |
|
A specialization of RootResource that stubs out some functions. |
|
An item resource for file attachments. |
|
A list resource for file attachments. |
|
An list resource for repositories. |
|
An item resource for the Review Bot extension. |
|
An item resource for Review Bot reviews. |
|
A list resource for Review Bot reviews. |
|
A list resource for Review Bot reviews. |
|
An item resource for status updates. |
|
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:
- __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()
andget_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.
- __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:
- __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:
- 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:
- __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:
- 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:
- 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:
- 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:
- __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.
- config = {}[source]¶
Custom configuration used for all tests.
This will be applied when setting up the test.
- Type:
dict
- 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.
- 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:
- 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:
- 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
ofdict
) –A simplifed list of chunk data. Each should have the following keys:
change
:One of
equal
,replace
,insert
, ordelete
.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
orreplace
, each entry must be a tuple of original and modified lines.For
insert
ordelete
, 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: