tests: fixed some tests for files pages.

This commit is contained in:
Marcin Kuzminski 2019-07-01 13:15:37 +02:00
parent 45a4a60cb7
commit 073b2bc899
8 changed files with 70 additions and 75 deletions

View file

@ -57,8 +57,7 @@ class TestChangelogController(TestController):
first_idx = -1
last_idx = -DEFAULT_CHANGELOG_SIZE
self.assert_commit_range_on_page(
response, first_idx, last_idx, backend)
self.assert_commit_range_on_page(response, first_idx, last_idx, backend)
def test_changelog(self, backend):
self.log_user()
@ -157,7 +156,8 @@ class TestChangelogController(TestController):
self, response, first_idx, last_idx, backend):
input_template = (
"""<input class="commit-range" """
"""data-commit-id="%(raw_id)s" data-commit-idx="%(idx)s" id="%(raw_id)s" """
"""data-commit-id="%(raw_id)s" data-commit-idx="%(idx)s" """
"""data-short-id="%(short_id)s" id="%(raw_id)s" """
"""name="%(raw_id)s" type="checkbox" value="1" />"""
)
@ -167,7 +167,8 @@ class TestChangelogController(TestController):
first_commit_on_page = repo.get_commit(commit_idx=first_idx)
response.mustcontain(
input_template % {'raw_id': first_commit_on_page.raw_id,
'idx': first_commit_on_page.idx})
'idx': first_commit_on_page.idx,
'short_id': first_commit_on_page.short_id})
response.mustcontain(commit_span_template % (
first_commit_on_page.idx, first_commit_on_page.short_id)
@ -176,7 +177,8 @@ class TestChangelogController(TestController):
last_commit_on_page = repo.get_commit(commit_idx=last_idx)
response.mustcontain(
input_template % {'raw_id': last_commit_on_page.raw_id,
'idx': last_commit_on_page.idx})
'idx': last_commit_on_page.idx,
'short_id': last_commit_on_page.short_id})
response.mustcontain(commit_span_template % (
last_commit_on_page.idx, last_commit_on_page.short_id)
)

View file

@ -243,7 +243,7 @@ class TestFilesViews(object):
repo_name=backend.repo_name,
commit_id=commit.raw_id, f_path='vcs/nodes.py'))
msgbox = """<div class="commit right-content">%s</div>"""
msgbox = """<div class="commit">%s</div>"""
response.mustcontain(msgbox % (commit.message, ))
assert_response = response.assert_response()
@ -313,6 +313,7 @@ class TestFilesViews(object):
expected_data = json.loads(
fixture.load_resource('svn_node_history_branches.json'))
assert expected_data == response.json
def test_file_source_history_with_annotation(self, backend, xhr_header):
@ -761,7 +762,7 @@ class TestModifyFilesWithWebInterface(object):
@pytest.mark.xfail_backends("svn", reason="Depends on online editing")
def test_add_file_into_repo_missing_content(self, backend, csrf_token):
repo = backend.create_repo()
backend.create_repo()
filename = 'init.py'
response = self.app.post(
route_path('repo_files_create_file',
@ -770,26 +771,25 @@ class TestModifyFilesWithWebInterface(object):
params={
'content': "",
'filename': filename,
'location': "",
'csrf_token': csrf_token,
},
status=302)
assert_session_flash(response,
'Successfully committed new file `{}`'.format(
os.path.join(filename)))
expected_msg = 'Successfully committed new file `{}`'.format(os.path.join(filename))
assert_session_flash(response, expected_msg)
def test_add_file_into_repo_missing_filename(self, backend, csrf_token):
commit_id = backend.repo.get_commit().raw_id
response = self.app.post(
route_path('repo_files_create_file',
repo_name=backend.repo_name,
commit_id='tip', f_path='/'),
commit_id=commit_id, f_path='/'),
params={
'content': "foo",
'csrf_token': csrf_token,
},
status=302)
assert_session_flash(response, 'No filename')
assert_session_flash(response, 'No filename specified')
def test_add_file_into_repo_errors_and_no_commits(
self, backend, csrf_token):
@ -806,7 +806,7 @@ class TestModifyFilesWithWebInterface(object):
},
status=302)
assert_session_flash(response, 'No filename')
assert_session_flash(response, 'No filename specified')
# Not allowed, redirect to the summary
redirected = response.follow()
@ -817,52 +817,51 @@ class TestModifyFilesWithWebInterface(object):
assert redirected.request.path == summary_url
@pytest.mark.parametrize("location, filename", [
('/abs', 'foo'),
('../rel', 'foo'),
('file/../foo', 'foo'),
@pytest.mark.parametrize("filename, clean_filename", [
('/abs/foo', 'abs/foo'),
('../rel/foo', 'rel/foo'),
('file/../foo/foo', 'file/foo/foo'),
])
def test_add_file_into_repo_bad_filenames(
self, location, filename, backend, csrf_token):
response = self.app.post(
route_path('repo_files_create_file',
repo_name=backend.repo_name,
commit_id='tip', f_path='/'),
params={
'content': "foo",
'filename': filename,
'location': location,
'csrf_token': csrf_token,
},
status=302)
assert_session_flash(
response,
'The location specified must be a relative path and must not '
'contain .. in the path')
@pytest.mark.parametrize("cnt, location, filename", [
(1, '', 'foo.txt'),
(2, 'dir', 'foo.rst'),
(3, 'rel/dir', 'foo.bar'),
])
def test_add_file_into_repo(self, cnt, location, filename, backend,
csrf_token):
def test_add_file_into_repo_bad_filenames(self, filename, clean_filename, backend, csrf_token):
repo = backend.create_repo()
commit_id = repo.get_commit().raw_id
response = self.app.post(
route_path('repo_files_create_file',
repo_name=repo.repo_name,
commit_id='tip', f_path='/'),
commit_id=commit_id, f_path='/'),
params={
'content': "foo",
'filename': filename,
'location': location,
'csrf_token': csrf_token,
},
status=302)
assert_session_flash(response,
'Successfully committed new file `{}`'.format(
os.path.join(location, filename)))
expected_msg = 'Successfully committed new file `{}`'.format(clean_filename)
assert_session_flash(response, expected_msg)
@pytest.mark.parametrize("cnt, filename, content", [
(1, 'foo.txt', "Content"),
(2, 'dir/foo.rst', "Content"),
(3, 'dir/foo-second.rst', "Content"),
(4, 'rel/dir/foo.bar', "Content"),
])
def test_add_file_into_empty_repo(self, cnt, filename, content, backend, csrf_token):
repo = backend.create_repo()
commit_id = repo.get_commit().raw_id
response = self.app.post(
route_path('repo_files_create_file',
repo_name=repo.repo_name,
commit_id=commit_id, f_path='/'),
params={
'content': content,
'filename': filename,
'csrf_token': csrf_token,
},
status=302)
expected_msg = 'Successfully committed new file `{}`'.format(filename)
assert_session_flash(response, expected_msg)
def test_edit_file_view(self, backend):
response = self.app.get(
@ -884,8 +883,7 @@ class TestModifyFilesWithWebInterface(object):
f_path='vcs/nodes.py'),
status=302)
assert_session_flash(
response,
'You can only edit files with commit being a valid branch')
response, 'Cannot modify file. Given commit `tip` is not head of a branch.')
def test_edit_file_view_commit_changes(self, backend, csrf_token):
repo = backend.create_repo()
@ -953,8 +951,7 @@ class TestModifyFilesWithWebInterface(object):
f_path='vcs/nodes.py'),
status=302)
assert_session_flash(
response,
'You can only delete files with commit being a valid branch')
response, 'Cannot modify file. Given commit `tip` is not head of a branch.')
def test_delete_file_view_commit_changes(self, backend, csrf_token):
repo = backend.create_repo()
@ -992,7 +989,7 @@ class TestFilesViewOtherCases(object):
repo_file_add_url = route_path(
'repo_files_add_file',
repo_name=repo.repo_name,
commit_id=0, f_path='') + '#edit'
commit_id=0, f_path='')
assert_session_flash(
response,
@ -1009,7 +1006,7 @@ class TestFilesViewOtherCases(object):
repo_file_add_url = route_path(
'repo_files_add_file',
repo_name=repo.repo_name,
commit_id=0, f_path='') + '#edit'
commit_id=0, f_path='')
response = self.app.get(
route_path('repo_files',

View file

@ -205,8 +205,7 @@ class RepoFilesView(RepoAppView):
h.flash(_('No such commit exists for this repository'), category='error')
raise HTTPNotFound()
except RepositoryError as e:
log.warning('Repository error while fetching '
'filenode `%s`. Err:%s', path, e)
log.warning('Repository error while fetching filenode `%s`. Err:%s', path, e)
h.flash(safe_str(h.escape(e)), category='error')
raise HTTPNotFound()
@ -215,13 +214,7 @@ class RepoFilesView(RepoAppView):
def _is_valid_head(self, commit_id, repo):
branch_name = sha_commit_id = ''
is_head = False
log.debug('Checking if commit_id %s is a head.', commit_id)
if h.is_svn(repo) and not repo.is_empty():
# Note: Subversion only has one head.
if commit_id == repo.get_commit(commit_idx=-1).raw_id:
is_head = True
return branch_name, sha_commit_id, is_head
log.debug('Checking if commit_id `%s` is a head for %s.', commit_id, repo)
for _branch_name, branch_commit_id in repo.branches.items():
# simple case we pass in branch name, it's a HEAD
@ -237,6 +230,12 @@ class RepoFilesView(RepoAppView):
sha_commit_id = branch_commit_id
break
if h.is_svn(repo) and not repo.is_empty():
# Note: Subversion only has one head.
if commit_id == repo.get_commit(commit_idx=-1).raw_id:
is_head = True
return branch_name, sha_commit_id, is_head
# checked branches, means we only need to try to get the branch/commit_sha
if not repo.is_empty():
commit = repo.get_commit(commit_id=commit_id)
@ -1286,8 +1285,7 @@ class RepoFilesView(RepoAppView):
if self.rhodecode_vcs_repo.is_empty():
# for empty repository we cannot check for current branch, we rely on
# c.commit.branch instead
_branch_name = c.commit.branch
is_head = True
_branch_name, _sha_commit_id, is_head = c.commit.branch, '', True
else:
_branch_name, _sha_commit_id, is_head = \
self._is_valid_head(commit_id, self.rhodecode_vcs_repo)
@ -1328,8 +1326,7 @@ class RepoFilesView(RepoAppView):
if self.rhodecode_vcs_repo.is_empty():
# for empty repository we cannot check for current branch, we rely on
# c.commit.branch instead
_branch_name = c.commit.branch
is_head = True
_branch_name, _sha_commit_id, is_head = c.commit.branch, '', True
else:
_branch_name, _sha_commit_id, is_head = \
self._is_valid_head(commit_id, self.rhodecode_vcs_repo)
@ -1425,8 +1422,7 @@ class RepoFilesView(RepoAppView):
if self.rhodecode_vcs_repo.is_empty():
# for empty repository we cannot check for current branch, we rely on
# c.commit.branch instead
_branch_name = c.commit.branch
is_head = True
_branch_name, _sha_commit_id, is_head = c.commit.branch, '', True
else:
_branch_name, _sha_commit_id, is_head = \
self._is_valid_head(commit_id, self.rhodecode_vcs_repo)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
{"more": false, "results": [{"text": "Changesets", "children": [{"text": "r15:16", "id": "16"}, {"text": "r12:13", "id": "13"}, {"text": "r7:8", "id": "8"}, {"text": "r3:4", "id": "4"}, {"text": "r2:3", "id": "3"}]}, {"text": "Branches", "children": [{"text": "branches/add-docs", "id": "branches/add-docs/example.py@26"}, {"text": "branches/argparse", "id": "branches/argparse/example.py@26"}, {"text": "trunk", "id": "trunk/example.py@26"}]}, {"text": "Tags", "children": [{"text": "tags/v0.1", "id": "tags/v0.1/example.py@26"}, {"text": "tags/v0.2", "id": "tags/v0.2/example.py@26"}, {"text": "tags/v0.3", "id": "tags/v0.3/example.py@26"}, {"text": "tags/v0.5", "id": "tags/v0.5/example.py@26"}]}]}
{"results": [{"text": "Changesets", "children": [{"text": "r15:16", "type": "sha", "id": "16"}, {"text": "r12:13", "type": "sha", "id": "13"}, {"text": "r7:8", "type": "sha", "id": "8"}, {"text": "r3:4", "type": "sha", "id": "4"}, {"text": "r2:3", "type": "sha", "id": "3"}]}, {"text": "Branches", "children": [{"text": "branches/add-docs", "type": "branch", "id": "branches/add-docs/example.py@26"}, {"text": "branches/argparse", "type": "branch", "id": "branches/argparse/example.py@26"}, {"text": "trunk", "type": "branch", "id": "trunk/example.py@26"}]}, {"text": "Tags", "children": [{"text": "tags/v0.1", "type": "tag", "id": "tags/v0.1/example.py@26"}, {"text": "tags/v0.2", "type": "tag", "id": "tags/v0.2/example.py@26"}, {"text": "tags/v0.3", "type": "tag", "id": "tags/v0.3/example.py@26"}, {"text": "tags/v0.5", "type": "tag", "id": "tags/v0.5/example.py@26"}]}], "more": false}

View file

@ -1 +1 @@
{"results": [{"text": "Changesets", "children": [{"text": "r382:383", "id": "383"}, {"text": "r323:324", "id": "324"}, {"text": "r322:323", "id": "323"}, {"text": "r299:300", "id": "300"}, {"text": "r277:278", "id": "278"}, {"text": "r273:274", "id": "274"}, {"text": "r270:271", "id": "271"}, {"text": "r269:270", "id": "270"}, {"text": "r263:264", "id": "264"}, {"text": "r261:262", "id": "262"}, {"text": "r251:252", "id": "252"}, {"text": "r208:209", "id": "209"}, {"text": "r202:203", "id": "203"}, {"text": "r173:174", "id": "174"}, {"text": "r172:173", "id": "173"}, {"text": "r171:172", "id": "172"}, {"text": "r145:146", "id": "146"}, {"text": "r144:145", "id": "145"}, {"text": "r140:141", "id": "141"}, {"text": "r134:135", "id": "135"}, {"text": "r107:108", "id": "108"}, {"text": "r106:107", "id": "107"}, {"text": "r100:101", "id": "101"}, {"text": "r94:95", "id": "95"}, {"text": "r85:86", "id": "86"}, {"text": "r73:74", "id": "74"}, {"text": "r72:73", "id": "73"}, {"text": "r71:72", "id": "72"}, {"text": "r69:70", "id": "70"}, {"text": "r67:68", "id": "68"}, {"text": "r63:64", "id": "64"}, {"text": "r62:63", "id": "63"}, {"text": "r61:62", "id": "62"}, {"text": "r50:51", "id": "51"}, {"text": "r49:50", "id": "50"}, {"text": "r48:49", "id": "49"}, {"text": "r47:48", "id": "48"}, {"text": "r46:47", "id": "47"}, {"text": "r45:46", "id": "46"}, {"text": "r41:42", "id": "42"}, {"text": "r39:40", "id": "40"}, {"text": "r37:38", "id": "38"}, {"text": "r25:26", "id": "26"}, {"text": "r23:24", "id": "24"}, {"text": "r8:9", "id": "9"}, {"text": "r7:8", "id": "8"}]}, {"text": "Branches", "children": []}, {"text": "Tags", "children": []}], "more": false}
{"results": [{"text": "Changesets", "children": [{"text": "r382:383", "type": "sha", "id": "383"}, {"text": "r323:324", "type": "sha", "id": "324"}, {"text": "r322:323", "type": "sha", "id": "323"}, {"text": "r299:300", "type": "sha", "id": "300"}, {"text": "r277:278", "type": "sha", "id": "278"}, {"text": "r273:274", "type": "sha", "id": "274"}, {"text": "r270:271", "type": "sha", "id": "271"}, {"text": "r269:270", "type": "sha", "id": "270"}, {"text": "r263:264", "type": "sha", "id": "264"}, {"text": "r261:262", "type": "sha", "id": "262"}, {"text": "r251:252", "type": "sha", "id": "252"}, {"text": "r208:209", "type": "sha", "id": "209"}, {"text": "r202:203", "type": "sha", "id": "203"}, {"text": "r173:174", "type": "sha", "id": "174"}, {"text": "r172:173", "type": "sha", "id": "173"}, {"text": "r171:172", "type": "sha", "id": "172"}, {"text": "r145:146", "type": "sha", "id": "146"}, {"text": "r144:145", "type": "sha", "id": "145"}, {"text": "r140:141", "type": "sha", "id": "141"}, {"text": "r134:135", "type": "sha", "id": "135"}, {"text": "r107:108", "type": "sha", "id": "108"}, {"text": "r106:107", "type": "sha", "id": "107"}, {"text": "r100:101", "type": "sha", "id": "101"}, {"text": "r94:95", "type": "sha", "id": "95"}, {"text": "r85:86", "type": "sha", "id": "86"}, {"text": "r73:74", "type": "sha", "id": "74"}, {"text": "r72:73", "type": "sha", "id": "73"}, {"text": "r71:72", "type": "sha", "id": "72"}, {"text": "r69:70", "type": "sha", "id": "70"}, {"text": "r67:68", "type": "sha", "id": "68"}, {"text": "r63:64", "type": "sha", "id": "64"}, {"text": "r62:63", "type": "sha", "id": "63"}, {"text": "r61:62", "type": "sha", "id": "62"}, {"text": "r50:51", "type": "sha", "id": "51"}, {"text": "r49:50", "type": "sha", "id": "50"}, {"text": "r48:49", "type": "sha", "id": "49"}, {"text": "r47:48", "type": "sha", "id": "48"}, {"text": "r46:47", "type": "sha", "id": "47"}, {"text": "r45:46", "type": "sha", "id": "46"}, {"text": "r41:42", "type": "sha", "id": "42"}, {"text": "r39:40", "type": "sha", "id": "40"}, {"text": "r37:38", "type": "sha", "id": "38"}, {"text": "r25:26", "type": "sha", "id": "26"}, {"text": "r23:24", "type": "sha", "id": "24"}, {"text": "r8:9", "type": "sha", "id": "9"}, {"text": "r7:8", "type": "sha", "id": "8"}]}, {"text": "Branches", "children": []}, {"text": "Tags", "children": []}], "more": false}

View file

@ -92,7 +92,7 @@ def junk_form_data_detector(request):
def sanity_check_factory(handler, registry):
def sanity_check(request):
log.debug('Checking URL sanity')
log.debug('Checking current URL sanity for bad data')
try:
junk_encoding_detector(request)
bad_url_data_detector(request)