git @ Cat's Eye Technologies klaus / af284ee
Add ctags tests Jonas Haag 9 years ago
4 changed file(s) with 61 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
00 #!/bin/bash -e
11 git init
22
3 echo Hello World > README
4 git add README
5 git commit -m "First commit"
3 echo "int a;" > test.c
4 echo "function test() {}" > test.js
5 git add test.c
6 git add test.js
7 git commit -m "Add some code"
8
9 git commit --allow-empty -m "Empty commit 1"
10 git tag tag1
11
12 git commit --allow-empty -m "Empty commit 2"
0 from io import BytesIO
1 import requests
2 import tarfile
3 import contextlib
4 from .utils import *
00 import os
1 import re
12 import subprocess
23 import tempfile
34 import shutil
3334 def options_test(make_app_args, expected_permissions):
3435 def test():
3536 with serve(**make_app_args):
36 for action, permitted in expected_permissions.items():
37 if action.endswith('auth'):
38 actions = [action]
37 for check, permitted in expected_permissions.items():
38 if check in globals():
39 checks = [check]
40 elif check.endswith('auth'):
41 checks = ['can_%s' % check]
3942 else:
40 actions = [action + '_unauth', action + '_auth']
41 for action in actions:
42 funcname = 'can_%s' % action
43 assert globals()[funcname]() == permitted
43 checks = ['can_%s_unauth' % check, 'can_%s_auth' % check]
44 for check in checks:
45 assert globals()[check]() == permitted
4446 return test
4547
4648
7173 test_smart_auth_disable_push = options_test(
7274 {'require_browser_auth': True, 'use_smarthttp': True, 'disable_push': True, 'htdigest_file': open(HTDIGEST_FILE)},
7375 {'reach_auth': True, 'reach_unauth': False, 'clone_auth': True, 'clone_unauth': False, 'push': False}
76 )
77
78 test_ctags_disabled = options_test(
79 {},
80 {'ctags_tags_and_branches': False, 'ctags_all': False}
81 )
82 test_ctags_tags_and_branches = options_test(
83 {'ctags_policy': 'tags-and-branches'},
84 {'ctags_tags_and_branches': True, 'ctags_all': False}
85 )
86 test_ctags_all = options_test(
87 {'ctags_policy': 'ALL'},
88 {'ctags_tags_and_branches': True, 'ctags_all': True}
7489 )
7590
7691
116131 ])
117132
118133
134 # Ctags
135 def ctags_tags_and_branches():
136 return all(
137 _ctags_enabled(ref, f)
138 for ref in ["master", "tag1"] for f in ["test.c", "test.js"]
139 )
140
141
142 def ctags_all():
143 all_refs = re.findall('href=".+/commit/([a-z0-9]{40})/">',
144 requests.get(UNAUTH_TEST_REPO_URL).content)
145 assert len(all_refs) == 3
146 return all(
147 _ctags_enabled(ref, f)
148 for ref in all_refs for f in ["test.c", "test.js"]
149 )
150
151 def _ctags_enabled(ref, filename):
152 response = requests.get(UNAUTH_TEST_REPO_URL + "blob/%s/%s" % (ref, filename))
153 href = '<a href="/%sblob/%s/%s#L-1">' % (TEST_REPO_URL, ref, filename)
154 return href in response.content
155
156
119157 def _GET_unauth(url=""):
120158 return requests.get(UNAUTH_TEST_SERVER + url, auth=requests.auth.HTTPDigestAuth("invalid", "password"))
121159
1010 response_body = BytesIO(response.raw.read())
1111 tarball = tarfile.TarFile.gzopen("test.tar.gz", fileobj=response_body)
1212 with contextlib.closing(tarball):
13 assert tarball.extractfile('README').read() == b'Hello World\n'
13 assert tarball.extractfile('test.c').read() == b'int a;\n'
1414
1515
1616 def test_no_newline_at_end_of_file():