diff --git a/rhodecode/tests/functional/test_files.py b/rhodecode/tests/functional/test_files.py --- a/rhodecode/tests/functional/test_files.py +++ b/rhodecode/tests/functional/test_files.py @@ -1,5 +1,11 @@ from rhodecode.tests import * +ARCHIVE_SPECS = { + '.tar.bz2': ('application/x-bzip2', 'tbz2', ''), + '.tar.gz': ('application/x-gzip', 'tgz', ''), + '.zip': ('application/zip', 'zip', ''), +} + class TestFilesController(TestController): def test_index(self): @@ -188,3 +194,120 @@ removed extra unicode conversion in diff """ in response.body, 'missing or wrong history in annotation' assert """branch: default""" in response.body, 'missing or wrong branch info' + + + + def test_archival(self): + self.log_user() + + for arch_ext, info in ARCHIVE_SPECS.items(): + fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext + filename = '%s-%s' % (HG_REPO, fname) + + response = self.app.get(url(controller='files', action='archivefile', + repo_name=HG_REPO, + fname=fname)) + + assert response.status == '200 OK', 'wrong response code' + assert response.response._headers.items() == [('Pragma', 'no-cache'), + ('Cache-Control', 'no-cache'), + ('Content-Type', '%s; charset=utf-8' % info[0]), + ('Content-Disposition', 'attachment; filename=%s' % filename), ], 'wrong headers' + + def test_archival_wrong_ext(self): + self.log_user() + + for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']: + fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext + + response = self.app.get(url(controller='files', action='archivefile', + repo_name=HG_REPO, + fname=fname)) + assert 'Unknown archive type' in response.body + + + def test_archival_wrong_revision(self): + self.log_user() + + for rev in ['00x000000', 'tar', 'wrong', '@##$@$424213232', '232dffcd']: + fname = '%s.zip' % rev + + response = self.app.get(url(controller='files', action='archivefile', + repo_name=HG_REPO, + fname=fname)) + assert 'Unknown revision' in response.body + + #========================================================================== + # RAW FILE + #========================================================================== + def test_raw_file_ok(self): + self.log_user() + response = self.app.get(url(controller='files', action='rawfile', + repo_name=HG_REPO, + revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc', + f_path='vcs/nodes.py')) + + assert response.content_disposition == "attachment; filename=nodes.py" + assert response.content_type == "text/x-python" + + def test_raw_file_wrong_cs(self): + self.log_user() + rev = u'ERRORce30c96924232dffcd24178a07ffeb5dfc' + f_path = 'vcs/nodes.py' + + response = self.app.get(url(controller='files', action='rawfile', + repo_name=HG_REPO, + revision=rev, + f_path=f_path)) + + assert """Revision %r does not exist for this repository""" % (rev) in response.session['flash'][0][1], 'No flash message' + assert """%s""" % (HG_REPO) in response.session['flash'][0][1], 'No flash message' + + + + def test_raw_file_wrong_f_path(self): + self.log_user() + rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' + f_path = 'vcs/ERRORnodes.py' + response = self.app.get(url(controller='files', action='rawfile', + repo_name=HG_REPO, + revision=rev, + f_path=f_path)) + assert "There is no file nor directory at the given path: %r at revision %r" % (f_path, rev[:12]) in response.session['flash'][0][1], 'No flash message' + + #========================================================================== + # RAW RESPONSE - PLAIN + #========================================================================== + def test_raw_ok(self): + self.log_user() + response = self.app.get(url(controller='files', action='raw', + repo_name=HG_REPO, + revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc', + f_path='vcs/nodes.py')) + + assert response.content_type == "text/plain" + + def test_raw_wrong_cs(self): + self.log_user() + rev = u'ERRORcce30c96924232dffcd24178a07ffeb5dfc' + f_path = 'vcs/nodes.py' + + response = self.app.get(url(controller='files', action='raw', + repo_name=HG_REPO, + revision=rev, + f_path=f_path)) + + assert """Revision %r does not exist for this repository""" % (rev) in response.session['flash'][0][1], 'No flash message' + assert """%s""" % (HG_REPO) in response.session['flash'][0][1], 'No flash message' + + + def test_raw_wrong_f_path(self): + self.log_user() + rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' + f_path = 'vcs/ERRORnodes.py' + response = self.app.get(url(controller='files', action='raw', + repo_name=HG_REPO, + revision=rev, + f_path=f_path)) + + assert "There is no file nor directory at the given path: %r at revision %r" % (f_path, rev[:12]) in response.session['flash'][0][1], 'No flash message'