本文整理汇总了Python中reviewboard.diffviewer.forms.UploadDiffForm.create方法的典型用法代码示例。如果您正苦于以下问题:Python UploadDiffForm.create方法的具体用法?Python UploadDiffForm.create怎么用?Python UploadDiffForm.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reviewboard.diffviewer.forms.UploadDiffForm
的用法示例。
在下文中一共展示了UploadDiffForm.create方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_creating_diffsets
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def test_creating_diffsets(self):
"""Test creating a DiffSet from form data"""
diff = (
'diff --git a/README b/README\n'
'index d6613f5..5b50866 100644\n'
'--- README\n'
'+++ README\n'
'@ -1,1 +1,1 @@\n'
'-blah..\n'
'+blah blah\n'
)
diff_file = SimpleUploadedFile('diff', diff,
content_type='text/x-patch')
repository = self.create_repository(tool_name='Test')
self.spy_on(repository.get_file_exists,
call_fake=lambda *args, **kwargs: True)
form = UploadDiffForm(
repository=repository,
data={
'basedir': '/',
'base_commit_id': '1234',
},
files={
'path': diff_file,
})
self.assertTrue(form.is_valid())
diffset = form.create(diff_file)
self.assertEqual(diffset.files.count(), 1)
self.assertEqual(diffset.basedir, '/')
self.assertEqual(diffset.base_commit_id, '1234')
示例2: new_diff
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def new_diff(request, review_request_id):
review_request = get_object_or_404(ReviewRequest, pk=review_request_id)
if not review_request.is_mutable_by(request.user):
return WebAPIResponseError(request, PERMISSION_DENIED)
form_data = request.POST.copy()
form = UploadDiffForm(review_request.repository, form_data, request.FILES)
if not form.is_valid():
return WebAPIResponseFormError(request, form)
try:
diffset = form.create(request.FILES['path'],
request.FILES.get('parent_diff_path'))
# Set the initial revision to be one newer than the most recent
# public revision, so we can reference it in the diff viewer.
#
# TODO: It would be nice to later consolidate this with the logic in
# DiffSet.save.
public_diffsets = review_request.diffset_history.diffsets
if public_diffsets.count() > 0:
diffset.revision = public_diffsets.latest().revision + 1
diffset.save()
else:
diffset.revision = 1
except FileNotFoundError, e:
return WebAPIResponseError(request, REPO_FILE_NOT_FOUND, {
'file': e.path,
'revision': e.revision
})
示例3: test_create
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def test_create(self):
"""Testing UploadDiffForm.create"""
diff_file = SimpleUploadedFile('diff',
self.DEFAULT_GIT_FILEDIFF_DATA_DIFF,
content_type='text/x-patch')
repository = self.create_repository(tool_name='Test')
self.spy_on(repository.get_file_exists,
call_fake=lambda *args, **kwargs: True)
form = UploadDiffForm(
repository=repository,
data={
'basedir': '/',
'base_commit_id': '1234',
},
files={
'path': diff_file,
})
self.assertTrue(form.is_valid())
diffset = form.create()
self.assertEqual(diffset.files.count(), 1)
self.assertEqual(diffset.basedir, '/')
self.assertEqual(diffset.base_commit_id, '1234')
示例4: test_create_filters_parent_diffs
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def test_create_filters_parent_diffs(self):
"""Testing UploadDiffForm.create filters parent diff files"""
saw_file_exists = {}
def get_file_exists(repository, filename, revision, *args, **kwargs):
saw_file_exists[(filename, revision)] = True
return True
parent_diff_1 = (
b'diff --git a/README b/README\n'
b'index d6613f4..5b50865 100644\n'
b'--- README\n'
b'+++ README\n'
b'@@ -2 +2 @@\n'
b'-blah..\n'
b'+blah blah\n'
)
parent_diff_2 = (
b'diff --git a/UNUSED b/UNUSED\n'
b'index 1234567..5b50866 100644\n'
b'--- UNUSED\n'
b'+++ UNUSED\n'
b'@@ -1,1 +1,1 @@\n'
b'-foo\n'
b'+bar\n'
)
parent_diff = parent_diff_1 + parent_diff_2
diff_file = SimpleUploadedFile('diff',
self.DEFAULT_GIT_FILEDIFF_DATA_DIFF,
content_type='text/x-patch')
parent_diff_file = SimpleUploadedFile('parent_diff', parent_diff,
content_type='text/x-patch')
repository = self.create_repository(tool_name='Test')
self.spy_on(repository.get_file_exists, call_fake=get_file_exists)
form = UploadDiffForm(
repository=repository,
data={
'basedir': '/',
},
files={
'path': diff_file,
'parent_diff_path': parent_diff_file,
})
self.assertTrue(form.is_valid())
diffset = form.create()
self.assertEqual(diffset.files.count(), 1)
filediff = diffset.files.get()
self.assertEqual(filediff.diff, self.DEFAULT_GIT_FILEDIFF_DATA_DIFF)
self.assertEqual(filediff.parent_diff, parent_diff_1)
self.assertIn(('/README', 'd6613f4'), saw_file_exists)
self.assertNotIn(('/UNUSED', '1234567'), saw_file_exists)
self.assertEqual(len(saw_file_exists), 1)
示例5: test_mercurial_parent_diff_base_rev
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def test_mercurial_parent_diff_base_rev(self):
"""Testing that the correct base revision is used for Mercurial diffs"""
diff = (
'# Node ID a6fc203fee9091ff9739c9c00cd4a6694e023f48\n'
'# Parent 7c4735ef51a7c665b5654f1a111ae430ce84ebbd\n'
'diff --git a/doc/readme b/doc/readme\n'
'--- a/doc/readme\n'
'+++ b/doc/readme\n'
'@@ -1,3 +1,3 @@\n'
' Hello\n'
'-\n'
'+...\n'
' goodbye\n'
)
parent_diff = (
'# Node ID 7c4735ef51a7c665b5654f1a111ae430ce84ebbd\n'
'# Parent 661e5dd3c4938ecbe8f77e2fdfa905d70485f94c\n'
'diff --git a/doc/newfile b/doc/newfile\n'
'new file mode 100644\n'
'--- /dev/null\n'
'+++ b/doc/newfile\n'
'@@ -0,0 +1,1 @@\n'
'+Lorem ipsum\n'
)
try:
import mercurial
except ImportError:
raise nose.SkipTest("Hg is not installed")
diff_file = SimpleUploadedFile('diff', diff,
content_type='text/x-patch')
parent_diff_file = SimpleUploadedFile('parent_diff', parent_diff,
content_type='text/x-patch')
repository = Repository.objects.create(
name='Test HG',
path='scmtools/testdata/hg_repo.bundle',
tool=Tool.objects.get(name='Mercurial'))
form = UploadDiffForm(
repository=repository,
files={
'path': diff_file,
'parent_diff_path': parent_diff_file,
})
self.assertTrue(form.is_valid())
diffset = form.create(diff_file, parent_diff_file)
self.assertEqual(diffset.files.count(), 1)
filediff = diffset.files.get()
self.assertEqual(filediff.source_revision,
'661e5dd3c4938ecbe8f77e2fdfa905d70485f94c')
示例6: test_create_with_parser_get_orig_commit_id
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def test_create_with_parser_get_orig_commit_id(self):
"""Testing UploadDiffForm.create uses correct base revision returned
by DiffParser.get_orig_commit_id
"""
diff = (
b'# Node ID a6fc203fee9091ff9739c9c00cd4a6694e023f48\n'
b'# Parent 7c4735ef51a7c665b5654f1a111ae430ce84ebbd\n'
b'diff --git a/doc/readme b/doc/readme\n'
b'--- a/doc/readme\n'
b'+++ b/doc/readme\n'
b'@@ -1,3 +1,3 @@\n'
b' Hello\n'
b'-\n'
b'+...\n'
b' goodbye\n'
)
parent_diff = (
b'# Node ID 7c4735ef51a7c665b5654f1a111ae430ce84ebbd\n'
b'# Parent 661e5dd3c4938ecbe8f77e2fdfa905d70485f94c\n'
b'diff --git a/doc/newfile b/doc/newfile\n'
b'new file mode 100644\n'
b'--- /dev/null\n'
b'+++ b/doc/newfile\n'
b'@@ -0,0 +1,1 @@\n'
b'+Lorem ipsum\n'
)
if not has_module('mercurial'):
raise nose.SkipTest("Hg is not installed")
diff_file = SimpleUploadedFile('diff', diff,
content_type='text/x-patch')
parent_diff_file = SimpleUploadedFile('parent_diff', parent_diff,
content_type='text/x-patch')
repository = Repository.objects.create(
name='Test HG',
path='scmtools/testdata/hg_repo',
tool=Tool.objects.get(name='Mercurial'))
form = UploadDiffForm(
repository=repository,
files={
'path': diff_file,
'parent_diff_path': parent_diff_file,
})
self.assertTrue(form.is_valid())
diffset = form.create()
self.assertEqual(diffset.files.count(), 1)
filediff = diffset.files.get()
self.assertEqual(filediff.source_revision,
'661e5dd3c4938ecbe8f77e2fdfa905d70485f94c')
示例7: test_creating_diffsets
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def test_creating_diffsets(self):
"""Test creating a DiffSet from form data"""
diff = (
'Index: README\n'
'==========================================================='
'========\n'
'--- README (revision 123)\n'
'+++ README (new)\n'
'@ -1,1 +1,1 @@\n'
'-blah..\n'
'+blah blah\n'
)
diff_file = SimpleUploadedFile('diff', diff,
content_type='text/x-patch')
repository = Repository.objects.create(
name='Subversion SVN',
path='file://%s' % (os.path.join(os.path.dirname(__file__),
'..', 'scmtools', 'testdata',
'svn_repo')),
tool=Tool.objects.get(name='Subversion'))
self.spy_on(repository.get_file_exists,
call_fake=lambda *args, **kwargs: True)
form = UploadDiffForm(
repository=repository,
data={
'basedir': '/',
'base_commit_id': '1234',
},
files={
'path': diff_file,
})
self.assertTrue(form.is_valid())
diffset = form.create(diff_file)
self.assertEqual(diffset.files.count(), 1)
self.assertEqual(diffset.basedir, '/')
self.assertEqual(diffset.base_commit_id, '1234')
示例8: handle_noargs
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def handle_noargs(self, users=None, review_requests=None, diffs=None,
reviews=None, diff_comments=None, password=None,
verbosity=NORMAL, **options):
num_of_requests = None
num_of_diffs = None
num_of_reviews = None
num_of_diff_comments = None
random.seed()
if review_requests:
num_of_requests = self.parseCommand("review_requests",
review_requests)
# Setup repository.
repo_dir = os.path.abspath(
os.path.join(sys.argv[0], "..", "scmtools", "testdata",
"git_repo"))
# Throw exception on error so transaction reverts.
if not os.path.exists(repo_dir):
raise CommandError("No path to the repository")
self.repository = Repository.objects.create(
name="Test Repository", path=repo_dir,
tool=Tool.objects.get(name="Git"))
if diffs:
num_of_diffs = self.parseCommand("diffs", diffs)
# Create the diff directory locations.
diff_dir_tmp = os.path.abspath(
os.path.join(sys.argv[0], "..", "reviews", "management",
"commands", "diffs"))
# Throw exception on error so transaction reverts.
if not os.path.exists(diff_dir_tmp):
raise CommandError("Diff dir does not exist")
diff_dir = diff_dir_tmp + '/' # Add trailing slash.
# Get a list of the appropriate files.
files = [f for f in os.listdir(diff_dir)
if f.endswith('.diff')]
# Check for any diffs in the files.
if len(files) == 0:
raise CommandError("No diff files in this directory")
if reviews:
num_of_reviews = self.parseCommand("reviews", reviews)
if diff_comments:
num_of_diff_comments = self.parseCommand("diff-comments",
diff_comments)
# Users is required for any other operation.
if not users:
raise CommandError("At least one user must be added")
# Start adding data to the database.
for i in range(1, users + 1):
new_user = User.objects.create(
username=self.randUsername(), # Avoids having to flush db.
first_name=random.choice(NAMES),
last_name=random.choice(NAMES),
email="[email protected]",
is_staff=False,
is_active=True,
is_superuser=False)
if password:
new_user.set_password(password)
new_user.save()
else:
new_user.set_password("test1")
new_user.save()
Profile.objects.create(
user=new_user,
first_time_setup_done=True,
collapsed_diffs=True,
wordwrapped_diffs=True,
syntax_highlighting=True,
show_submitted=True)
# Review Requests.
req_val = self.pickRandomValue(num_of_requests)
if int(verbosity) > NORMAL:
print "For user %s:%s" % (i, new_user.username)
print "============================="
for j in range(0, req_val):
if int(verbosity) > NORMAL:
print "Request #%s:" % j
review_request = ReviewRequest.objects.create(new_user, None)
review_request.public = True
review_request.summary = self.lorem_ipsum("summary")
review_request.description = self.lorem_ipsum("description")
#.........这里部分代码省略.........
示例9: test_parent_diff_filtering
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def test_parent_diff_filtering(self):
"""Testing UploadDiffForm and filtering parent diff files"""
saw_file_exists = {}
def get_file_exists(filename, revision, request):
saw_file_exists[(filename, revision)] = True
return True
diff = (
'Index: README\n'
'==========================================================='
'========\n'
'--- README (revision 124)\n'
'+++ README (new)\n'
'@ -1,1 +1,1 @@\n'
'-blah blah\n'
'+blah!\n'
)
parent_diff_1 = (
'Index: README\n'
'==========================================================='
'========\n'
'--- README (revision 123)\n'
'+++ README (new)\n'
'@ -1,1 +1,1 @@\n'
'-blah..\n'
'+blah blah\n'
)
parent_diff_2 = (
'Index: UNUSED\n'
'==========================================================='
'========\n'
'--- UNUSED (revision 123)\n'
'+++ UNUSED (new)\n'
'@ -1,1 +1,1 @@\n'
'-foo\n'
'+bar\n'
)
parent_diff = parent_diff_1 + parent_diff_2
diff_file = SimpleUploadedFile('diff', diff,
content_type='text/x-patch')
parent_diff_file = SimpleUploadedFile('parent_diff', parent_diff,
content_type='text/x-patch')
# Note that we're using SVN here for the test just because it's
# a bit easier to test with than Git (easier diff parsing logic
# and revision numbers).
repository = Repository.objects.create(
name='Subversion SVN',
path='file://%s' % (os.path.join(os.path.dirname(__file__),
'..', 'scmtools', 'testdata',
'svn_repo')),
tool=Tool.objects.get(name='Subversion'))
repository.get_file_exists = get_file_exists
form = UploadDiffForm(
repository=repository,
data={
'basedir': '/',
},
files={
'path': diff_file,
'parent_diff_path': parent_diff_file,
})
self.assertTrue(form.is_valid())
diffset = form.create(diff_file, parent_diff_file)
self.assertEqual(diffset.files.count(), 1)
filediff = diffset.files.get()
self.assertEqual(filediff.diff, diff)
self.assertEqual(filediff.parent_diff, parent_diff_1)
self.assertTrue(('/README', '123') in saw_file_exists)
self.assertFalse(('/UNUSED', '123') in saw_file_exists)
self.assertEqual(len(saw_file_exists), 1)
示例10: UploadDiffForm
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
diff_form = UploadDiffForm(repository, data={
'basedir': self.cleaned_data['basedir'],
},
files={
'path': diff_file,
'parent_diff_path': parent_diff_file,
})
diff_form.full_clean()
class SavedError(Exception):
"""Empty exception class for when we already saved the error info"""
pass
try:
diff_form.create(diff_file, parent_diff_file,
review_request.diffset_history)
if 'path' in diff_form.errors:
self.errors['diff_path'] = diff_form.errors['path']
raise SavedError
elif 'base_diff_path' in diff_form.errors:
self.errors['base_diff_path'] = diff_form.errors['base_diff_path']
raise SavedError
except SavedError:
review_request.delete()
raise
except EmptyDiffError:
review_request.delete()
self.errors['diff_path'] = forms.util.ErrorList([
'The selected file does not appear to be a diff.'])
raise
except Exception, e:
示例11: test_create_with_parent_filediff_with_move_and_change
# 需要导入模块: from reviewboard.diffviewer.forms import UploadDiffForm [as 别名]
# 或者: from reviewboard.diffviewer.forms.UploadDiffForm import create [as 别名]
def test_create_with_parent_filediff_with_move_and_change(self):
"""Testing UploadDiffForm.create with a parent diff consisting of a
move/rename with content change
"""
revisions = [
b'93e6b3e8944c48737cb11a1e52b046fa30aea7a9',
b'4839fc480f47ca59cf05a9c39410ea744d1e17a2',
b'04861c126cfebd7e7cb93045ab0bff4a7acc4cf2',
]
parent_diff = SimpleUploadedFile(
'parent_diff',
(b'diff --git a/foo b/bar\n'
b'similarity index 55%%\n'
b'rename from foo\n'
b'rename to bar\n'
b'index %s..%s 100644\n'
b'--- a/foo\n'
b'+++ b/bar\n'
b'@@ -1,2 +1,3 @@\n'
b' Foo\n'
b'+Bar\n') % (revisions[0], revisions[1]),
content_type='text/x-patch')
diff = SimpleUploadedFile(
'diff',
(b'diff --git a/bar b/bar\n'
b'index %s..%s 100644\n'
b'--- a/bar\n'
b'+++ b/bar\n'
b'@@ -1,3 +1,4 @@\n'
b' Foo\n'
b' Bar\n'
b'+Baz\n') % (revisions[1], revisions[2]),
content_type='text/x-patch')
repository = self.create_repository(tool_name='Test')
self.spy_on(repository.get_file_exists,
call_fake=lambda *args, **kwargs: True)
# We will only be making one call to get_file and we can fake it out.
self.spy_on(repository.get_file,
call_fake=lambda *args, **kwargs: b'Foo\n')
self.spy_on(patch)
form = UploadDiffForm(
repository=repository,
data={
'basedir': '/',
},
files={
'path': diff,
'parent_diff_path': parent_diff,
})
self.assertTrue(form.is_valid())
diffset = form.create()
self.assertEqual(diffset.files.count(), 1)
f = diffset.files.get()
self.assertEqual(f.source_revision, revisions[0])
self.assertEqual(f.dest_detail, revisions[2])
original_file = get_original_file(f, None, ['ascii'])
self.assertEqual(original_file, b'Foo\nBar\n')
self.assertTrue(patch.spy.called)
patched_file = get_patched_file(original_file, f, None)
self.assertEqual(patched_file, b'Foo\nBar\nBaz\n')
self.assertEqual(len(patch.spy.calls), 2)