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')) #test or history response.mustcontain(""" """) response.mustcontain("""
merge
""") response.mustcontain("""branch: default""") 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(""" """) response.mustcontain("""branch: default""") 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")