本文整理汇总了Python中reviewboard.diffviewer.forms.UploadDiffForm类的典型用法代码示例。如果您正苦于以下问题:Python UploadDiffForm类的具体用法?Python UploadDiffForm怎么用?Python UploadDiffForm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UploadDiffForm类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_diff
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
})
示例2: test_create
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')
示例3: test_creating_diffsets
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')
示例4: test_create_filters_parent_diffs
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
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
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_crate_missing_basedir
def test_crate_missing_basedir(self):
"""Testing UploadDiffForm with a missing basedir field that is
required
"""
repository = self.create_repository(tool_name='Test')
scmtool = repository.get_scmtool()
self.spy_on(repository.get_file_exists,
call_fake=lambda *args, **kwargs: True)
revisions = [
b'93e6b3e8944c48737cb11a1e52b046fa30aea7a9',
b'4839fc480f47ca59cf05a9c39410ea744d1e17a2',
]
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,2 +1,3 @@\n'
b' Foo\n'
b'+Bar\n') % (revisions[0], revisions[1]),
content_type='text/x-patch')
try:
orig_use_abs_paths = scmtool.diffs_use_absolute_paths
scmtool.diffs_use_absolute_paths = True
form = UploadDiffForm(
repository=repository,
files={
'path': diff,
}
)
self.assertFalse(form.is_valid())
finally:
scmtool.diffs_use_absolute_paths = orig_use_abs_paths
self.assertIn('basedir', form.errors)
self.assertIn('This field is required.', form.errors['basedir'])
示例8: test_creating_diffsets
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')
示例9: handle_noargs
#.........这里部分代码省略.........
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")
review_request.shipit_count = 0
review_request.repository = self.repository
# Set the targeted reviewer to superuser or 1st defined.
if j == 0:
review_request.target_people.add(User.objects.get(pk=1))
review_request.save()
# Add the diffs if any to add.
diff_val = self.pickRandomValue(num_of_diffs)
# If adding diffs add history.
if diff_val > 0:
diffset_history = DiffSetHistory.objects.create(
name='testDiffFile' + str(i))
diffset_history.save()
# Won't execute if diff_val is 0, ie: no diffs requested.
for k in range(0, diff_val):
if int(verbosity) > NORMAL:
print "%s:\tDiff #%s" % (i, k)
random_number = random.randint(0, len(files) - 1)
file_to_open = diff_dir + files[random_number]
f = UploadedFile(open(file_to_open, 'r'))
form = UploadDiffForm(review_request.repository, f)
cur_diff = form.create(f, None, diffset_history)
review_request.diffset_history = diffset_history
review_request.save()
review_request.publish(new_user)
f.close()
# Add the reviews if any.
review_val = self.pickRandomValue(num_of_reviews)
for l in range(0, review_val):
if int(verbosity) > NORMAL:
print "%s:%s:\t\tReview #%s:" % (i, j, l)
reviews = Review.objects.create(
review_request=review_request,
user=new_user)
reviews.publish(new_user)
# Add comments if any.
comment_val = self.pickRandomValue(
num_of_diff_comments)
for m in range(0, comment_val):
if int(verbosity) > NORMAL:
print "%s:%s:\t\t\tComments #%s" % (i, j, m)
if m == 0:
file_diff = cur_diff.files.order_by('id')[0]
# Choose random lines to comment.
# Max lines: should be mod'd in future to read
示例10: test_parent_diff_filtering
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)
示例11: UploadDiffForm
# creating a new one.
review_request = ReviewRequest.objects.get(changenum=changenum)
review_request.update_from_changenum(changenum)
if review_request.status == 'D':
# Act like we're creating a brand new review request if the
# old one is discarded.
review_request.status = 'P'
review_request.public = False
review_request.save()
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
示例12: test_create_with_parent_filediff_with_move_and_change
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)