Files
@ 78c7e8efe658
Branch filter:
Location: kallithea/rhodecode/tests/functional/test_files.py
78c7e8efe658
20.0 KiB
text/x-python
new feature: API access white list definition from .ini files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | from rhodecode.tests import *
from rhodecode.model.db import Repository
from rhodecode.model.meta import Session
ARCHIVE_SPECS = {
'.tar.bz2': ('application/x-bzip2', 'tbz2', ''),
'.tar.gz': ('application/x-gzip', 'tgz', ''),
'.zip': ('application/zip', 'zip', ''),
}
def _set_downloads(repo_name, set_to):
repo = Repository.get_by_repo_name(repo_name)
repo.enable_downloads = set_to
Session().add(repo)
Session().commit()
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('<a class="browser-dir ypjax-link" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/docs">docs</a>')
response.mustcontain('<a class="browser-dir ypjax-link" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/tests">tests</a>')
response.mustcontain('<a class="browser-dir ypjax-link" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/vcs">vcs</a>')
response.mustcontain('<a class="browser-file ypjax-link" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/.hgignore">.hgignore</a>')
response.mustcontain('<a class="browser-file ypjax-link" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/MANIFEST.in">MANIFEST.in</a>')
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('<a class="browser-dir ypjax-link" href="/vcs_test_hg/files/7ba66bec8d6dbba14a2155be32408c435c5f4492/docs">docs</a>')
response.mustcontain('<a class="browser-dir ypjax-link" href="/vcs_test_hg/files/7ba66bec8d6dbba14a2155be32408c435c5f4492/tests">tests</a>')
response.mustcontain('<a class="browser-file ypjax-link" href="/vcs_test_hg/files/7ba66bec8d6dbba14a2155be32408c435c5f4492/README.rst">README.rst</a>')
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("""<span style="text-transform: uppercase;"><a href="#">Branch: git</a></span>""")
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("""<div class="commit">Partially implemented <a class="issue-tracker-link" href="https://myissueserver.com/vcs_test_hg/issue/16">#16</a>. 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.</div>
""")
response.mustcontain("""<span style="text-transform: uppercase;"><a href="#">Branch: default</a></span>""")
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("""<optgroup label="Changesets">
<option selected="selected" value="8911406ad776fdd3d0b9932a2e89677e57405a48">r167:8911406ad776 (default)</option>
<option value="aa957ed78c35a1541f508d2ec90e501b0a9e3167">r165:aa957ed78c35 (default)</option>
<option value="48e11b73e94c0db33e736eaeea692f990cb0b5f1">r140:48e11b73e94c (default)</option>
<option value="adf3cbf483298563b968a6c673cd5bde5f7d5eea">r126:adf3cbf48329 (default)</option>
<option value="6249fd0fb2cfb1411e764129f598e2cf0de79a6f">r113:6249fd0fb2cf (git)</option>
<option value="75feb4c33e81186c87eac740cee2447330288412">r109:75feb4c33e81 (default)</option>
<option value="9a4dc232ecdc763ef2e98ae2238cfcbba4f6ad8d">r108:9a4dc232ecdc (default)</option>
<option value="595cce4efa21fda2f2e4eeb4fe5f2a6befe6fa2d">r107:595cce4efa21 (default)</option>
<option value="4a8bd421fbc2dfbfb70d85a3fe064075ab2c49da">r104:4a8bd421fbc2 (default)</option>
<option value="57be63fc8f85e65a0106a53187f7316f8c487ffa">r102:57be63fc8f85 (default)</option>
<option value="5530bd87f7e2e124a64d07cb2654c997682128be">r101:5530bd87f7e2 (git)</option>
<option value="e516008b1c93f142263dc4b7961787cbad654ce1">r99:e516008b1c93 (default)</option>
<option value="41f43fc74b8b285984554532eb105ac3be5c434f">r93:41f43fc74b8b (default)</option>
<option value="cc66b61b8455b264a7a8a2d8ddc80fcfc58c221e">r92:cc66b61b8455 (default)</option>
<option value="73ab5b616b3271b0518682fb4988ce421de8099f">r91:73ab5b616b32 (default)</option>
<option value="e0da75f308c0f18f98e9ce6257626009fdda2b39">r82:e0da75f308c0 (default)</option>
<option value="fb2e41e0f0810be4d7103bc2a4c7be16ee3ec611">r81:fb2e41e0f081 (default)</option>
<option value="602ae2f5e7ade70b3b66a58cdd9e3e613dc8a028">r76:602ae2f5e7ad (default)</option>
<option value="a066b25d5df7016b45a41b7e2a78c33b57adc235">r73:a066b25d5df7 (default)</option>
<option value="637a933c905958ce5151f154147c25c1c7b68832">r61:637a933c9059 (web)</option>
<option value="0c21004effeb8ce2d2d5b4a8baf6afa8394b6fbc">r60:0c21004effeb (web)</option>
<option value="a1f39c56d3f1d52d5fb5920370a2a2716cd9a444">r59:a1f39c56d3f1 (web)</option>
<option value="97d32df05c715a3bbf936bf3cc4e32fb77fe1a7f">r58:97d32df05c71 (web)</option>
<option value="08eaf14517718dccea4b67755a93368341aca919">r57:08eaf1451771 (web)</option>
<option value="22f71ad265265a53238359c883aa976e725aa07d">r56:22f71ad26526 (web)</option>
<option value="97501f02b7b4330924b647755663a2d90a5e638d">r49:97501f02b7b4 (web)</option>
<option value="86ede6754f2b27309452bb11f997386ae01d0e5a">r47:86ede6754f2b (web)</option>
<option value="014c40c0203c423dc19ecf94644f7cac9d4cdce0">r45:014c40c0203c (web)</option>
<option value="ee87846a61c12153b51543bf860e1026c6d3dcba">r30:ee87846a61c1 (default)</option>
<option value="9bb326a04ae5d98d437dece54be04f830cf1edd9">r26:9bb326a04ae5 (default)</option>
<option value="536c1a19428381cfea92ac44985304f6a8049569">r24:536c1a194283 (default)</option>
<option value="dc5d2c0661b61928834a785d3e64a3f80d3aad9c">r8:dc5d2c0661b6 (default)</option>
<option value="3803844fdbd3b711175fc3da9bdacfcd6d29a6fb">r7:3803844fdbd3 (default)</option>
</optgroup>
<optgroup label="Branches">
<option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">default</option>
<option value="97e8b885c04894463c51898e14387d80c30ed1ee">git</option>
<option value="2e6a2bf9356ca56df08807f4ad86d480da72a8f4">web</option>
</optgroup>
<optgroup label="Tags">
<option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">tip</option>
<option value="fd4bdb5e9b2a29b4393a4ac6caef48c17ee1a200">0.1.4</option>
<option value="17544fbfcd33ffb439e2b728b5d526b1ef30bfcf">0.1.3</option>
<option value="a7e60bff65d57ac3a1a1ce3b12a70f8a9e8a7720">0.1.2</option>
<option value="eb3a60fc964309c1a318b8dfe26aa2d1586c85ae">0.1.1</option>
</optgroup>
""")
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("""<span style="text-transform: uppercase;"><a href="#">Branch: default</a></span>""")
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("""<optgroup label="Changesets">
<option selected="selected" value="8911406ad776fdd3d0b9932a2e89677e57405a48">r167:8911406ad776 (default)</option>
<option value="aa957ed78c35a1541f508d2ec90e501b0a9e3167">r165:aa957ed78c35 (default)</option>
<option value="48e11b73e94c0db33e736eaeea692f990cb0b5f1">r140:48e11b73e94c (default)</option>
<option value="adf3cbf483298563b968a6c673cd5bde5f7d5eea">r126:adf3cbf48329 (default)</option>
<option value="6249fd0fb2cfb1411e764129f598e2cf0de79a6f">r113:6249fd0fb2cf (git)</option>
<option value="75feb4c33e81186c87eac740cee2447330288412">r109:75feb4c33e81 (default)</option>
<option value="9a4dc232ecdc763ef2e98ae2238cfcbba4f6ad8d">r108:9a4dc232ecdc (default)</option>
<option value="595cce4efa21fda2f2e4eeb4fe5f2a6befe6fa2d">r107:595cce4efa21 (default)</option>
<option value="4a8bd421fbc2dfbfb70d85a3fe064075ab2c49da">r104:4a8bd421fbc2 (default)</option>
<option value="57be63fc8f85e65a0106a53187f7316f8c487ffa">r102:57be63fc8f85 (default)</option>
<option value="5530bd87f7e2e124a64d07cb2654c997682128be">r101:5530bd87f7e2 (git)</option>
<option value="e516008b1c93f142263dc4b7961787cbad654ce1">r99:e516008b1c93 (default)</option>
<option value="41f43fc74b8b285984554532eb105ac3be5c434f">r93:41f43fc74b8b (default)</option>
<option value="cc66b61b8455b264a7a8a2d8ddc80fcfc58c221e">r92:cc66b61b8455 (default)</option>
<option value="73ab5b616b3271b0518682fb4988ce421de8099f">r91:73ab5b616b32 (default)</option>
<option value="e0da75f308c0f18f98e9ce6257626009fdda2b39">r82:e0da75f308c0 (default)</option>
<option value="fb2e41e0f0810be4d7103bc2a4c7be16ee3ec611">r81:fb2e41e0f081 (default)</option>
<option value="602ae2f5e7ade70b3b66a58cdd9e3e613dc8a028">r76:602ae2f5e7ad (default)</option>
<option value="a066b25d5df7016b45a41b7e2a78c33b57adc235">r73:a066b25d5df7 (default)</option>
<option value="637a933c905958ce5151f154147c25c1c7b68832">r61:637a933c9059 (web)</option>
<option value="0c21004effeb8ce2d2d5b4a8baf6afa8394b6fbc">r60:0c21004effeb (web)</option>
<option value="a1f39c56d3f1d52d5fb5920370a2a2716cd9a444">r59:a1f39c56d3f1 (web)</option>
<option value="97d32df05c715a3bbf936bf3cc4e32fb77fe1a7f">r58:97d32df05c71 (web)</option>
<option value="08eaf14517718dccea4b67755a93368341aca919">r57:08eaf1451771 (web)</option>
<option value="22f71ad265265a53238359c883aa976e725aa07d">r56:22f71ad26526 (web)</option>
<option value="97501f02b7b4330924b647755663a2d90a5e638d">r49:97501f02b7b4 (web)</option>
<option value="86ede6754f2b27309452bb11f997386ae01d0e5a">r47:86ede6754f2b (web)</option>
<option value="014c40c0203c423dc19ecf94644f7cac9d4cdce0">r45:014c40c0203c (web)</option>
<option value="ee87846a61c12153b51543bf860e1026c6d3dcba">r30:ee87846a61c1 (default)</option>
<option value="9bb326a04ae5d98d437dece54be04f830cf1edd9">r26:9bb326a04ae5 (default)</option>
<option value="536c1a19428381cfea92ac44985304f6a8049569">r24:536c1a194283 (default)</option>
<option value="dc5d2c0661b61928834a785d3e64a3f80d3aad9c">r8:dc5d2c0661b6 (default)</option>
<option value="3803844fdbd3b711175fc3da9bdacfcd6d29a6fb">r7:3803844fdbd3 (default)</option>
</optgroup>
<optgroup label="Branches">
<option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">default</option>
<option value="97e8b885c04894463c51898e14387d80c30ed1ee">git</option>
<option value="2e6a2bf9356ca56df08807f4ad86d480da72a8f4">web</option>
</optgroup>
<optgroup label="Tags">
<option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">tip</option>
<option value="fd4bdb5e9b2a29b4393a4ac6caef48c17ee1a200">0.1.4</option>
<option value="17544fbfcd33ffb439e2b728b5d526b1ef30bfcf">0.1.3</option>
<option value="a7e60bff65d57ac3a1a1ce3b12a70f8a9e8a7720">0.1.2</option>
<option value="eb3a60fc964309c1a318b8dfe26aa2d1586c85ae">0.1.1</option>
</optgroup>""")
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()
_set_downloads(HG_REPO, set_to=True)
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()
_set_downloads(HG_REPO, set_to=True)
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()
_set_downloads(HG_REPO, set_to=True)
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), status=404)
msg = """Revision %s does not exist for this repository""" % (rev)
response.mustcontain(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), status=404)
msg = "There is no file nor directory at the given path: '%s' at revision %s" % (f_path, rev[:12])
response.mustcontain(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), status=404)
msg = """Revision %s does not exist for this repository""" % (rev)
response.mustcontain(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), status=404)
msg = "There is no file nor directory at the given path: '%s' at revision %s" % (f_path, rev[:12])
response.mustcontain(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")
def test_add_file_view_hg(self):
self.log_user()
response = self.app.get(url('files_add_home',
repo_name=HG_REPO,
revision='tip', f_path='/'))
def test_add_file_view_git(self):
self.log_user()
response = self.app.get(url('files_add_home',
repo_name=GIT_REPO,
revision='tip', f_path='/'))
def test_edit_file_view_hg(self):
self.log_user()
response = self.app.get(url('files_edit_home',
repo_name=HG_REPO,
revision='tip', f_path='vcs/nodes.py'))
def test_edit_file_view_git(self):
self.log_user()
response = self.app.get(url('files_edit_home',
repo_name=GIT_REPO,
revision='tip', f_path='vcs/nodes.py'))
|