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):
self.log_user()
response = self.app.get(url(controller='files', action='index',
repo_name=HG_REPO,
revision='tip',
f_path='/'))
# Test response...
response.mustcontain('docs ')
response.mustcontain('tests ')
response.mustcontain('vcs ')
response.mustcontain('.hgignore ')
response.mustcontain('MANIFEST.in ')
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...
response.mustcontain('docs ')
response.mustcontain('tests ')
response.mustcontain('README.rst ')
response.mustcontain('1.1 KiB')
response.mustcontain('text/x-python')
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='/'))
response.mustcontain("""branch: git """)
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='/'))
response.mustcontain("""@ r%s:%s""" % (r[0], r[1][:12]))
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'))
response.mustcontain("""
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.
""")
response.mustcontain("""branch: default """)
def test_file_source_history(self):
self.log_user()
response = self.app.get(url(controller='files', action='history',
repo_name=HG_REPO,
revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
f_path='vcs/nodes.py'),
extra_environ={'HTTP_X_PARTIAL_XHR': '1'},)
#test or history
response.mustcontain("""
r167:8911406ad776 (default)
r165:aa957ed78c35 (default)
r140:48e11b73e94c (default)
r126:adf3cbf48329 (default)
r113:6249fd0fb2cf (git)
r109:75feb4c33e81 (default)
r108:9a4dc232ecdc (default)
r107:595cce4efa21 (default)
r104:4a8bd421fbc2 (default)
r102:57be63fc8f85 (default)
r101:5530bd87f7e2 (git)
r99:e516008b1c93 (default)
r93:41f43fc74b8b (default)
r92:cc66b61b8455 (default)
r91:73ab5b616b32 (default)
r82:e0da75f308c0 (default)
r81:fb2e41e0f081 (default)
r76:602ae2f5e7ad (default)
r73:a066b25d5df7 (default)
r61:637a933c9059 (web)
r60:0c21004effeb (web)
r59:a1f39c56d3f1 (web)
r58:97d32df05c71 (web)
r57:08eaf1451771 (web)
r56:22f71ad26526 (web)
r49:97501f02b7b4 (web)
r47:86ede6754f2b (web)
r45:014c40c0203c (web)
r30:ee87846a61c1 (default)
r26:9bb326a04ae5 (default)
r24:536c1a194283 (default)
r8:dc5d2c0661b6 (default)
r7:3803844fdbd3 (default)
default
git
web
tip
0.1.4
0.1.3
0.1.2
0.1.1
""")
def test_file_annotation(self):
self.log_user()
response = self.app.get(url(controller='files', action='index',
repo_name=HG_REPO,
revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
f_path='vcs/nodes.py',
annotate=True))
response.mustcontain("""branch: default """)
def test_file_annotation_history(self):
self.log_user()
response = self.app.get(url(controller='files', action='history',
repo_name=HG_REPO,
revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
f_path='vcs/nodes.py',
annotate=True),
extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
response.mustcontain("""
r167:8911406ad776 (default)
r165:aa957ed78c35 (default)
r140:48e11b73e94c (default)
r126:adf3cbf48329 (default)
r113:6249fd0fb2cf (git)
r109:75feb4c33e81 (default)
r108:9a4dc232ecdc (default)
r107:595cce4efa21 (default)
r104:4a8bd421fbc2 (default)
r102:57be63fc8f85 (default)
r101:5530bd87f7e2 (git)
r99:e516008b1c93 (default)
r93:41f43fc74b8b (default)
r92:cc66b61b8455 (default)
r91:73ab5b616b32 (default)
r82:e0da75f308c0 (default)
r81:fb2e41e0f081 (default)
r76:602ae2f5e7ad (default)
r73:a066b25d5df7 (default)
r61:637a933c9059 (web)
r60:0c21004effeb (web)
r59:a1f39c56d3f1 (web)
r58:97d32df05c71 (web)
r57:08eaf1451771 (web)
r56:22f71ad26526 (web)
r49:97501f02b7b4 (web)
r47:86ede6754f2b (web)
r45:014c40c0203c (web)
r30:ee87846a61c1 (default)
r26:9bb326a04ae5 (default)
r24:536c1a194283 (default)
r8:dc5d2c0661b6 (default)
r7:3803844fdbd3 (default)
default
git
web
tip
0.1.4
0.1.3
0.1.2
0.1.1
""")
def test_file_annotation_git(self):
self.log_user()
response = self.app.get(url(controller='files', action='index',
repo_name=GIT_REPO,
revision='master',
f_path='vcs/nodes.py',
annotate=True))
def test_archival(self):
self.log_user()
for arch_ext, info in ARCHIVE_SPECS.items():
short = '27cd5cce30c9%s' % arch_ext
fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
filename = '%s-%s' % (HG_REPO, short)
response = self.app.get(url(controller='files',
action='archivefile',
repo_name=HG_REPO,
fname=fname))
self.assertEqual(response.status, '200 OK')
heads = [
('Pragma', 'no-cache'),
('Cache-Control', 'no-cache'),
('Content-Disposition', 'attachment; filename=%s' % filename),
('Content-Type', '%s; charset=utf-8' % info[0]),
]
self.assertEqual(response.response._headers.items(), heads)
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))
response.mustcontain('Unknown archive type')
def test_archival_wrong_revision(self):
self.log_user()
for rev in ['00x000000', 'tar', 'wrong', '@##$@$42413232', '232dffcd']:
fname = '%s.zip' % rev
response = self.app.get(url(controller='files',
action='archivefile',
repo_name=HG_REPO,
fname=fname))
response.mustcontain('Unknown revision')
#==========================================================================
# 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'))
self.assertEqual(response.content_disposition, "attachment; filename=nodes.py")
self.assertEqual(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))
msg = """Revision %r does not exist for this repository""" % (rev)
self.checkSessionFlash(response, msg)
msg = """%s""" % (HG_REPO)
self.checkSessionFlash(response, msg)
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))
msg = "There is no file nor directory at the given path: %r at revision %r" % (f_path, rev[:12])
self.checkSessionFlash(response, msg)
#==========================================================================
# 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'))
self.assertEqual(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))
msg = """Revision %r does not exist for this repository""" % (rev)
self.checkSessionFlash(response, msg)
msg = """%s""" % (HG_REPO)
self.checkSessionFlash(response, msg)
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))
msg = "There is no file nor directory at the given path: %r at revision %r" % (f_path, rev[:12])
self.checkSessionFlash(response, msg)
def test_ajaxed_files_list(self):
self.log_user()
rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
response = self.app.get(
url('files_nodelist_home', repo_name=HG_REPO,f_path='/',revision=rev),
extra_environ={'HTTP_X_PARTIAL_XHR': '1'},
)
response.mustcontain("vcs/web/simplevcs/views/repository.py")