Jump to >

This documentation covers the in-development release of Review Board. You can see the latest stable docs or all previous versions.

reviewboard.testing.testcase

class TestCase(methodName='runTest')[source]

Bases: djblets.testing.testcases.FixturesCompilerMixin, djblets.testing.testcases.TestCase

The base class for Review Board test cases.

This class provides a number of convenient functions for creating common objects for testing, such as review requests and comments. They’re populated with default data that can be overridden by the callers.

This also overcomes an annoyance with default Django unit tests where the cache is not cleared across tests, leading to inconsistent results and useless testing.

local_site_name = 'local-site-1'[source]
local_site_id = 1[source]
maxDiff = 1000000[source]
ws_re = re.compile('\\s+')[source]
DEFAULT_FILEDIFF_DATA_DIFF = b'--- README\trevision 123\n+++ README\trevision 123\n@@ -1 +1 @@\n-Hello, world!\n+Hello, everybody!\n'[source]
DEFAULT_GIT_FILEDIFF_DATA_DIFF = b'diff --git a/README b/README\nindex 94bdd3e..197009f 100644\n--- README\n+++ README\n@@ -2 +2 @@\n-blah blah\n+blah!\n'[source]
DEFAULT_GIT_README_DIFF = b'diff --git a/readme b/readme\nindex d6613f5..5b50866 100644\n--- a/readme\n+++ b/readme\n@@ -1 +1,3 @@\nHello there\n+\n+Oh hi!\n'[source]
DEFAULT_GIT_FILEMODE_DIFF = b'diff --git a/testing b/testing\nold mode 100755\nnew mode 100644\nindex e69de29..bcae657\n--- a/testing\n+++ b/testing\n@@ -0,0 +1 @@\n+ADD\ndiff --git a/testing2 b/testing2\nold mode 100644\nnew mode 100755\n'[source]
DEFAULT_GIT_FILE_NOT_FOUND_DIFF = b'diff --git a/missing-file b/missing-file\nindex d6613f0..5b50866 100644\n--- a/missing-file\n+++ b/missing-file\n@@ -1 +1,3 @@\nHello there\n+\n+Oh hi!\n'[source]
DEFAULT_GIT_BINARY_IMAGE_DIFF = b'diff --git a/logo.png b/logo.png\nindex 86b520c..86b520d\nBinary files a/logo.png and b/logo.png differ\n'[source]
classmethod setUpClass()[source]

Set up the test class.

classmethod tearDownClass()[source]

Tear down the test class.

setUp()[source]

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

load_fixtures(fixtures, **kwargs)[source]

Load data from fixtures.

If the legacy test_scmtools fixture is used, the SCMTools registry will re-synchronize with the database, adding any missing tools.

Parameters
  • fixtures (list of str) – The list of fixtures to load.

  • **kwargs (dict) – Additional keyword arguments to pass to the parent method.

shortDescription()[source]

Returns 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.

get_local_site_or_none(name)[source]

Returns a LocalSite matching the name, if provided, or None.

get_local_site(name)[source]
create_local_site(name='local-site-1', **kwargs)[source]

Create a LocalSite for testing.

To maintain compatibility with the behavior of the test_site fixture, this will cache the created LocalSite for use in get_local_site().

New in version 5.0.

Parameters
Returns

The resulting LocalSite.

Return type

reviewboard.site.models.LocalSite

create_http_request(path='/', user=None, method='get', with_local_site=False, local_site=None, resolver_match=None, view=None, **kwargs)[source]

Create an HttpRequest for testing.

This wraps RequestFactory, automatically handing some common fields normally set by middleware, including the user, resolver match, and Local Site.

Parameters
  • path (unicode, optional) – The path for the HTTP request, relative to the server root.

  • user (django.contrib.auth.models.User, optional) – The user authenticated for the request. If not provided, AnonymousUser will be used.

  • method (unicode, optional) – The method on RequestFactory used to create the request.

  • with_local_site (bool, optional) – If set, the default Local Site will be assigned to the request, if local_site is not provided in the call.

  • local_site (reviewboard.site.models.LocalSite, optional) – The Local Site to assign to the request.

  • resolver_match (django.urls.ResolverMatch, optional) – A custom resolver match to set for the request. This may be used by views to determine which URL entry was invoked. If not provided, a blank one pointing to the provided view will be used.

  • view (callable, optional) – The view used for a default ResolverMatch.

  • **kwargs (dict) – Additional keyword arguments to pass to the request factory method.

Returns

The resulting HTTP request.

Return type

django.http.HttpRequest

Raises

ValueError – One or more of the values provided was invalid.

create_user(username='test-user', password='', email='test@example.com', perms=None, **kwargs)[source]

Create a User for testing.

Parameters
  • username (unicode, optional) – The username.

  • password (unicode, optional) – The user’s password.

  • email (unicode, optional) – The user’s e-mail address.

  • perms (list of tuple, optional) – A list of permissions to assign. Each item is a tuple of (app_label, permission_name).

  • **kwargs (dict) – Additional attributes for the user.

Returns

The new User object.

Return type

django.contrib.auth.models.User

create_webapi_token(user, note='Sample note', policy={'access': 'rw'}, with_local_site=False, token_generator_id=None, token_info={'token_type': 'rbp'}, **kwargs)[source]

Create a WebAPIToken for testing.

Changed in version 5.0:

  • Added the token_generator_id and token_info parameters. These are used to specify the type of token to generate.

Parameters
  • user (django.contrib.auth.models.User) – The user who owns the token.

  • note (str, optional) – A note describing the token.

  • policy (dict, optional) – The policy document describing what this token can access in the API.

  • with_local_site (bool, optional) – Whether to create the repository using a Local Site. This will choose one based on local_site_name.

  • token_generator_id (str, optional) –

    The ID of the token generator to use for generating the token. If not set this will use the default token generator that is defined in the token generator registry.

    New in version 5.0.

  • token_info (dict, optional) –

    A dictionary that contains information needed for token generation. If not set this will default to a dictionary that contains a token_type value.

    New in version 5.0.

  • **kwargs (dict) – Keyword arguments to be passed to generate_token().

Returns

The WebAPIToken that was created.

Return type

reviewboard.webapi.models.WebAPIToken

assert_warns(cls=<class 'DeprecationWarning'>, message=None)[source]

A context manager for asserting code generates a warning.

This will check that the code ran in the context will generate a warning with the given class and message. If the call generates multiple warnings, each will be checked.

Parameters
  • cls (type, optional) – The type of warning that should be generated.

  • message (unicode, optional) – The message that should be generated in the warning.

Context

The code to run that’s expected to generate a warning.

create_diff_file_attachment(filediff, from_modified=True, review_request=None, orig_filename='filename.png', caption='My Caption', mimetype='image/png', **kwargs)[source]

Creates a diff-based FileAttachment for testing.

The FileAttachment is tied to the given FileDiff. It’s populated with default data that can be overridden by the caller.

create_diffcommit(repository=None, diffset=None, commit_id='r1', parent_id='r0', diff_contents=b'diff --git a/README b/README\nindex 94bdd3e..197009f 100644\n--- README\n+++ README\n@@ -2 +2 @@\n-blah blah\n+blah!\n', parent_diff_contents=None, author_name='Author', author_email='author@example.com', author_date=None, commit_message='Commit message', committer_name='Committer', committer_email='committer@example.com', committer_date=None, with_diff=True, extra_data=None, **kwargs)[source]

Create a DiffCommit for testing.

By default, this also parses the provided diff data and creates a reviewboard.diffviewer.models.filediff.FileDiff attached to the commit. Callers can turn this off using with_diff=False.

Changed in version 4.0.5: Added the with_diff and extra_data options.

Parameters
  • repository (reviewboard.scmtools.models.Repository, optional) – The repository the commit is associated with.

  • diffset (reviewboard.diffviewer.models.diffset.DiffSet, optional) – The parent diffset.

  • commit_id (unicode, optional) – The commit ID.

  • parent_id (unicode, optional) – The commit ID of the parent commit.

  • diff_contents (bytes, optional) – The contents of the diff.

  • parent_diff_contents (bytes, optional) – The contents of the parent diff, if any.

  • author_name (unicode, optional) – The name of the commit’s author.

  • author_email (unicode, optional) – The e-mail address of the commit’s author.

  • author_date (datetime.datetime, optional) – The date the commit was authored.

  • commit_message (unicode, optional) – The commit message.

  • committer_name (unicode, optional) – The name of the committer, if any.

  • committer_email (unicode, optional) – The e-mail address of the committer, if any.

  • committer_date (datetime.datetime, optional) – The date the commit was committed, if any.

  • with_diff (bool, optional) –

    Whether to create this with a diff.

    If True (the default), this will also create a FileDiff based on diff_contents and parent_diff_contents. The diffs will be parsed using the repository’s tool’s native parser in order to create the commit.

    If False, this will just create the object in the database.

  • extra_data (dict, optional) – Explicit extra_data to attach to the commit.

  • **kwargs (dict) – Keyword arguments to be passed to the DiffCommit initializer.

Returns

The resulting DiffCommit.

Return type

reviewboard.diffviewer.models.diffcommit.DiffCommit

create_diffset(review_request=None, revision=1, repository=None, draft=False, name='diffset', **kwargs)[source]

Creates a DiffSet for testing.

The DiffSet defaults to revision 1. This can be overridden by the caller.

DiffSets generally are tied to a ReviewRequest, but it’s optional.

create_diff_comment(review, filediff, interfilediff=None, text='My comment', issue_opened=False, issue_status=None, first_line=1, num_lines=5, extra_fields=None, reply_to=None, timestamp=None, **kwargs)[source]

Create a Comment for testing.

The comment is tied to the given Review and FileDiff (and, optionally, an interfilediff). It’s populated with default data that can be overridden by the caller.

Parameters
Returns

The resulting comment.

Return type

reviewboard.reviews.models.diff_comment.Comment

create_file_attachment(review_request, attachment_history=None, draft=False, active=True, **kwargs)[source]

Create a FileAttachment for testing.

The attachment is tied to the given ReviewRequest. It’s populated with default data that can be overridden by the caller.

Parameters
Returns

The resulting file attachment.

Return type

reviewboard.attachments.models.FileAttachment

create_user_file_attachment(user, has_file=False, **kwargs)[source]

Create a user FileAttachment for testing.

The reviewboard.attachments.models.FileAttachment is tied to the given django.contrib.auth.models.User. It’s populated with default data that can be overridden by the caller. Notably, by default the FileAttachment will be created without a file or a local_site.

Parameters
Returns

The new file attachment instance.

Return type

reviewboard.attachments.models.FileAttachment

create_file_attachment_comment(review, file_attachment, diff_against_file_attachment=None, text='My comment', issue_opened=False, issue_status=None, extra_fields=None, reply_to=None, timestamp=None, **kwargs)[source]

Create a FileAttachmentComment for testing.

The comment is tied to the given Review and FileAttachment. It’s populated with default data that can be overridden by the caller.

Parameters
Returns

The resulting comment.

Return type

reviewboard.reviews.models.file_attachment_comment.FileAttachmentComment

create_file_attachment_history(review_request=None, display_position=None, **kwargs)[source]

Create a FileAttachmentHistory for testing.

Parameters
  • review_request (reviewboard.reviews.models.review_request.ReviewRequest, optional) – The optional review request to attach the history to.

  • display_position (int, optional) – The display position on the review request. If not provided, a proper position will be computed.

  • **kwargs (dict) – Additional fields to set on the model.

Returns

The new file attachment instance.

Return type

reviewboard.attachments.models.FileAttachmentHistory

create_filediff(diffset, source_file='/test-file', dest_file='/test-file', source_revision='123', dest_detail='124', status='M', diff=b'--- README\trevision 123\n+++ README\trevision 123\n@@ -1 +1 @@\n-Hello, world!\n+Hello, everybody!\n', commit=None, encoding=None, save=True, **kwargs)[source]

Create a FileDiff for testing.

The FileDiff is tied to the given DiffSet. It’s populated with default data that can be overridden by the caller.

Parameters
  • diffset (reviewboard.diffviewer.models.diffset.DiffSet) – The parent diff set that will own this file.

  • source_file (unicode, optional) – The source filename.

  • dest_file (unicode, optional) – The destination filename, which will be the same as source_file unless the file was moved/renamed/copied.

  • source_revision (unicode, optional) – The source revision.

  • dest_detail (unicode, optional) – The destination revision or other detail as found in the parsed diff. This may be a timestamp or some other value.

  • status (unicode, optional) – The status of the file. This is the operation performed as indicated in the diff.

  • diff (bytes, optional) – The diff contents.

  • commit (reviewboard.diffviewer.models.diffcommit.DiffCommit, optional) – The commit to attach the FileDiff to.

  • encoding (unicode, optional) – An explicit encoding to set for the file.

  • save (bool, optional) – Whether to automatically save the resulting object.

  • **kwargs (dict) –

    Additional fields to set on the model.

    New in version 4.0.5.

Returns

The resulting FileDiff.

Return type

reviewboard.diffviewer.models.filediff.FileDiff

create_repository(with_local_site=False, name='Test Repo', tool_name='Git', path=None, local_site=None, extra_data=None, **kwargs)[source]

Create a Repository for testing.

The Repository may optionally be attached to a LocalSite. It’s also populated with default data that can be overridden by the caller.

Parameters
  • with_local_site (bool, optional) –

    Whether to create the repository using a Local Site. This will choose one based on local_site_name.

    If local_site is provided, this argument is ignored.

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

  • tool_name (unicode, optional) – The name of the registered SCM Tool for the repository.

  • path (unicode, optional) – The path for the repository. If not provided, one will be computed.

  • local_site (reviewboard.site.models.LocalSite, optional) – The explicit Local Site to attach.

  • extra_data (dict, optional) – Explicit extra_data to attach to the repository.

  • **kwargs (dict) – Additional fields to set on the repository.

Returns

The new repository.

Return type

reviewboard.scmtools.models.Repository

create_review_request(with_local_site=False, create_repository=False, create_with_history=False, publish=False, id=None, local_id=1001, local_site=None, repository=None, time_added=None, last_updated=None, status='P', submitter='doc', summary='Test Summary', description='Test Description', testing_done='Testing', branch='my-branch', depends_on=None, target_people=None, target_groups=None, **kwargs)[source]

Create a ReviewRequest for testing.

The ReviewRequest may optionally be attached to a LocalSite. It’s also populated with default data that can be overridden by the caller.

Parameters
  • with_local_site (bool, optional) –

    Whether to create this review request on a default local site.

    This is ignored if local_site is provided.

  • create_repository (bool, optional) –

    Whether to create a new repository in the database for this review request.

    This can’t be set if repository is provided.

  • create_with_history (bool, optional) – Whether or not the review request should support multiple commits.

  • publish (bool, optional) – Whether to publish the review request after creation.

  • id (int, optional) – An explicit database ID to set for the review request.

  • local_id (int, optional) – The ID specific to the local site, if one is used.

  • local_site (reviewboard.site.models.LocalSite, optional) –

    The LocalSite to associate the review request with.

    If not provided, the LocalSite with the name specified in local_site_name will be used.

  • repository (reviewboard.scmtools.models.Repository, optional) – An explicit repository to set for the review request.

  • time_added (datetime.datetime, optional) – An explicit creation timestamp to set for the review request.

  • last_updated (datetime.datetime, optional) – An explicit last updated timestamp to set for the review request.

  • status (unicode, optional) – The status of the review request. This must be one of the values listed in STATUSES.

  • submitter (unicode or django.contrib.auth.models.User, optional) – The submitter of the review request. This can be a username (which will be looked up) or an explicit user.

  • summary (unicode, optional) – The summary for the review request.

  • description (unicode, optional) – The description for the review request.

  • testing_done (unicode, optional) – The Testing Done text for the review request.

  • branch (unicode, optional) – The branch for the review request.

  • depends_on (list of reviewboard.reviews.models.review_request.ReviewRequest, optional) – A list of review requests to set as dependencies.

  • target_people (list of django.contrib.auth.models.User, optional) – A list of users to set as target reviewers.

  • target_groups (list of reviewboard.reviews.models.group.Group, optional) – A list of review groups to set as target reviewers.

  • **kwargs (dict) – Additional fields to set on the review request.

Returns

The resulting review request.

Return type

reviewboard.reviews.models.review_request.ReviewRequest

Raises

ValueError – An invalid value was provided during initialization.

create_many_review_requests(count, with_local_site=False, create_repository=False, create_with_history=True, start_id=None, start_local_id=1001, local_site=None, repository=None, public=False, status='P', submitter='doc', summary='Test Summary %s', description='Test Description %s', testing_done='Testing %s', branch='my-branch', depends_on=None, target_people=None, target_groups=None, **kwargs)[source]

Batch-create multiple ReviewRequests for testing.

This will execute the minimum number of SQL statements needed to add the requested amount of review requests to the database.

Due to the nature of this method, not every operation supported by create_review_request() is supported here.

New in version 5.0.

Parameters
  • count (int) – The number of review requests to create.

  • with_local_site (bool, optional) –

    Whether to create the review requests on a default local site.

    This is ignored if local_site is provided.

  • create_repository (bool, optional) –

    Whether to create a new repository in the database, shared by all created review requests.

    This can’t be set if repository is provided.

  • create_with_history (bool, optional) –

    Whether or not the review requests should all support multiple commits.

    Note that unlike create_review_request(), this defaults to True.

  • start_id (int, optional) – An explicit database ID to start with for the new review requests.

  • start_local_id (int, optional) – The LocalSite-specific ID to use as the start for the new review requests.

  • local_site (reviewboard.site.models.LocalSite, optional) –

    The LocalSite to associate the review requests with.

    If not provided, the LocalSite with the name specified in local_site_name will be used, if using with_local_site.

  • repository (reviewboard.scmtools.models.Repository, optional) – An explicit repository to set for the review request.

  • public (bool, optional) – Whether to mark each review request as public.

  • status (str, optional) – The status of the review requests. This must be one of the values listed in STATUSES.

  • submitter (str or django.contrib.auth.models.User, optional) – The submitter of the review requests. This can be a username (which will be looked up) or an explicit user.

  • summary (str, optional) –

    The summary for the review request.

    This must contains a %s, which will be replaced with the 1-based index of the review request.

  • description (str, optional) –

    The description for the review request.

    This must contains a %s, which will be replaced with the 1-based index of the review request.

  • testing_done (str, optional) –

    The Testing Done text for the review request.

    This must contains a %s, which will be replaced with the 1-based index of the review request.

  • branch (str, optional) – The branch for the review request.

  • depends_on (list of reviewboard.reviews.models.review_request.ReviewRequest, optional) – A list of review requests to set as dependencies for each review request.

  • target_people (list of django.contrib.auth.models.User, optional) – A list of users to set as target reviewers for each review request.

  • target_groups (list of reviewboard.reviews.models.group.Group, optional) – A list of review groups to set as target reviewers for each review request.

  • **kwargs (dict) –

    Additional fields to set on each review request.

    Note that not all fields can necessarily be set, and some may have side effects.

Returns

The list of resulting review requests.

Return type

list of reviewboard.reviews.models.review_request.ReviewRequest

Raises

ValueError – An invalid value was provided during initialization.

create_review_request_draft(review_request, **kwargs)[source]

Create a ReviewRequestDraft for testing.

Parameters
  • (reviewboard.reviews.models.review_request. (review_request) – ReviewRequest) The review request for the draft.

  • **kwargs (dict) –

    Additional fields to set on the review request draft.

    New in version 4.0.5.

Returns

The newly-created draft.

Return type

reviewboard.reviews.models.review_request_draft.ReviewRequestDraft

create_visit(review_request, visibility, user='doc', username=None, timestamp=None, **kwargs)[source]

Create a ReviewRequestVisit for testing.

The ReviewRequestVisit is tied to the given ReviewRequest and User. It’s populated with default data that can be overridden by the caller.

The provided user may either be a username or a User object.

create_review(review_request, user='dopey', body_top='Test Body Top', body_bottom='Test Body Bottom', ship_it=False, publish=False, timestamp=None, **kwargs)[source]

Creates a Review for testing.

The Review is tied to the given ReviewRequest. It’s populated with default data that can be overridden by the caller.

The provided user may either be a username or a User object.

If publish is True, Review.publish() will be called.

Parameters
Returns

The resulting review.

Return type

reviewboard.reviews.models.review.Review

create_review_group(name='test-group', with_local_site=False, local_site=None, visible=True, invite_only=False, is_default_group=False, **kwargs)[source]

Creates a review group for testing.

The group may optionally be attached to a LocalSite. It’s also populated with default data that can be overridden by the caller.

create_reply(review, user='grumpy', body_top='Test Body Top', timestamp=None, publish=False, **kwargs)[source]

Create a review reply for testing.

The reply is tied to the given Review. It’s populated with default data that can be overridden by the caller.

To reply to a body_top or body_bottom field, pass either body_top_reply_to= or body_bottom_reply_to= to this method. This will be passed to the review’s constructor.

Parameters
Returns

The resulting review.

Return type

reviewboard.reviews.models.review.Review

create_screenshot(review_request, caption='My caption', draft=False, active=True, **kwargs)[source]

Create a Screenshot for testing.

The screenshot is tied to the given ReviewRequest. It’s populated with default data that can be overridden by the caller.

Parameters
  • review_request (reviewboard.reviews.models.review_request.ReviewRequest) – The review request that ultimately owns the screenshot.

  • caption (unicode, optional) – The caption to use for the screenshot.

  • draft (bool or :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` reviewboard.reviews.models.review_request_draft.ReviewRequestDraft) – A draft to associate the screenshot with. This can also be a boolean, for legacy reasons, which will attempt to look up or create a draft for the review request.

  • active (bool) – Whether this screenshot is considered active (not deleted).

  • **kwargs (dict) – Additional fields to set on the screenshot.

Returns

The resulting screenshot.

Return type

reviewboard.reviews.models.screenshot.Screenshot

create_screenshot_comment(review, screenshot, text='My comment', x=1, y=1, w=5, h=5, issue_opened=False, issue_status=None, extra_fields=None, reply_to=None, timestamp=None, **kwargs)[source]

Create a ScreenshotComment for testing.

The comment is tied to the given Review and Screenshot. It’s It’s populated with default data that can be overridden by the caller.

Parameters
  • review (reviewboard.reviews.models.review.Review) – The review associated with the comment.

  • screenshot (reviewboard.reviews.models.screenshot.Screenshot) – The screenshot associated with the comment.

  • text (unicode) – The text for the comment.

  • x (int, optional) – The X location for the comment on the screenshot.

  • y (int, optional) – The Y location for the comment on the screenshot.

  • w (int, optional) – The width for the comment on the screenshot.

  • h (int, optional) – The height for the comment on the screenshot.

  • issue_opened (bool, optional) – Whether an issue is to be opened for the comment.

  • issue_status (unicode, optional) – The issue status to set, if an issue is opened. Defaults to being an open issue.

  • extra_fields (dict, optional) – Extra data to set on the comment.

  • reply_to (reviewboard.reviews.models.general_comment.GeneralComment, optional) – The comment this comment replies to.

  • timestamp (datetime.datetime, optional) –

    The timestamp for the comment.

    New in version 5.0.

  • **kwargs (dict) – Additional model attributes to set on the comment.

Returns

The resulting comment.

Return type

reviewboard.reviews.models.screenshot_comment.ScreenshotComment

create_file_attachment_base(caption='My Caption', orig_filename='logo.png', mimetype='image/png', uuid=None, has_file=True, file_content=None, user=None, with_local_site=False, local_site_name=None, local_site=None, **kwargs)[source]

Base helper to create a FileAttachment object.

When creating a reviewboard.attachments.models.FileAttachment that will be associated to a review request, a user and local_site should not be specified.

This is not meant to be called directly by tests. Callers should generallly use one of:

Parameters
  • caption (unicode, optional) – The caption for the file attachment.

  • orig_filename (unicode, optional) – The original name of the file to set in the model.

  • mimetype (unicode, optional) – The mimetype of the file attachment.

  • uuid (unicode, optional) – The UUID used to prefix the filename and reference the file attachment.

  • has_file (bool, optional) –

    True if an actual file object should be included in the model.

    This will set the file content based on file_content, if one is provided. If not provided, the Review Board logo is used as the file content.

  • file_content (bytes, optional) – The file content. This is only set if passing has_file=True.

  • user (django.contrib.auth.models.User, optonal) – The user who owns the file attachment.

  • with_local_site (bool, optional) – True if the file attachment should be associated with a local site. If this is set, one of local_site_name or local_site should be provided as well.

  • local_site_name (unicode, optional) – The name of the local site to associate this attachment with.

  • local_site (reviewboard.site.models.LocalSite, optional) – The local site to associate this attachment with.

  • kwargs (dict) – Additional keyword arguments to pass into the FileAttachment constructor.

Returns

The new file attachment instance.

Return type

reviewboard.attachments.models.FileAttachment

create_general_comment(review, text='My comment', issue_opened=False, issue_status=None, extra_fields=None, reply_to=None, timestamp=None, **kwargs)[source]

Create a GeneralComment for testing.

The comment is tied to the given Review. It is populated with default data that can be overridden by the caller.

Parameters
Returns

The resulting comment.

Return type

reviewboard.reviews.models.general_comment.GeneralComment

create_status_update(review_request, user='dopey', service_id='service', summary='Status Update', state='P', review=None, change_description=None, timestamp=None, **kwargs)[source]

Create a status update for testing.

It is populated with default data that can be overridden by the caller.

Parameters
Returns

The new status update.

Return type

reviewboard.reviews.models.StatusUpdate

create_webhook(enabled=False, events='*', url='http://example.com', encoding='application/json', use_custom_content=False, custom_content='', secret='', apply_to='A', repositories=None, with_local_site=False, local_site=None, extra_fields=None, **kwargs)[source]

Create a webhook for testing.

It is populated with default data that can be overridden by the caller.

Parameters
  • enabled (bool) – Whether or not the webhook is enabled when it is created.

  • events (unicode) – A comma-separated list of events that the webhook will trigger on.

  • url (unicode) – The URL that requests will be made against.

  • encoding (unicode) – The encoding of the payload to send.

  • use_custom_content (bool) – Determines if custom content will be sent for the payload (if True) or if it will be auto-generated (if False).

  • custom_content (unicode) – The custom content to send when use_custom_content is True.

  • secret (unicode) – An HMAC secret to sign the payload with.

  • apply_to (unicode) – The types of repositories the webhook will apply to.

  • repositories (list) – A list of repositories that the webhook will be limited to if apply_to is WebHookTarget.APPLY_TO_SELECTED_REPOS.

  • with_local_site (bool) – Determines if this should be created with a local site.

  • local_site (reviewboard.site.models.LocalSite) – An optional local site. If with_local_site is True and this argument is None, the local site will be looked up.

  • extra_fields (dict) – Extra data to be imported into the webhook.

  • **kwargs (dict) –

    Additional keyword arguments to pass into the WebHookTarget constructor.

    New in version 4.0.5.

Returns

A webhook constructed with the given arguments.

Return type

WebHookTarget

create_oauth_application(user, local_site=None, with_local_site=False, redirect_uris='http://example.com', authorization_grant_type='client-credentials', client_type='public', **kwargs)[source]

Create an OAuth application.

Parameters
  • user (django.contrib.auth.models.User) – The user whom is to own the application.

  • local_site (reviewboard.site.models.LocalSite, optional) – The LocalSite for the application to be associated with, if any.

  • redirect_uris (unicode, optional) – A whitespace-separated list of allowable redirect URIs.

  • authorization_grant_type (unicode, optional) – The grant type for the application.

  • client_type (unicode, optional) – The application client type.

  • **kwargs (dict) – Additional keyword arguments to pass to the Application initializer.

Returns

The created application.

Return type

reviewboard.oauth.models.Application

create_oauth_token(application, user, scope='', expires=None, **kwargs)[source]

Create an OAuth2 access token for testing.

Parameters
  • application (reviewboard.oauth.models.Application) – The application the token should be associated with.

  • user (django.contrib.auth.models.User) – The user who should own the token.

  • scope (unicode, optional) – The scopes of the token. This argument defaults to the empty scope.

  • expires (datetime.timedelta, optional) – How far into the future the token expires. If not provided, this argument defaults to one hour.

  • **kwargs (dict) –

    Additional keyword arguments to pass into the AccessToken constructor.

    New in version 4.0.5.

Returns

The created access token.

Return type

oauth2_provider.models.AccessToken

siteconfig_settings(settings, reload_settings=True)[source]

Temporarily sets siteconfig settings for a test.

Parameters
  • settings (dict) – The new siteconfig settings to set.

  • reload_settings (bool, optional) – Whether to reload and recompute all settings, applying them to Django and other objects.

Context

The current site configuration will contain the new settings for this test.

__annotations__ = {}