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.
-
DEFAULT_FILEDIFF_DATA
= ‘— README\trevision 123\n+++ README\trevision 123\n@@ -1 +1 @@\n-Hello, world!\n+Hello, everybody!\n’[source]¶
-
DEFAULT_GIT_FILEDIFF_DATA
= ‘diff –git a/README b/README\nindex 94bdd3e..197009f 100644\n— README\n+++ README\n@@ -2 +2 @@\n-blah blah\n+blah!\n’[source]¶
-
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.
-
create_webapi_token
(user, note=u’Sample note’, policy={u’access’: u’rw’}, with_local_site=False, **kwargs)[source]¶ Creates a WebAPIToken for testing.
-
assert_warns
(*args, **kwds)[source]¶ A context manager for asserting code generates a warning.
This method only supports code which generates a single warning. Tests which make use of code generating multiple warnings will need to manually catch their warnings.
-
create_diff_file_attachment
(filediff, from_modified=True, review_request=None, orig_filename=u’filename.png’, caption=u’My Caption’, mimetype=u’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_diffset
(review_request=None, revision=1, repository=None, draft=False, name=u’diffset’)[source]¶ Creates a DiffSet for testing.
The DiffSet defaults to revision 1. This can be overriden by the caller.
DiffSets generally are tied to a ReviewRequest, but it’s optional.
-
create_diff_comment
(review, filediff, interfilediff=None, text=u’My comment’, issue_opened=False, issue_status=None, first_line=1, num_lines=5, extra_fields=None, reply_to=None, **kwargs)[source]¶ Creates 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.
-
create_file_attachment
(review_request, orig_filename=u’filename.png’, caption=u’My Caption’, draft=False, active=True, **kwargs)[source]¶ Creates a FileAttachment for testing.
The FileAttachment is tied to the given ReviewRequest. It’s populated with default data that can be overridden by the caller.
-
create_file_attachment_comment
(review, file_attachment, diff_against_file_attachment=None, text=u’My comment’, issue_opened=False, extra_fields=None, reply_to=None)[source]¶ Creates 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.
-
create_filediff
(diffset, source_file=u’/test-file’, dest_file=u’/test-file’, source_revision=u‘123’, dest_detail=u‘124’, status=u’M’, diff=’— README\trevision 123\n+++ README\trevision 123\n@@ -1 +1 @@\n-Hello, world!\n+Hello, everybody!\n’, save=True)[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) – 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.
- save (bool, optional) – Whether to automatically save the resulting object.
Returns: The resulting FileDiff.
Return type:
-
create_repository
(with_local_site=False, name=u’Test Repo’, tool_name=u’Git’, path=None, local_site=None, **kwargs)[source]¶ Creates 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.
This accepts a tool_name of “Git”, “Mercurial” or “Subversion”. The correct bundled repository path will be used for the given tool_name.
-
create_review_request
(with_local_site=False, local_site=None, summary=u’Test Summary’, description=u’Test Description’, testing_done=u’Testing’, submitter=u’doc’, local_id=1001, bugs_closed=u”, status=u’P’, public=False, publish=False, commit_id=None, changenum=None, repository=None, id=None, create_repository=False)[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.
If create_repository is True, a Repository will be created automatically. If set, a custom repository cannot be provided.
The provided submitter may either be a username or a User object.
If publish is True, ReviewRequest.publish() will be called.
-
create_visit
(review_request, visibility, user=u’doc’, username=None, timestamp=None)[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=u’dopey’, username=None, body_top=u’Test Body Top’, body_bottom=u’Test Body Bottom’, ship_it=False, publish=False)[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.
-
create_review_group
(name=u’test-group’, with_local_site=False, local_site=None, visible=True, invite_only=False, is_default_group=False)[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=u’grumpy’, username=None, body_top=u’Test Body Top’, timestamp=None, publish=False)[source]¶ Creates 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.
-
create_screenshot
(review_request, caption=u’My caption’, draft=False, active=True)[source]¶ Creates 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.
-
create_screenshot_comment
(review, screenshot, text=u’My comment’, x=1, y=1, w=5, h=5, issue_opened=False, extra_fields=None, reply_to=None, **kwargs)[source]¶ Creates 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.
-
create_webhook
(enabled=False, events=u’*’, url=u’http://example.com’, encoding=u’application/json’, use_custom_content=False, custom_content=u”, secret=u”, apply_to=u’A’, repositories=None, with_local_site=False, local_site=None, extra_fields=None)[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 (ifFalse
). - custom_content (unicode) – The custom content to send when
use_custom_content
isTrue
. - 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
isWebHookTarget.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
isTrue
and this argument isNone
, the local site will be looked up. - extra_fields (dict) – Extra data to be imported into the webhook.
Returns: A webhook constructed with the given arguments.
Return type:
-