from rhodecode.tests import *
ARCHIVE_SPECS = {
'.tar.bz2': ('application/x-tar', 'tbz2', ''),
'.tar.gz': ('application/x-tar', 'tgz', ''),
'.zip': ('application/zip', 'zip', ''),
}
class TestFilesController(TestController):
def test_index(self):
self.log_user()
response = self.app.get(url(controller='files', action='index',
repo_name=HG_REPO,
revision='tip',
f_path='/'))
# Test response...
assert 'docs' in response.body, 'missing dir'
assert 'tests' in response.body, 'missing dir'
assert 'vcs' in response.body, 'missing dir'
assert '.hgignore' in response.body, 'missing file'
assert 'MANIFEST.in' in response.body, 'missing file'
def test_index_revision(self):
self.log_user()
response = self.app.get(url(controller='files', action='index',
repo_name=HG_REPO,
revision='7ba66bec8d6dbba14a2155be32408c435c5f4492',
f_path='/'))
#Test response...
assert 'docs' in response.body, 'missing dir'
assert 'tests' in response.body, 'missing dir'
assert 'README.rst' in response.body, 'missing file'
assert '1.1 KiB' in response.body, 'missing size of setup.py'
assert 'text/x-python' in response.body, 'missing mimetype of setup.py'
def test_index_different_branch(self):
self.log_user()
response = self.app.get(url(controller='files', action='index',
repo_name=HG_REPO,
revision='97e8b885c04894463c51898e14387d80c30ed1ee',
f_path='/'))
assert """branch: git""" in response.body, 'missing or wrong branch info'
def test_index_paging(self):
self.log_user()
for r in [(73, 'a066b25d5df7016b45a41b7e2a78c33b57adc235'),
(92, 'cc66b61b8455b264a7a8a2d8ddc80fcfc58c221e'),
(109, '75feb4c33e81186c87eac740cee2447330288412'),
(1, '3d8f361e72ab303da48d799ff1ac40d5ac37c67e'),
(0, 'b986218ba1c9b0d6a259fac9b050b1724ed8e545')]:
response = self.app.get(url(controller='files', action='index',
repo_name=HG_REPO,
revision=r[1],
f_path='/'))
assert """@ r%s:%s""" % (r[0], r[1][:12]) in response.body, 'missing info about current revision'
def test_file_source(self):
self.log_user()
response = self.app.get(url(controller='files', action='index',
repo_name=HG_REPO,
revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
f_path='vcs/nodes.py'))
#test or history
assert """
""" in response.body
assert """
"Partially implemented #16. filecontent/commit message/author/node name are safe_unicode now.
In addition some other __str__ are unicode as well
Added test for unicode
Improved test to clone into uniq repository.
removed extra unicode conversion in diff."
""" in response.body
assert """branch: default""" in response.body, 'missing or wrong branch info'
def test_file_annotation(self):
self.log_user()
response = self.app.get(url(controller='files', action='annotate',
repo_name=HG_REPO,
revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
f_path='vcs/nodes.py'))
print response.body
assert """
""" 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